Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CategoryAllocation(ModelSQL, ModelView):
- """
- Category Budget Allocation by Secretary
- """
- __name__ = 'budget.category_allocation'
- name = fields.Char('Name', required=True, translate=True)
- amounts = fields.Function(fields.One2Many('budget.amount_secretary', 'category', 'Amount per secretary'), 'get_amounts')
- @staticmethod
- def table_query():
- table = sql.Table('product_category')
- return table.select()
- def get_amounts(self, name):
- bp_pool = Pool().get('budget.product')
- secretary_pool = Pool().get('budget.secretary')
- all_products = bp_pool.search([('budget.state', 'not in', ['canceled', 'rejected'])])
- products = filter(lambda x: self.id in map(lambda y: y.id, x.product.categories), all_products)
- # products = all_products
- amounts = []
- all_secretaries = secretary_pool.search([])
- for secretary in all_secretaries:
- amount_secretary = {'category': self.id,
- 'secretary': secretary.name,
- 'amount': 0}
- for product in products:
- if product.budget.activity.program.secretary == secretary:
- amount_secretary['amount'] += product.amount
- if amount_secretary['amount'] != 0:
- amounts.append(amount_secretary)
- return amounts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement