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.

39 lines
1.2 KiB

  1. # Copyright 2018 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. from odoo.exceptions import AccessError
  5. from odoo.tools.translate import _
  6. class ContractContract(models.Model):
  7. _inherit = 'contract.contract'
  8. sale_order_count = fields.Integer(compute="_compute_sale_order_count")
  9. @api.depends('contract_line_ids')
  10. def _compute_sale_order_count(self):
  11. for rec in self:
  12. try:
  13. order_count = len(
  14. rec.contract_line_ids.mapped(
  15. 'sale_order_line_id.order_id'
  16. )
  17. )
  18. except AccessError:
  19. order_count = 0
  20. rec.sale_order_count = order_count
  21. @api.multi
  22. def action_view_sales_orders(self):
  23. self.ensure_one()
  24. orders = self.contract_line_ids.mapped(
  25. 'sale_order_line_id.order_id'
  26. )
  27. return {
  28. "name": _("Sales Orders"),
  29. "view_mode": "tree,form",
  30. "res_model": "sale.order",
  31. "type": "ir.actions.act_window",
  32. "domain": [("id", "in", orders.ids)],
  33. }