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.5 KiB

  1. # Copyright (C) 2018 - TODAY, Pavlov Media
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models
  4. class AgreementAppendix(models.Model):
  5. _name = 'agreement.appendix'
  6. _description = 'Agreement Appendices'
  7. _order = "sequence"
  8. name = fields.Char(string="Name", required=True)
  9. title = fields.Char(string="Title", required=True,
  10. help="The title is displayed on the PDF."
  11. "The name is not.")
  12. sequence = fields.Integer(string="Sequence", default=10)
  13. content = fields.Html(string="Content")
  14. dynamic_content = fields.Html(
  15. compute="_compute_dynamic_content",
  16. string="Dynamic Content",
  17. help='compute dynamic Content')
  18. agreement_id = fields.Many2one('agreement', string="Agreement",
  19. ondelete="cascade")
  20. active = fields.Boolean(
  21. string="Active",
  22. default=True,
  23. help="If unchecked, it will allow you to hide this appendix without "
  24. "removing it.")
  25. # compute the dynamic content for mako expression
  26. @api.multi
  27. def _compute_dynamic_content(self):
  28. MailTemplates = self.env['mail.template']
  29. for appendix in self:
  30. lang = appendix.agreement_id and \
  31. appendix.agreement_id.partner_id.lang or 'en_US'
  32. content = MailTemplates.with_context(
  33. lang=lang).render_template(
  34. appendix.content, 'agreement.appendix', appendix.id)
  35. appendix.dynamic_content = content