Advertisement
Guest User

Untitled

a guest
Oct 5th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1.  
  2. class CategoryAllocation(ModelSQL, ModelView):
  3. """
  4. Category Budget Allocation by Secretary
  5. """
  6. __name__ = 'budget.category_allocation'
  7. name = fields.Char('Name', required=True, translate=True)
  8. amounts = fields.Function(fields.One2Many('budget.amount_secretary', 'category', 'Amount per secretary'), 'get_amounts')
  9.  
  10. @staticmethod
  11. def table_query():
  12. table = sql.Table('product_category')
  13. return table.select()
  14.  
  15. def get_amounts(self, name):
  16. bp_pool = Pool().get('budget.product')
  17. secretary_pool = Pool().get('budget.secretary')
  18.  
  19. all_products = bp_pool.search([('budget.state', 'not in', ['canceled', 'rejected'])])
  20. products = filter(lambda x: self.id in map(lambda y: y.id, x.product.categories), all_products)
  21. # products = all_products
  22. amounts = []
  23. all_secretaries = secretary_pool.search([])
  24. for secretary in all_secretaries:
  25. amount_secretary = {'category': self.id,
  26. 'secretary': secretary.name,
  27. 'amount': 0}
  28. for product in products:
  29. if product.budget.activity.program.secretary == secretary:
  30. amount_secretary['amount'] += product.amount
  31. if amount_secretary['amount'] != 0:
  32. amounts.append(amount_secretary)
  33. return amounts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement