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.

38 lines
1.3 KiB

  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 fields, models, api
  4. class Agreement(models.Model):
  5. _inherit = 'agreement'
  6. service_order_count = fields.Integer(
  7. compute='_compute_service_order_count',
  8. string='# Service Orders'
  9. )
  10. @api.multi
  11. def _compute_service_order_count(self):
  12. for agreement in self:
  13. res = self.env['fsm.order'].search_count(
  14. [('agreement_id', '=', agreement.id)])
  15. agreement.service_order_count = res or 0
  16. @api.multi
  17. def action_view_service_order(self):
  18. for agreement in self:
  19. fsm_order_ids = self.env['fsm.order'].search(
  20. [('agreement_id', '=', agreement.id)])
  21. action = self.env.ref(
  22. 'fieldservice.action_fsm_operation_order').read()[0]
  23. if len(fsm_order_ids) > 1:
  24. action['domain'] = [('id', 'in', fsm_order_ids.ids)]
  25. elif len(fsm_order_ids) == 1:
  26. action['views'] = [(
  27. self.env.ref('fieldservice.fsm_order_form').id,
  28. 'form')]
  29. action['res_id'] = fsm_order_ids.ids[0]
  30. else:
  31. action = {'type': 'ir.actions.act_window_close'}
  32. return action