[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">
<field name="name">Contract modifications</field>
<field name="res_model">contract.contract</field>
<field name="default" eval="False"/>
</record>
</odoo>

View File

@@ -62,22 +62,39 @@
</div>
]]></field>
</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>We have modifications on the contract <strong t-esc="object.name" /> that we want to notify you.</p>
<table border="1">
<p>We have modifications on the contract that we want to notify you.</p>
]]></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>
<tr>
<th>Date</th>
<th>Description</th>
<th name="th_date">Date</th>
<th name="th_description">Description</th>
</tr>
</thead>
<tbody>
<t t-foreach="object.modification_ids" t-as="notification_id">
<tr t-if="not notification_id.sent">
<td><span t-field="notification_id.date" /></td>
<td><div t-field="notification_id.description" /></td>
<t t-foreach="record.modification_ids" t-as="modification">
<tr t-if="not modification.sent">
<td name="td_date"><span t-field="modification.date" /></td>
<td name="td_description"><div t-field="modification.description" /></td>
</tr>
</t>
</tbody>

View File

@@ -6,8 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 16:39+0000\n"
"PO-Revision-Date: 2020-12-23 16:39+0000\n"
"POT-Creation-Date: 2020-12-24 08:24+0000\n"
"PO-Revision-Date: 2020-12-24 08:24+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@@ -15,6 +15,14 @@ msgstr ""
"Content-Transfer-Encoding: \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
#: model:mail.template,body_html:contract.email_contract_template
msgid "\n"
@@ -74,6 +82,11 @@ msgstr ""
msgid "${object.company_id.name} Contract (Ref ${object.name or 'n/a'})"
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
#: 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"
@@ -411,7 +424,7 @@ msgid "Company"
msgstr ""
#. module: contract
#: code:addons/contract/models/contract.py:436
#: code:addons/contract/models/contract.py:441
#, python-format
msgid "Compose Email"
msgstr ""
@@ -638,7 +651,7 @@ msgid "Contract lines"
msgstr ""
#. module: contract
#: code:addons/contract/models/contract.py:592
#: code:addons/contract/models/contract.py:597
#, python-format
msgid "Contract manually invoiced: <a href=\"#\" data-oe-model=\"%s\" data-oe-id=\"%s\">Invoice</a>"
msgstr ""
@@ -767,6 +780,7 @@ msgstr ""
#: 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.report_contract_document
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
#, python-format
msgid "Date"
msgstr ""
@@ -926,11 +940,6 @@ msgstr ""
msgid "Group By..."
msgstr ""
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "Hello"
msgstr ""
#. 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_line__id
@@ -1357,7 +1366,7 @@ msgid "Planned"
msgstr ""
#. module: contract
#: code:addons/contract/models/contract.py:394
#: code:addons/contract/models/contract.py:399
#, python-format
msgid "Please define a %s journal for the company '%s'."
msgstr ""
@@ -1591,7 +1600,6 @@ msgstr ""
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_line__state
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "State"
msgstr ""
@@ -1692,7 +1700,7 @@ msgid "Technical field for UX purpose."
msgstr ""
#. 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_terminate_form_view
#, python-format
@@ -1841,11 +1849,6 @@ msgstr ""
msgid "View"
msgstr ""
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "We have modifications on the contract"
msgstr ""
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids
msgid "Website Messages"
@@ -1901,7 +1904,7 @@ msgid "Year(s)"
msgstr ""
#. module: contract
#: code:addons/contract/models/contract.py:641
#: code:addons/contract/models/contract.py:646
#, python-format
msgid "You are not allowed to terminate contracts."
msgstr ""
@@ -1952,8 +1955,3 @@ msgstr ""
msgid "on"
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 ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-23 16:39+0000\n"
"PO-Revision-Date: 2020-12-23 18:14+0100\n"
"POT-Creation-Date: 2020-12-24 08:24+0000\n"
"PO-Revision-Date: 2020-12-24 09:28+0100\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: es\n"
@@ -17,6 +17,21 @@ msgstr ""
"Plural-Forms: \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
#: model:mail.template,body_html:contract.email_contract_template
msgid ""
@@ -155,6 +170,15 @@ msgstr ""
msgid "${object.company_id.name} Contract (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
#: model_terms:ir.ui.view,arch_db:contract.contract_manually_create_invoice_form_view
msgid ""
@@ -512,7 +536,7 @@ msgid "Company"
msgstr "Compañía"
#. module: contract
#: code:addons/contract/models/contract.py:436
#: code:addons/contract/models/contract.py:441
#, python-format
msgid "Compose Email"
msgstr "Componer correo electrónico"
@@ -767,7 +791,7 @@ msgid "Contract lines"
msgstr "Líneas de contrato"
#. module: contract
#: code:addons/contract/models/contract.py:592
#: code:addons/contract/models/contract.py:597
#, python-format
msgid ""
"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_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.template_contract_modification
#, python-format
msgid "Date"
msgstr "Fecha"
@@ -1068,11 +1093,6 @@ msgstr "Grupo"
msgid "Group By..."
msgstr "Agrupar por..."
#. module: contract
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "Hello"
msgstr "Hola"
#. 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_line__id
@@ -1092,7 +1112,7 @@ msgstr "ID"
#. module: contract
#: model:ir.model.fields,help:contract.field_contract_contract__message_unread
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
#: model:ir.model.fields,help:contract.field_res_company__create_new_line_at_contract_line_renew
@@ -1520,7 +1540,7 @@ msgid "Planned"
msgstr "Planificado"
#. module: contract
#: code:addons/contract/models/contract.py:394
#: code:addons/contract/models/contract.py:399
#, python-format
msgid "Please define a %s journal for the company '%s'."
msgstr "Por favor defina un diario de %s para la compañía '%s'."
@@ -1758,9 +1778,8 @@ msgstr ""
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_line__state
#: model_terms:ir.ui.view,arch_db:contract.template_contract_modification
msgid "State"
msgstr "Provincia"
msgstr "Estado"
#. module: contract
#: 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_template_line__display_type
msgid "Technical field for UX purpose."
msgstr "Campo técnico para propósitos UX"
msgstr "Campo técnico para propósitos UX."
#. 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_terminate_form_view
#, python-format
@@ -2018,11 +2037,6 @@ msgstr "Validar"
msgid "View"
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
#: model:ir.model.fields,field_description:contract.field_contract_contract__website_message_ids
msgid "Website Messages"
@@ -2078,7 +2092,7 @@ msgid "Year(s)"
msgstr "Año(s)"
#. module: contract
#: code:addons/contract/models/contract.py:641
#: code:addons/contract/models/contract.py:646
#, python-format
msgid "You are not allowed to terminate contracts."
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
msgid "on"
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,20 +150,24 @@ class ContractContract(models.Model):
@api.model
def _modification_mail_send(self):
modification_ids_not_sent = self.modification_ids.filtered(
for record in self:
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_modification_subtype = self.env.ref(
'contract.mail_message_subtype_contract_modification'
)
notified_partners = self.message_follower_ids.filtered(
notified_partners = record.message_follower_ids.filtered(
lambda x: contract_modification_subtype in x.subtype_ids
).mapped('partner_id')
if notified_partners:
self.message_post_with_view(
'mail.email_contract_modification_template',
partner_ids=notified_partners.ids,
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})

View File

@@ -28,7 +28,6 @@ class ContractModification(models.Model):
sent = fields.Boolean(
string='Sent',
default=False,
readonly=True,
)
@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([
("model", "=", "contract.contract"),
("res_id", "=", self.contract.id),