[FIX+IMP] contract: Make template to work + other refinements

- Contract modification subtype non default
- Hybrid template between mail.template Jinja + inheritable QWeb
- QWeb element qualified for easing inheritance
- Translations updated
- _modification_mail_send multi-record
- Tests resilience
This commit is contained in:
Pedro M. Baeza
2020-12-23 21:08:59 +01:00
parent a9f65b439a
commit c09c93cda6
7 changed files with 103 additions and 75 deletions

View File

@@ -7,5 +7,6 @@
<record id="mail_message_subtype_contract_modification" model="mail.message.subtype"> <record id="mail_message_subtype_contract_modification" model="mail.message.subtype">
<field name="name">Contract modifications</field> <field name="name">Contract modifications</field>
<field name="res_model">contract.contract</field> <field name="res_model">contract.contract</field>
<field name="default" eval="False"/>
</record> </record>
</odoo> </odoo>

View File

@@ -62,22 +62,39 @@
</div> </div>
]]></field> ]]></field>
</record> </record>
<template id="template_contract_modification" name="Contract Modification">
<t t-call="email_template_qweb.view_email_template_corporate_identity"> <record id="mail_template_contract_modification" model="mail.template">
<field name="name">Contract Modification Template</field>
<field name="email_from">${(object.user_id.email and '%s &lt;%s&gt;' % (object.user_id.name, object.user_id.email) or '')|safe}</field>
<field name="subject">${object.company_id.name} Contract (Ref ${object.name or 'n/a'}) - Modifications</field>
<field name="model_id" ref="model_contract_contract"/>
<field name="lang">${object.partner_id.lang}</field>
<field name="body_html"><![CDATA[
<p>Hello</p> <p>Hello</p>
<p>We have modifications on the contract <strong t-esc="object.name" /> that we want to notify you.</p> <p>We have modifications on the contract that we want to notify you.</p>
<table border="1"> ]]></field>
</record>
<template id="mail_notification_contract" inherit_id="mail.mail_notification_paynow" primary="True">
<xpath expr="//t[@t-raw='message.body']" position="after">
<t t-raw="0"/>
</xpath>
</template>
<template id="template_contract_modification" name="Contract Modification">
<t t-call="contract.mail_notification_contract">
<table border="1" align="center">
<thead> <thead>
<tr> <tr>
<th>Date</th> <th name="th_date">Date</th>
<th>Description</th> <th name="th_description">Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<t t-foreach="object.modification_ids" t-as="notification_id"> <t t-foreach="record.modification_ids" t-as="modification">
<tr t-if="not notification_id.sent"> <tr t-if="not modification.sent">
<td><span t-field="notification_id.date" /></td> <td name="td_date"><span t-field="modification.date" /></td>
<td><div t-field="notification_id.description" /></td> <td name="td_description"><div t-field="modification.description" /></td>
</tr> </tr>
</t> </t>
</tbody> </tbody>

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 16:39+0000\n" "POT-Creation-Date: 2020-12-24 08:24+0000\n"
"PO-Revision-Date: 2020-12-23 16:39+0000\n" "PO-Revision-Date: 2020-12-24 08:24+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@@ -15,6 +15,14 @@ msgstr ""
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: contract
#: model:mail.template,body_html:contract.mail_template_contract_modification
msgid "\n"
" <p>Hello</p>\n"
" <p>We have modifications on the contract that we want to notify you.</p>\n"
" "
msgstr ""
#. module: contract #. module: contract
#: model:mail.template,body_html:contract.email_contract_template #: model:mail.template,body_html:contract.email_contract_template
msgid "\n" msgid "\n"
@@ -74,6 +82,11 @@ msgstr ""
msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'})" msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'})"
msgstr "" msgstr ""
#. module: contract
#: model:mail.template,subject:contract.mail_template_contract_modification
msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'}) - Modifications"
msgstr ""
#. module: contract #. module: contract
#: model_terms:ir.ui.view,arch_db:contract.contract_manually_create_invoice_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_manually_create_invoice_form_view
msgid "<span attrs=\"{'invisible': [('contract_to_invoice_count', '&gt;', 1)]}\">\n" msgid "<span attrs=\"{'invisible': [('contract_to_invoice_count', '&gt;', 1)]}\">\n"
@@ -411,7 +424,7 @@ msgid "Company"
msgstr "" msgstr ""
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:436 #: code:addons/contract/models/contract.py:441
#, python-format #, python-format
msgid "Compose Email" msgid "Compose Email"
msgstr "" msgstr ""
@@ -638,7 +651,7 @@ msgid "Contract lines"
msgstr "" msgstr ""
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:592 #: code:addons/contract/models/contract.py:597
#, python-format #, python-format
msgid "Contract manually invoiced: <a href=\"#\" data-oe-model=\"%s\" data-oe-id=\"%s\">Invoice</a>" msgid "Contract manually invoiced: <a href=\"#\" data-oe-model=\"%s\" data-oe-id=\"%s\">Invoice</a>"
msgstr "" msgstr ""
@@ -767,6 +780,7 @@ msgstr ""
#: model:ir.model.fields,field_description:contract.field_contract_modification__date #: model:ir.model.fields,field_description:contract.field_contract_modification__date
#: model_terms:ir.ui.view,arch_db:contract.portal_my_contracts #: model_terms:ir.ui.view,arch_db:contract.portal_my_contracts
#: model_terms:ir.ui.view,arch_db:contract.report_contract_document #: model_terms:ir.ui.view,arch_db:contract.report_contract_document
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
#, python-format #, python-format
msgid "Date" msgid "Date"
msgstr "" msgstr ""
@@ -926,11 +940,6 @@ msgstr ""
msgid "Group By..." msgid "Group By..."
msgstr "" msgstr ""
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "Hello"
msgstr ""
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract__id #: model:ir.model.fields,field_description:contract.field_contract_abstract_contract__id
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract_line__id #: model:ir.model.fields,field_description:contract.field_contract_abstract_contract_line__id
@@ -1357,7 +1366,7 @@ msgid "Planned"
msgstr "" msgstr ""
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:394 #: code:addons/contract/models/contract.py:399
#, python-format #, python-format
msgid "Please define a %s journal for the company '%s'." msgid "Please define a %s journal for the company '%s'."
msgstr "" msgstr ""
@@ -1591,7 +1600,6 @@ msgstr ""
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_line__state #: model:ir.model.fields,field_description:contract.field_contract_line__state
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "State" msgid "State"
msgstr "" msgstr ""
@@ -1692,7 +1700,7 @@ msgid "Technical field for UX purpose."
msgstr "" msgstr ""
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:627 #: code:addons/contract/models/contract.py:632
#: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view
#: model_terms:ir.ui.view,arch_db:contract.contract_contract_terminate_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_contract_terminate_form_view
#, python-format #, python-format
@@ -1841,11 +1849,6 @@ msgstr ""
msgid "View" msgid "View"
msgstr "" msgstr ""
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "We have modifications on the contract"
msgstr ""
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids #: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids
msgid "Website Messages" msgid "Website Messages"
@@ -1901,7 +1904,7 @@ msgid "Year(s)"
msgstr "" msgstr ""
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:641 #: code:addons/contract/models/contract.py:646
#, python-format #, python-format
msgid "You are not allowed to terminate contracts." msgid "You are not allowed to terminate contracts."
msgstr "" msgstr ""
@@ -1952,8 +1955,3 @@ msgstr ""
msgid "on" msgid "on"
msgstr "" msgstr ""
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "that we want to notify you."
msgstr ""

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 16:39+0000\n" "POT-Creation-Date: 2020-12-24 08:24+0000\n"
"PO-Revision-Date: 2020-12-23 18:14+0100\n" "PO-Revision-Date: 2020-12-24 09:28+0100\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: es\n" "Language: es\n"
@@ -17,6 +17,21 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
"X-Generator: Poedit 2.3\n" "X-Generator: Poedit 2.3\n"
#. module: contract
#: model:mail.template,body_html:contract.mail_template_contract_modification
msgid ""
"\n"
" <p>Hello</p>\n"
" <p>We have modifications on the contract that we want to notify "
"you.</p>\n"
" "
msgstr ""
"\n"
" <p>Hola</p>\n"
" <p>Tenemos modificaciones en el contrato que queremos "
"notificarle.</p>\n"
" "
#. module: contract #. module: contract
#: model:mail.template,body_html:contract.email_contract_template #: model:mail.template,body_html:contract.email_contract_template
msgid "" msgid ""
@@ -155,6 +170,15 @@ msgstr ""
msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'})" msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'})"
msgstr "${object.company_id.name} Contrato (Ref ${object.name or 'n/a'})" msgstr "${object.company_id.name} Contrato (Ref ${object.name or 'n/a'})"
#. module: contract
#: model:mail.template,subject:contract.mail_template_contract_modification
msgid ""
"${object.company_id.name} Contract (Ref ${object.name or 'n/a'}) - "
"Modifications"
msgstr ""
"${object.company_id.name} Contrato (Ref ${object.name or 'n/a'}) - "
"Modificaciones"
#. module: contract #. module: contract
#: model_terms:ir.ui.view,arch_db:contract.contract_manually_create_invoice_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_manually_create_invoice_form_view
msgid "" msgid ""
@@ -512,7 +536,7 @@ msgid "Company"
msgstr "Compañía" msgstr "Compañía"
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:436 #: code:addons/contract/models/contract.py:441
#, python-format #, python-format
msgid "Compose Email" msgid "Compose Email"
msgstr "Componer correo electrónico" msgstr "Componer correo electrónico"
@@ -767,7 +791,7 @@ msgid "Contract lines"
msgstr "Líneas de contrato" msgstr "Líneas de contrato"
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:592 #: code:addons/contract/models/contract.py:597
#, python-format #, python-format
msgid "" msgid ""
"Contract manually invoiced: <a href=\"#\" data-oe-model=\"%s\" data-oe-id=" "Contract manually invoiced: <a href=\"#\" data-oe-model=\"%s\" data-oe-id="
@@ -900,6 +924,7 @@ msgstr "URL para portal"
#: model:ir.model.fields,field_description:contract.field_contract_modification__date #: model:ir.model.fields,field_description:contract.field_contract_modification__date
#: model_terms:ir.ui.view,arch_db:contract.portal_my_contracts #: model_terms:ir.ui.view,arch_db:contract.portal_my_contracts
#: model_terms:ir.ui.view,arch_db:contract.report_contract_document #: model_terms:ir.ui.view,arch_db:contract.report_contract_document
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
#, python-format #, python-format
msgid "Date" msgid "Date"
msgstr "Fecha" msgstr "Fecha"
@@ -1068,11 +1093,6 @@ msgstr "Grupo"
msgid "Group By..." msgid "Group By..."
msgstr "Agrupar por..." msgstr "Agrupar por..."
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "Hello"
msgstr "Hola"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract__id #: model:ir.model.fields,field_description:contract.field_contract_abstract_contract__id
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract_line__id #: model:ir.model.fields,field_description:contract.field_contract_abstract_contract_line__id
@@ -1092,7 +1112,7 @@ msgstr "ID"
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_contract_contract__message_unread #: model:ir.model.fields,help:contract.field_contract_contract__message_unread
msgid "If checked new messages require your attention." msgid "If checked new messages require your attention."
msgstr "Si está marcado, hay nuevos mensajes que requieren su atención" msgstr "Si está marcado, hay nuevos mensajes que requieren su atención."
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_res_company__create_new_line_at_contract_line_renew #: model:ir.model.fields,help:contract.field_res_company__create_new_line_at_contract_line_renew
@@ -1520,7 +1540,7 @@ msgid "Planned"
msgstr "Planificado" msgstr "Planificado"
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:394 #: code:addons/contract/models/contract.py:399
#, python-format #, python-format
msgid "Please define a %s journal for the company '%s'." msgid "Please define a %s journal for the company '%s'."
msgstr "Por favor defina un diario de %s para la compañía '%s'." msgstr "Por favor defina un diario de %s para la compañía '%s'."
@@ -1758,9 +1778,8 @@ msgstr ""
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_line__state #: model:ir.model.fields,field_description:contract.field_contract_line__state
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "State" msgid "State"
msgstr "Provincia" msgstr "Estado"
#. module: contract #. module: contract
#: model:ir.model.fields,help:contract.field_contract_contract__activity_state #: model:ir.model.fields,help:contract.field_contract_contract__activity_state
@@ -1861,10 +1880,10 @@ msgstr "Etiquetas"
#: model:ir.model.fields,help:contract.field_contract_line__display_type #: model:ir.model.fields,help:contract.field_contract_line__display_type
#: model:ir.model.fields,help:contract.field_contract_template_line__display_type #: model:ir.model.fields,help:contract.field_contract_template_line__display_type
msgid "Technical field for UX purpose." msgid "Technical field for UX purpose."
msgstr "Campo técnico para propósitos UX" msgstr "Campo técnico para propósitos UX."
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:627 #: code:addons/contract/models/contract.py:632
#: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view
#: model_terms:ir.ui.view,arch_db:contract.contract_contract_terminate_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_contract_terminate_form_view
#, python-format #, python-format
@@ -2018,11 +2037,6 @@ msgstr "Validar"
msgid "View" msgid "View"
msgstr "Ver" msgstr "Ver"
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "We have modifications on the contract"
msgstr "Tenemos modificaciones en el contrato"
#. module: contract #. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids #: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids
msgid "Website Messages" msgid "Website Messages"
@@ -2078,7 +2092,7 @@ msgid "Year(s)"
msgstr "Año(s)" msgstr "Año(s)"
#. module: contract #. module: contract
#: code:addons/contract/models/contract.py:641 #: code:addons/contract/models/contract.py:646
#, python-format #, python-format
msgid "You are not allowed to terminate contracts." msgid "You are not allowed to terminate contracts."
msgstr "No tiene permitido rescindir contratos." msgstr "No tiene permitido rescindir contratos."
@@ -2146,8 +2160,3 @@ msgstr "ejemplo Contrato XYZ"
#: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view #: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view
msgid "on" msgid "on"
msgstr "de" msgstr "de"
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "that we want to notify you."
msgstr "que queremos notificarle."

