Browse Source

Merge pull request #312 from ygol/12.0-feat-customparties

[IMP] agreement_legal: add custom dynamic parties
pull/318/head
Maxime Chambreuil 6 years ago
committed by GitHub
parent
commit
dae89f14c8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 52
      agreement_legal/models/agreement.py
  2. 9
      agreement_legal/report/agreement.xml
  3. 11
      agreement_legal/views/agreement.xml

52
agreement_legal/models/agreement.py

@ -170,6 +170,46 @@ class Agreement(models.Model):
company_contact_email = fields.Char(
related="company_contact_id.email", string="Email"
)
use_parties_content = fields.Boolean(
string="Use parties content",
help="Use custom content for parties")
def _get_default_parties(self):
deftext = """
<h3>Company Information</h3>
<p>
${object.company_partner_id.name or ''}.<br>
${object.company_partner_id.street or ''} <br>
${object.company_partner_id.state_id.code or ''}
${object.company_partner_id.zip or ''}
${object.company_partner_id.city or ''}<br>
${object.company_partner_id.country_id.name or ''}.<br><br>
Represented by <b>${object.company_contact_id.name or ''}.</b>
</p>
<p></p>
<h3>Partner Information</h3>
<p>
${object.partner_id.name or ''}.<br>
${object.partner_id.street or ''} <br>
${object.partner_id.state_id.code or ''}
${object.partner_id.zip or ''} ${object.partner_id.city or ''}<br>
${object.partner_id.country_id.name or ''}.<br><br>
Represented by <b>${object.partner_contact_id.name or ''}.</b>
</p>
"""
return deftext
parties = fields.Html(
string="Parties",
track_visibility="onchange",
default=_get_default_parties,
help="Parties of the agreement",
)
dynamic_parties = fields.Html(
compute="_compute_dynamic_parties",
string="Dynamic Parties",
help="Compute dynamic parties",
)
agreement_type_id = fields.Many2one(
"agreement.type",
string="Agreement Type",
@ -308,6 +348,18 @@ class Agreement(models.Model):
)
agreement.dynamic_description = description
@api.multi
def _compute_dynamic_parties(self):
MailTemplates = self.env["mail.template"]
for agreement in self:
lang = agreement.partner_id.lang or "en_US"
parties = MailTemplates.with_context(
lang=lang
)._render_template(
agreement.parties, "agreement", agreement.id
)
agreement.dynamic_parties = parties
@api.multi
def _compute_dynamic_special_terms(self):
MailTemplates = self.env["mail.template"]

9
agreement_legal/report/agreement.xml

@ -25,9 +25,15 @@
<div class="page">
<h1 t-field="doc.name"/>
<div name="description">
<p t-field="doc.dynamic_description"/>
<span t-field="doc.dynamic_description"/>
</div>
<h2>Parties</h2>
<div name="parties">
<t t-if="doc.use_parties_content">
<p t-field="doc.dynamic_parties"/>
</t>
</div>
<t t-if="not doc.use_parties_content">
<h3>Company Information</h3>
<div name="company_address">
<address t-field="doc.company_partner_id"
@ -44,6 +50,7 @@
<div name="partner_contact">
Represented by <span t-field="doc.partner_contact_id.name"/>.
</div>
</t>
<h2>Agreement</h2>
<h3>Recitals</h3>
<table class="table table-condensed">

11
agreement_legal/views/agreement.xml

@ -90,6 +90,14 @@
</p>
</group>
<group name="parties" string="Parties">
<group name="cust_parties">
<field name="use_parties_content" string="Use custom content" />
</group>
<group name="cust_parties">
<p>
This section (on the left) allows you to replace the default listing of the parties with custom dynamic content.
</p>
</group>
<group name="partner"
string="Partner">
<div class="o_address_format">
@ -119,6 +127,9 @@
<field name="company_contact_email" widget="email" readonly="1" nolabel="1"/>
</group>
</group>
<group name="parties_content" string="Parties Content" attrs="{'invisible':[('use_parties_content', '=', False)]}">
<field name="parties" nolabel="1"/>
</group>
<group name="term_information">
<group name="termdates_left" string="Term Dates">
<field name="start_date" attrs="{'required': [('is_template', '=', False)], 'invisible': [('is_template', '=', True)]}"/>

Loading…
Cancel
Save