Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] email_template_qweb #1361

Open
wants to merge 46 commits into
base: 17.0
Choose a base branch
from

Conversation

AnaisLForgeFlow
Copy link

Standard Migration

@ForgeFlow

lasley and others added 30 commits April 29, 2024 12:01
If the result is of type unicode, render method encodes it in utf-8.
We need to decode it in that case so that the rendering results correct.
Updated by Update PO files to match POT (msgmerge) hook in Weblate.
Currently translated at 88.9% (8 of 9 strings)

Translation: social-12.0/social-12.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-12-0/social-12-0-email_template_qweb/pt_BR/
Currently translated at 100.0% (9 of 9 strings)

Translation: social-12.0/social-12.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-12-0/social-12-0-email_template_qweb/pt_BR/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: social-13.0/social-13.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-13-0/social-13-0-email_template_qweb/
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: social-13.0/social-13.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-13-0/social-13-0-email_template_qweb/
Currently translated at 80.0% (8 of 10 strings)

Translation: social-14.0/social-14.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-14-0/social-14-0-email_template_qweb/fr/
Currently translated at 76.9% (10 of 13 strings)

Translation: social-14.0/social-14.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-14-0/social-14-0-email_template_qweb/fr_FR/
Translations were broken, things hav changed in 14.0 and we need to call
`_classify_per_lang` method to get the right lang, and use it to render
the content.
fshah-initos and others added 15 commits April 29, 2024 12:01
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/
Currently translated at 63.6% (7 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/it/
Currently translated at 100.0% (11 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/es/
Currently translated at 63.6% (7 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/it/
Currently translated at 100.0% (11 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/it/
Currently translated at 100.0% (11 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/it/
Currently translated at 100.0% (11 of 11 strings)

Translation: social-16.0/social-16.0-email_template_qweb
Translate-URL: https://translation.odoo-community.org/projects/social-16-0/social-16-0-email_template_qweb/pt_BR/
@AnaisLForgeFlow AnaisLForgeFlow force-pushed the 17.0-mig-email_template_qweb branch from 708f3e2 to 4c4c80b Compare May 6, 2024 11:09
@pedrobaeza
Copy link
Member

/ocabot migration email_template_qweb

@OCA-git-bot OCA-git-bot added this to the 17.0 milestone May 6, 2024
@OCA-git-bot OCA-git-bot mentioned this pull request May 6, 2024
30 tasks
Copy link
Contributor

@GuillemCForgeFlow GuillemCForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the rest, LGTM 👍🏿

email_template_qweb/views/mail_template.xml Show resolved Hide resolved
@AnaisLForgeFlow AnaisLForgeFlow force-pushed the 17.0-mig-email_template_qweb branch from 4c4c80b to 912b94e Compare May 8, 2024 09:10
@Rad0van
Copy link
Contributor

Rad0van commented Jun 1, 2024

While it works fine in some contexts it doesn't work in this scenario:

  1. There is a template and a related view created. In my case through data/email_templates.xml - the same way as in here:
    <?xml version="1.0" encoding="UTF-8" ?>
    <odoo>
    <record id="email_template_demo1" model="mail.template">
    <field name="name">QWeb demo</field>
    <field name="body_type">qweb_view</field>
    <field name="body_view_id" ref="view_email_template_demo1" />
    <field name="model_id" ref="base.model_res_users" />
    <field name="subject">QWeb demo email</field>
    </record>
    </odoo>
  2. You open email composer from code using something similar to this: https://github.com/odoo/odoo/blob/7564e62114721d6e57c3f4c3d306612d5daaf2e0/addons/sale/models/sale_order.py#L843-L870
  3. What you get is an empty email body :-(

The reason being is this:

  1. Mail composer computes the body here: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/mail/wizard/mail_compose_message.py#L226-L235
  2. Which calls this one: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/mail/wizard/mail_compose_message.py#L1385-L1406

This line is the culprit:
template_value = self.template_id[template_fname] if self.template_id else False

template_fname contains "body_html" However that attribute is not defined in data XML so it returns with no body being rendered.

This usecase used to work in 16.0

Comment on lines +30 to +39
custom_context = {
"object": record,
"email_template": self,
"format_datetime": lambda dt,
tz=False,
dt_format=False,
lang_code=False: format_datetime(
self.env, dt, tz, dt_format, lang_code
),
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
custom_context = {
"object": record,
"email_template": self,
"format_datetime": lambda dt,
tz=False,
dt_format=False,
lang_code=False: format_datetime(
self.env, dt, tz, dt_format, lang_code
),
}
custom_context = self._render_eval_context()
custom_context.update(
{
"object": record,
"email_template": self,
"format_datetime": lambda dt, tz=False, dt_format=False, lang_code=False: format_datetime(
self.env, dt, tz, dt_format, lang_code
),
}
)

This is akin to #1249

@Rad0van
Copy link
Contributor

Rad0van commented Aug 4, 2024

While it works fine in some contexts it doesn't work in this scenario:

  1. There is a template and a related view created. In my case through data/email_templates.xml - the same way as in here:
    <?xml version="1.0" encoding="UTF-8" ?>
    <odoo>
    <record id="email_template_demo1" model="mail.template">
    <field name="name">QWeb demo</field>
    <field name="body_type">qweb_view</field>
    <field name="body_view_id" ref="view_email_template_demo1" />
    <field name="model_id" ref="base.model_res_users" />
    <field name="subject">QWeb demo email</field>
    </record>
    </odoo>
  2. You open email composer from code using something similar to this: https://github.com/odoo/odoo/blob/7564e62114721d6e57c3f4c3d306612d5daaf2e0/addons/sale/models/sale_order.py#L843-L870
  3. What you get is an empty email body :-(

The reason being is this:

  1. Mail composer computes the body here: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/mail/wizard/mail_compose_message.py#L226-L235
  2. Which calls this one: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/mail/wizard/mail_compose_message.py#L1385-L1406

This line is the culprit: template_value = self.template_id[template_fname] if self.template_id else False

template_fname contains "body_html" However that attribute is not defined in data XML so it returns with no body being rendered.

This usecase used to work in 16.0

I see 2 possible fixes here:

  1. override the _compute_body in mail/wizard
    /mail_compose_message.py
    - this does not feel exactly right but would do
  2. sneak in some dummy body_html in our implementation of _generate_template - this does not feel right even more

Any ideas? Maybe @pedrobaeza ?

@pedrobaeza
Copy link
Member

Check where self.template_id[template_fname] is fed and fill it with the QWeb render result.

@Rad0van
Copy link
Contributor

Rad0van commented Aug 5, 2024

Check where self.template_id[template_fname] is fed and fill it with the QWeb render result.

Thanks for quick reply but I am not sure I follow :-(
In my opinion it is not fed anywhere - it is part of the mail.template: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/mail/models/mail_template.py#L63-L65

For common templates it is filled in like this: https://github.com/odoo/odoo/blob/aff187f814998f4825da25f273eacef724686da3/addons/sale/data/mail_template_data.xml#L11-L41

In the _compute_body method it asks for "body_html" exactly.

So I fail to see how to feed the result QWeb render to it...

@pedrobaeza
Copy link
Member

Well, I didn't know as well the internals, but it seems the __get__ of the model or something is overriden to get that weird behavior returning a specific body when you pass the XML-ID.

@simahawk
Copy link
Contributor

This modules is not needed anymore. See #1480
Do you see any case where it could still provide value?

@simahawk
Copy link
Contributor

This modules is not needed anymore. See #1480 Do you see any case where it could still provide value?

ops, this is still v17 not v18. Sorry... However, as is not merged yet, we could evaluate if we can get rid of it already in v17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.