OCA reporting engine fork for dev and update.
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.

44 lines
1.8 KiB

  1. # Copyright 2014 Guewen Baconnier (Camptocamp SA)
  2. # Copyright 2013-2014 Nicolas Bessi (Camptocamp SA)
  3. # Copyright 2020 NextERP Romania SRL
  4. # Copyright 2021 Tecnativa - Víctor Martínez
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from odoo import api, fields, models
  7. from odoo.tools.safe_eval import safe_eval
  8. class CommentTemplate(models.AbstractModel):
  9. _name = "comment.template"
  10. _description = (
  11. "base.comment.template to put header and footer "
  12. "in reports based on created comment templates"
  13. )
  14. # This field allows to set any given field that determines the source partner for
  15. # the comment templates downstream.
  16. # E.g.: other models where the partner field is called customer_id.
  17. _comment_template_partner_field_name = "partner_id"
  18. comment_template_ids = fields.Many2many(
  19. compute="_compute_comment_template_ids",
  20. comodel_name="base.comment.template",
  21. string="Comment Template",
  22. domain=lambda self: [("model_ids.model", "=", self._name)],
  23. store=True,
  24. readonly=False,
  25. )
  26. @api.depends(_comment_template_partner_field_name)
  27. def _compute_comment_template_ids(self):
  28. for record in self:
  29. partner = record[self._comment_template_partner_field_name]
  30. record.comment_template_ids = [(5,)]
  31. templates = self.env["base.comment.template"].search(
  32. [
  33. ("id", "in", partner.base_comment_template_ids.ids),
  34. ("model_ids.model", "=", self._name),
  35. ]
  36. )
  37. for template in templates:
  38. domain = safe_eval(template.domain)
  39. if not domain or record.filtered_domain(domain):
  40. record.comment_template_ids = [(4, template.id)]