SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.db.models import Sum
  2.  
  3. from customer_purchase_order.models import CustomerPurchaseOrder
  4. from customer_purchase_order.models import CustomerPurchaseOrderItem
  5.  
  6. for ct in cts:
  7.     cpos = CustomerPurchaseOrder.objects.filter(customer_team=ct, cancelled=False).distinct()
  8.     total = cpos.count()
  9.  
  10.     for index, cpo in enumerate(cpos):
  11.         CustomerPurchaseOrder.objects.filter(
  12.             id=cpo.id,
  13.         ).update(
  14.             total_gross_value_on_file=CustomerPurchaseOrderItem.objects.filter(customer_purchase_order=cpo).distinct().aggregate(total_gross_value_on_file=Sum('total_gross_value_on_file')).get('total_gross_value_on_file'),
  15.         )
  16.         print u'completed {0}%'.format(((index+1) * 100) / total)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top