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
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 AgreementClause(models.Model):
  5. _name = 'agreement.clause'
  6. _description = 'Agreement Clauses'
  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. section_id = fields.Many2one(
  19. 'agreement.section',
  20. string="Section",
  21. ondelete="cascade"
  22. )
  23. content = fields.Html(string="Clause 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 clause in self:
  38. lang = clause.agreement_id and \
  39. clause.agreement_id.partner_id.lang or 'en_US'
  40. content = \
  41. MailTemplates.with_context(lang=lang).render_template(
  42. clause.content, 'agreement.clause', clause.id)
  43. clause.dynamic_content = content