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.

49 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(
  25. compute="_compute_dynamic_content",
  26. string="Dynamic Content",
  27. help='compute dynamic Content')
  28. active = fields.Boolean(
  29. string="Active",
  30. default=True,
  31. help="If unchecked, it will allow you to hide the agreement without "
  32. "removing it."
  33. )
  34. # compute the dynamic content for mako expression
  35. @api.multi
  36. def _compute_dynamic_content(self):
  37. MailTemplates = self.env['mail.template']
  38. for section in self:
  39. lang = section.agreement_id and \
  40. section.agreement_id.partner_id.lang or 'en_US'
  41. content = MailTemplates.with_context(
  42. lang=lang).render_template(
  43. section.content, 'agreement.section', section.id)
  44. section.dynamic_content = content