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.

88 lines
3.0 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 fields, models
  7. class BaseCommentTemplate(models.Model):
  8. """Comment templates printed on reports"""
  9. _name = "base.comment.template"
  10. _description = "Comments Template"
  11. _order = "sequence,id"
  12. active = fields.Boolean(default=True)
  13. position = fields.Selection(
  14. string="Position on document",
  15. selection=[("before_lines", "Top"), ("after_lines", "Bottom")],
  16. required=True,
  17. default="before_lines",
  18. help="This field allows to select the position of the comment on reports.",
  19. )
  20. name = fields.Char(
  21. string="Name",
  22. translate=True,
  23. required=True,
  24. help="Name/description of this comment template",
  25. )
  26. text = fields.Html(
  27. string="Template",
  28. translate=True,
  29. required=True,
  30. sanitize=False,
  31. help="This is the text template that will be inserted into reports.",
  32. )
  33. company_id = fields.Many2one(
  34. comodel_name="res.company",
  35. string="Company",
  36. ondelete="cascade",
  37. index=True,
  38. help="If set, the comment template will be available only for the selected "
  39. "company.",
  40. )
  41. partner_ids = fields.Many2many(
  42. comodel_name="res.partner",
  43. relation="base_comment_template_res_partner_rel",
  44. column1="base_comment_template_id",
  45. column2="res_partner_id",
  46. string="Partner",
  47. readonly=True,
  48. help="If set, the comment template will be available only for the selected "
  49. "partner.",
  50. )
  51. model_ids = fields.Many2many(
  52. comodel_name="ir.model",
  53. string="IR Model",
  54. ondelete="cascade",
  55. domain=[
  56. ("is_comment_template", "=", True),
  57. ("model", "!=", "comment.template"),
  58. ],
  59. required=True,
  60. help="This comment template will be available on this models. "
  61. "You can see here only models allowed to set the coment template.",
  62. )
  63. domain = fields.Char(
  64. string="Filter Domain",
  65. required=True,
  66. default="[]",
  67. help="This comment template will be available only for objects "
  68. "that satisfy the condition",
  69. )
  70. sequence = fields.Integer(
  71. required=True, default=10, help="The smaller number = The higher priority"
  72. )
  73. def name_get(self):
  74. """Redefine the name_get method to show the template name with the position."""
  75. res = []
  76. for item in self:
  77. name = "{} ({})".format(
  78. item.name, dict(self._fields["position"].selection).get(item.position)
  79. )
  80. if self.env.context.get("comment_template_model_display"):
  81. name += " (%s)" % ", ".join(item.model_ids.mapped("name"))
  82. res.append((item.id, name))
  83. return res