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. 39
      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( company_contact_email = fields.Char(
related="company_contact_id.email", string="Email" 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_id = fields.Many2one(
"agreement.type", "agreement.type",
string="Agreement Type", string="Agreement Type",
@ -308,6 +348,18 @@ class Agreement(models.Model):
) )
agreement.dynamic_description = description 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 @api.multi
def _compute_dynamic_special_terms(self): def _compute_dynamic_special_terms(self):
MailTemplates = self.env["mail.template"] MailTemplates = self.env["mail.template"]

39
agreement_legal/report/agreement.xml

@ -25,25 +25,32 @@
<div class="page"> <div class="page">
<h1 t-field="doc.name"/> <h1 t-field="doc.name"/>
<div name="description"> <div name="description">
<p t-field="doc.dynamic_description"/>
<span t-field="doc.dynamic_description"/>
</div> </div>
<h2>Parties</h2> <h2>Parties</h2>
<h3>Company Information</h3>
<div name="company_address">
<address t-field="doc.company_partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
</div>
<div name="company_contact">
Represented by <span t-field="doc.company_contact_id.name"/>.
</div>
<h3>Partner Information</h3>
<div name="partner_address">
<address t-field="doc.partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
</div>
<div name="partner_contact">
Represented by <span t-field="doc.partner_contact_id.name"/>.
<div name="parties">
<t t-if="doc.use_parties_content">
<p t-field="doc.dynamic_parties"/>
</t>
</div> </div>
<t t-if="not doc.use_parties_content">
<h3>Company Information</h3>
<div name="company_address">
<address t-field="doc.company_partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
</div>
<div name="company_contact">
Represented by <span t-field="doc.company_contact_id.name"/>.
</div>
<h3>Partner Information</h3>
<div name="partner_address">
<address t-field="doc.partner_id"
t-options='{"widget": "contact", "fields": ["address", "name"], "no_marker": True}' />
</div>
<div name="partner_contact">
Represented by <span t-field="doc.partner_contact_id.name"/>.
</div>
</t>
<h2>Agreement</h2> <h2>Agreement</h2>
<h3>Recitals</h3> <h3>Recitals</h3>
<table class="table table-condensed"> <table class="table table-condensed">

11
agreement_legal/views/agreement.xml

@ -90,6 +90,14 @@
</p> </p>
</group> </group>
<group name="parties" string="Parties"> <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" <group name="partner"
string="Partner"> string="Partner">
<div class="o_address_format"> <div class="o_address_format">
@ -119,6 +127,9 @@
<field name="company_contact_email" widget="email" readonly="1" nolabel="1"/> <field name="company_contact_email" widget="email" readonly="1" nolabel="1"/>
</group> </group>
</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="term_information">
<group name="termdates_left" string="Term Dates"> <group name="termdates_left" string="Term Dates">
<field name="start_date" attrs="{'required': [('is_template', '=', False)], 'invisible': [('is_template', '=', True)]}"/> <field name="start_date" attrs="{'required': [('is_template', '=', False)], 'invisible': [('is_template', '=', True)]}"/>

Loading…
Cancel
Save