[IMP]13481: compute dynamic content using mako template mechanism and render it in preview-pdf generation for agreement, clause, recital, section, appendix

This commit is contained in:
Sandip Mangukiya
2018-12-21 01:03:25 -08:00
parent a9942b7a8e
commit 56812369bc
13 changed files with 127 additions and 11 deletions

View File

@@ -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,6 +326,17 @@ 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):

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -2,3 +2,4 @@
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Wolfgang Hall <whall@opensourceintegrators.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Sandip Mangukiya <smangukiya@opensourceintegrators.com>

View File

@@ -25,7 +25,7 @@
<div class="page">
<h1 t-field="doc.name"/>
<div name="description">
<p t-field="doc.description"/>
<p t-field="doc.dynamic_description"/>
</div>
<h2>Parties</h2>
<h3>Company Information</h3>
@@ -55,7 +55,7 @@
<t t-if="r.title">
<h3 t-field="r.title"/>
</t>
<p t-field="r.content"/>
<p t-field="r.dynamic_content"/>
</li>
</ol>
</td>
@@ -71,13 +71,13 @@
<t t-if="s.title">
<h3 t-field="s.title"/>
</t>
<p t-field="s.content"/>
<p t-field="s.dynamic_content"/>
<ol>
<li t-foreach="s.clauses_ids" t-as="c">
<t t-if="c.title">
<h4 t-field="c.title"/>
</t>
<p t-field="c.content"/>
<p t-field="c.dynamic_content"/>
</li>
</ol>
</li>
@@ -132,7 +132,7 @@
<div class="page">
<h1 t-field="a.title"
style="page-break-before: always;"/>
<p t-field="a.content"/>
<p t-field="a.dynamic_content"/>
</div>
</div>
</t>

View File

@@ -63,6 +63,13 @@
required="True"
nolabel="1"/>
</group>
<div class="oe_edit_only">
<p>
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}
</p>
</div>
<group name="parties" string="Parties">
<group name="partner"
string="Partner">

View File

@@ -42,6 +42,13 @@
</group>
</group>
<field name="content" widget="html"/>
<div class="oe_edit_only">
<p>
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}
</p>
</div>
</sheet>
</form>
</field>

View File

@@ -44,6 +44,13 @@
</group>
</group>
<field name="content" widget="html"/>
<div class="oe_edit_only">
<p>
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}
</p>
</div>
</sheet>
</form>
</field>

View File

@@ -42,6 +42,13 @@
</group>
</group>
<field name="content" widget="html"/>
<div class="oe_edit_only">
<p>
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}
</p>
</div>
</sheet>
</form>
</field>

View File

@@ -44,6 +44,13 @@
<notebook>
<page string="Content">
<field name='content' nolabel="1"/>
<div class="oe_edit_only">
<p>
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}
</p>
</div>
</page>
<page string="Clauses">
<field name="clauses_ids"

View File

@@ -123,6 +123,12 @@
parent="agreement_configuration"
sequence="30"
action="partner_agreement_action_renewaltype"/>
<menuitem
name="Increase Types"
id="agreement_increamenttypes"
parent="agreement_configuration"
sequence="31"
action="partner_agreement_action_increasetype"/>
<menuitem
name="Stages"
id="agreement_stages"