diff --git a/agreement/models/agreement.py b/agreement/models/agreement.py index 7402de27..ed4bced2 100644 --- a/agreement/models/agreement.py +++ b/agreement/models/agreement.py @@ -40,6 +40,9 @@ class Agreement(models.Model): track_visibility='onchange', help="Description of the agreement" ) + dynamic_description = fields.Text(compute="_compute_dynamic_description", + string="Dynamic Description", + help='compute dynamic description') start_date = fields.Date( string="Start Date", track_visibility='onchange', @@ -323,12 +326,23 @@ class Agreement(models.Model): track_visibility='always' ) + # compute the dynamic content for mako expression + @api.multi + def _compute_dynamic_description(self): + MailTemplates = self.env['mail.template'] + for agreement in self: + lang = agreement.partner_id.lang or 'en_US' + description = \ + MailTemplates.with_context(lang=lang).render_template( + agreement.description, 'agreement', agreement.id) + agreement.dynamic_description = description + # compute contract_value field @api.depends('total_customer_mrc', 'total_customer_nrc', 'term') def _compute_contract_value(self): for record in self: - record.contract_value =\ - (record.total_customer_mrc * record.term) +\ + record.contract_value = \ + (record.total_customer_mrc * record.term) + \ record.total_customer_nrc # compute total_company_mrc field diff --git a/agreement/models/agreement_appendix.py b/agreement/models/agreement_appendix.py index 97fc9352..4824a2e9 100644 --- a/agreement/models/agreement_appendix.py +++ b/agreement/models/agreement_appendix.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class AgreementAppendix(models.Model): @@ -15,6 +15,9 @@ class AgreementAppendix(models.Model): "The name is not.") sequence = fields.Integer(string="Sequence", default=10) content = fields.Html(string="Content") + dynamic_content = fields.Html(compute="_compute_dynamic_content", + string="Dynamic Content", + help='compute dynamic Content') agreement_id = fields.Many2one('agreement', string="Agreement", ondelete="cascade") active = fields.Boolean( @@ -22,3 +25,15 @@ class AgreementAppendix(models.Model): default=True, help="If unchecked, it will allow you to hide this appendix without " "removing it.") + + # compute the dynamic content for mako expression + @api.multi + def _compute_dynamic_content(self): + MailTemplates = self.env['mail.template'] + for appendix in self: + lang = appendix.agreement_id and \ + appendix.agreement_id.partner_id.lang or 'en_US' + content = \ + MailTemplates.with_context(lang=lang).render_template( + appendix.content, 'agreement.appendix', appendix.id) + appendix.dynamic_content = content diff --git a/agreement/models/agreement_clause.py b/agreement/models/agreement_clause.py index 63c54f93..d5c7ea47 100644 --- a/agreement/models/agreement_clause.py +++ b/agreement/models/agreement_clause.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class AgreementClause(models.Model): @@ -25,9 +25,24 @@ class AgreementClause(models.Model): ondelete="cascade" ) content = fields.Html(string="Clause Content") + dynamic_content = fields.Html(compute="_compute_dynamic_content", + string="Dynamic Content", + help='compute dynamic Content') active = fields.Boolean( string="Active", default=True, help="If unchecked, it will allow you to hide the agreement without " "removing it." ) + + # compute the dynamic content for mako expression + @api.multi + def _compute_dynamic_content(self): + MailTemplates = self.env['mail.template'] + for clause in self: + lang = clause.agreement_id and \ + clause.agreement_id.partner_id.lang or 'en_US' + content = \ + MailTemplates.with_context(lang=lang).render_template( + clause.content, 'agreement.clause', clause.id) + clause.dynamic_content = content diff --git a/agreement/models/agreement_recital.py b/agreement/models/agreement_recital.py index e5002fea..1a7bad60 100644 --- a/agreement/models/agreement_recital.py +++ b/agreement/models/agreement_recital.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class AgreementRecital(models.Model): @@ -15,6 +15,9 @@ class AgreementRecital(models.Model): "The name is not.") sequence = fields.Integer(string="Sequence", default=10) content = fields.Html(string="Content") + dynamic_content = fields.Html(compute="_compute_dynamic_content", + string="Dynamic Content", + help='compute dynamic Content') agreement_id = fields.Many2one('agreement', string="Agreement", ondelete="cascade") active = fields.Boolean( @@ -22,3 +25,15 @@ class AgreementRecital(models.Model): default=True, help="If unchecked, it will allow you to hide this recital without " "removing it.") + + # compute the dynamic content for mako expression + @api.multi + def _compute_dynamic_content(self): + MailTemplates = self.env['mail.template'] + for recital in self: + lang = recital.agreement_id and \ + recital.agreement_id.partner_id.lang or 'en_US' + content = \ + MailTemplates.with_context(lang=lang).render_template( + recital.content, 'agreement.recital', recital.id) + recital.dynamic_content = content diff --git a/agreement/models/agreement_section.py b/agreement/models/agreement_section.py index 7f89749f..fcf2feee 100644 --- a/agreement/models/agreement_section.py +++ b/agreement/models/agreement_section.py @@ -1,7 +1,7 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class AgreementSection(models.Model): @@ -25,9 +25,24 @@ class AgreementSection(models.Model): string="Clauses" ) content = fields.Html(string="Section Content") + dynamic_content = fields.Html(compute="_compute_dynamic_content", + string="Dynamic Content", + help='compute dynamic Content') active = fields.Boolean( string="Active", default=True, help="If unchecked, it will allow you to hide the agreement without " "removing it." ) + + # compute the dynamic content for mako expression + @api.multi + def _compute_dynamic_content(self): + MailTemplates = self.env['mail.template'] + for section in self: + lang = section.agreement_id and \ + section.agreement_id.partner_id.lang or 'en_US' + content = \ + MailTemplates.with_context(lang=lang).render_template( + section.content, 'agreement.section', section.id) + section.dynamic_content = content diff --git a/agreement/readme/CONTRIBUTORS.rst b/agreement/readme/CONTRIBUTORS.rst index 4e2eb061..0ac1664f 100644 --- a/agreement/readme/CONTRIBUTORS.rst +++ b/agreement/readme/CONTRIBUTORS.rst @@ -2,3 +2,4 @@ * Bhavesh Odedra * Wolfgang Hall * Maxime Chambreuil +* Sandip Mangukiya diff --git a/agreement/report/agreement.xml b/agreement/report/agreement.xml index ec3290f3..6a8ae52c 100644 --- a/agreement/report/agreement.xml +++ b/agreement/report/agreement.xml @@ -25,7 +25,7 @@

