Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement