Browse Source

[ADD] custom dynamic parties

pull/312/head
Yves Goldberg 6 years ago
parent
commit
9bf56092b6
  1. 26
      agreement_legal/models/agreement.py
  2. 39
      agreement_legal/report/agreement.xml
  3. 13
      agreement_legal/views/agreement.xml

26
agreement_legal/models/agreement.py

@ -170,6 +170,20 @@ 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",
default = False,
help="Use custom content for parties" )
parties = fields.Html(
string="Parties",
track_visibility="onchange",
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 +322,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">

13
agreement_legal/views/agreement.xml

@ -90,7 +90,15 @@
</p> </p>
</group> </group>
<group name="parties" string="Parties"> <group name="parties" string="Parties">
<group name="partner"
<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"> string="Partner">
<div class="o_address_format"> <div class="o_address_format">
<field name="partner_id" <field name="partner_id"
@ -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