flectra/addons/hr_expense/models/hr_department.py

17 lines
798 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
2018-01-16 11:34:37 +01:00
from flectra import fields, models
class HrDepartment(models.Model):
_inherit = 'hr.department'
def _compute_expense_sheets_to_approve(self):
expense_sheet_data = self.env['hr.expense.sheet'].read_group([('department_id', 'in', self.ids), ('state', '=', 'submit')], ['department_id'], ['department_id'])
result = dict((data['department_id'][0], data['department_id_count']) for data in expense_sheet_data)
for department in self:
department.expense_sheets_to_approve_count = result.get(department.id, 0)
expense_sheets_to_approve_count = fields.Integer(compute='_compute_expense_sheets_to_approve', string='Expenses Reports to Approve')