You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
761 B

  1. # Copyright (C) 2018 - TODAY, Open Source Integrators
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class Agreement(models.Model):
  5. _inherit = "agreement"
  6. repair_count = fields.Integer('# Repair Orders',
  7. compute='_compute_repair_count')
  8. @api.multi
  9. def _compute_repair_count(self):
  10. data = self.env['mrp.repair'].read_group(
  11. [('agreement_id', 'in', self.ids)],
  12. ['agreement_id'], ['agreement_id'])
  13. count_data = dict((item['agreement_id'][0],
  14. item['agreement_id_count']) for item in data)
  15. for agreement in self:
  16. agreement.repair_count = count_data.get(agreement.id, 0)