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.

40 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 AccountAnalyticAccount(models.Model):
  7. _name = 'account.analytic.account'
  8. _inherit = 'account.analytic.account'
  9. sale_order_count = fields.Integer(compute="_compute_sale_order_count")
  10. @api.depends('recurring_invoice_line_ids')
  11. def _compute_sale_order_count(self):
  12. for rec in self:
  13. try:
  14. order_count = len(
  15. rec.recurring_invoice_line_ids.mapped(
  16. 'sale_order_line_id.order_id'
  17. )
  18. )
  19. except AccessError:
  20. order_count = 0
  21. rec.sale_order_count = order_count
  22. @api.multi
  23. def action_view_sales_orders(self):
  24. self.ensure_one()
  25. orders = self.recurring_invoice_line_ids.mapped(
  26. 'sale_order_line_id.order_id'
  27. )
  28. return {
  29. "name": _("Sales Orders"),
  30. "view_mode": "tree,form",
  31. "res_model": "sale.order",
  32. "type": "ir.actions.act_window",
  33. "domain": [("id", "in", orders.ids)],
  34. }