View File

@@ -150,22 +150,26 @@ class ContractContract(models.Model):
@api.model @api.model
def _modification_mail_send(self): def _modification_mail_send(self):
modification_ids_not_sent = self.modification_ids.filtered( for record in self:
lambda x: not x.sent modification_ids_not_sent = record.modification_ids.filtered(
) lambda x: not x.sent
if modification_ids_not_sent:
contract_modification_subtype = self.sudo().env.ref(
'contract.mail_message_subtype_contract_modification'
) )
notified_partners = self.message_follower_ids.filtered( if modification_ids_not_sent:
lambda x: contract_modification_subtype in x.subtype_ids contract_modification_subtype = self.env.ref(
).mapped('partner_id') 'contract.mail_message_subtype_contract_modification'
if notified_partners:
self.message_post_with_view(
'mail.email_contract_modification_template',
partner_ids=notified_partners.ids,
) )
modification_ids_not_sent.write({'sent': True}) notified_partners = record.message_follower_ids.filtered(
lambda x: contract_modification_subtype in x.subtype_ids
).mapped('partner_id')
if notified_partners:
record.message_post_with_template(
self.env.ref(
"contract.mail_template_contract_modification"
).id,
partner_ids=[(4, x.id) for x in notified_partners],
notif_layout="contract.template_contract_modification",
)
modification_ids_not_sent.write({'sent': True})
@api.multi @api.multi
def _inverse_partner_id(self): def _inverse_partner_id(self):

View File

@@ -28,7 +28,6 @@ class ContractModification(models.Model):
sent = fields.Boolean( sent = fields.Boolean(
string='Sent', string='Sent',
default=False, default=False,
readonly=True,
) )
@api.model_create_multi @api.model_create_multi

View File

@@ -163,7 +163,7 @@ class TestContract(TestContractBase):
) )
] ]
}) })
self.assertEqual(len(self.contract.message_partner_ids.ids), 2) self.assertGreaterEqual(len(self.contract.message_partner_ids), 2)
mail_messages = self.env["mail.message"].search([ mail_messages = self.env["mail.message"].search([
("model", "=", "contract.contract"), ("model", "=", "contract.contract"),
("res_id", "=", self.contract.id), ("res_id", "=", self.contract.id),