-

+

Parties

Company Information

@@ -55,7 +55,7 @@

-

+

@@ -71,13 +71,13 @@

-

+

  1. -

    +

@@ -132,7 +132,7 @@

-

+

diff --git a/agreement/views/agreement.xml b/agreement/views/agreement.xml index c0d7aee3..4ae4f9ba 100644 --- a/agreement/views/agreement.xml +++ b/agreement/views/agreement.xml @@ -63,6 +63,13 @@ required="True" nolabel="1"/> +
+

+ For dynamic content use mako expression '${expression}'. For ex: + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name} +

+
diff --git a/agreement/views/agreement_appendix.xml b/agreement/views/agreement_appendix.xml index 0ae5017b..ad4a772f 100644 --- a/agreement/views/agreement_appendix.xml +++ b/agreement/views/agreement_appendix.xml @@ -42,6 +42,13 @@ +
+

+ For dynamic content use mako expression '${expression}'. For ex: + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name} +

+
diff --git a/agreement/views/agreement_clause.xml b/agreement/views/agreement_clause.xml index 9d0d9dfe..96467c7d 100644 --- a/agreement/views/agreement_clause.xml +++ b/agreement/views/agreement_clause.xml @@ -44,6 +44,13 @@ +
+

+ For dynamic content use mako expression '${expression}'. For ex: + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name} +

+
diff --git a/agreement/views/agreement_recital.xml b/agreement/views/agreement_recital.xml index b963c254..904c5989 100644 --- a/agreement/views/agreement_recital.xml +++ b/agreement/views/agreement_recital.xml @@ -42,6 +42,13 @@ +
+

+ For dynamic content use mako expression '${expression}'. For ex: + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name} +

+
diff --git a/agreement/views/agreement_section.xml b/agreement/views/agreement_section.xml index 7c660df7..dcca2d41 100644 --- a/agreement/views/agreement_section.xml +++ b/agreement/views/agreement_section.xml @@ -44,6 +44,13 @@ +
+

+ For dynamic content use mako expression '${expression}'. For ex: + 1. object's field name: ${object.field_name} or + 2. many2one field name: ${object.many2one_field_id.field_name} +

+
+