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.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(compute="_compute_dynamic_content",
  15. string="Dynamic Content",
  16. help='compute dynamic Content')
  17. agreement_id = fields.Many2one('agreement', string="Agreement",
  18. ondelete="cascade")
  19. active = fields.Boolean(
  20. string="Active",
  21. default=True,
  22. help="If unchecked, it will allow you to hide this appendix without "
  23. "removing it.")
  24. # compute the dynamic content for mako expression
  25. @api.multi
  26. def _compute_dynamic_content(self):
  27. MailTemplates = self.env['mail.template']
  28. for appendix in self:
  29. lang = appendix.agreement_id and \
  30. appendix.agreement_id.partner_id.lang or 'en_US'
  31. content = \
  32. MailTemplates.with_context(lang=lang).render_template(
  33. appendix.content, 'agreement.appendix', appendix.id)
  34. appendix.dynamic_content = content