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.

48 lines
1.6 KiB

6 years ago
6 years ago
  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 AgreementSection(models.Model):
  5. _name = 'agreement.section'
  6. _description = 'Agreement Sections'
  7. _order = 'sequence'
  8. name = fields.Char(string="Name", required=True)
  9. title = fields.Char(string="Title",
  10. help="The title is displayed on the PDF."
  11. "The name is not.")
  12. sequence = fields.Integer(string="Sequence")
  13. agreement_id = fields.Many2one(
  14. 'agreement',
  15. string="Agreement",
  16. ondelete="cascade"
  17. )
  18. clauses_ids = fields.One2many(
  19. 'agreement.clause',
  20. 'section_id',
  21. string="Clauses"
  22. )
  23. content = fields.Html(string="Section Content")
  24. dynamic_content = fields.Html(compute="_compute_dynamic_content",
  25. string="Dynamic Content",
  26. help='compute dynamic Content')
  27. active = fields.Boolean(
  28. string="Active",
  29. default=True,
  30. help="If unchecked, it will allow you to hide the agreement without "
  31. "removing it."
  32. )
  33. # compute the dynamic content for mako expression
  34. @api.multi
  35. def _compute_dynamic_content(self):
  36. MailTemplates = self.env['mail.template']
  37. for section in self:
  38. lang = section.agreement_id and \
  39. section.agreement_id.partner_id.lang or 'en_US'
  40. content = \
  41. MailTemplates.with_context(lang=lang).render_template(
  42. section.content, 'agreement.section', section.id)
  43. section.dynamic_content = content