Skip to content

Commit

Permalink
[FIX] purchase: fix mail templates
Browse files Browse the repository at this point in the history
Activate multi-company, deactivate the common contact book.
Create a PO P with user U1 in company A. Switch to company B.
User U2 in company A tries to send P by email.
Rendering of the template fails, because it tries to access object.create_uid,
which breaks multi-company record rules.

The signature was not working because it used user_id, a non-existing field,
instead of create_uid.

opw 1930521

closes #30868
  • Loading branch information
Nans Lefebvre committed Feb 6, 2019
1 parent 4f9fc18 commit a21864c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
15 changes: 10 additions & 5 deletions addons/purchase/data/mail_template_data.xml
Expand Up @@ -5,7 +5,7 @@
<!--Email template -->
<record id="email_template_edi_purchase" model="mail.template">
<field name="name">RFQ - Send by Email</field>
<field name="email_from">${(object.create_uid.email and '&quot;%s&quot; &lt;%s&gt;' % (object.create_uid.name, object.create_uid.email) or '')|safe}</field>
<field name="email_from">${(object.sudo().create_uid.email and '&quot;%s&quot; &lt;%s&gt;' % (object.sudo().create_uid.name, object.sudo().create_uid.email) or '')|safe}</field>
<field name="subject">${object.company_id.name} Order (Ref ${object.name or 'n/a' })</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
Expand All @@ -32,11 +32,11 @@ amounting in <strong>${format_amount(object.amount_total, object.currency_id)}</
from ${object.company_id.name}.
</p>
<p>Do not hesitate to contact us, further you have any question.</p>
<p>Do not hesitate to contact us if you have any further question.</p>
<p>Best regards,</p>
<p style="color:#888888;">
% if object.user_id and object.user_id.signature:
${object.user_id.signature | safe}
% if object.sudo().create_uid and object.sudo().create_uid.signature:
${object.sudo().create_uid.signature | safe}
% endif
</p>
]]></field>
Expand All @@ -46,7 +46,7 @@ from ${object.company_id.name}.
<!--Email template -->
<record id="email_template_edi_purchase_done" model="mail.template">
<field name="name">Purchase Order - Send by Email</field>
<field name="email_from">${(object.create_uid.email and '&quot;%s&quot; &lt;%s&gt;' % (object.create_uid.name, object.create_uid.email) or '')|safe}</field>
<field name="email_from">${(object.sudo().create_uid.email and '&quot;%s&quot; &lt;%s&gt;' % (object.sudo().create_uid.name, object.sudo().create_uid.email) or '')|safe}</field>
<field name="subject">${object.company_id.name} Order (Ref ${object.name or 'n/a' })</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
Expand Down Expand Up @@ -74,6 +74,11 @@ from ${object.company_id.name}.
<p>You can reply to this email if you have any questions.</p>
<p>Thank you,</p>
<p style="color:#888888;">
% if object.sudo().create_uid and object.sudo().create_uid.signature:
${object.sudo().create_uid.signature | safe}
% endif
</p>
]]></field>
</record>

Expand Down
11 changes: 8 additions & 3 deletions addons/purchase/i18n/purchase.pot
Expand Up @@ -36,11 +36,11 @@ msgid "\n"
"from ${object.company_id.name}.\n"
"</p>\n"
"\n"
"<p>Do not hesitate to contact us, further you have any question.</p>\n"
"<p>Do not hesitate to contact us if you have any further question.</p>\n"
"<p>Best regards,</p>\n"
"<p style=\"color:#888888;\">\n"
"% if object.user_id and object.user_id.signature:\n"
" ${object.user_id.signature | safe}\n"
"% if object.sudo().create_uid and object.sudo().create_uid.signature:\n"
" ${object.sudo().create_uid.signature | safe}\n"
"% endif\n"
"</p>\n"
""
Expand Down Expand Up @@ -68,6 +68,11 @@ msgid "\n"
"\n"
"<p>You can reply to this email if you have any questions.</p>\n"
"<p>Thank you,</p>\n"
"<p style=\"color:#888888;\">\n"
"% if object.sudo().create_uid and object.sudo().create_uid.signature:\n"
" ${object.sudo().create_uid.signature | safe}\n"
"% endif\n"
"</p>\n"
""
msgstr ""

Expand Down

0 comments on commit a21864c

Please sign in to comment.