[19.0][FIX] loyalty: clear stale mail.template.lang referencing removed _get_mail_partner#5629
Conversation
68659a1 to
50d63b6
Compare
Add the merges introduced by today's PR series so the auto-built image includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again: - 19.0-fix-hr-null-write-date (OCA#5628) - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629) - 19.0-fix-hr-obsolete-fields-cleanup (OCA#5630) - 19.0-fix-partner-autocomplete-cleanup (OCA#5631) - 19.0-fix-l10n-fr-cleanup (OCA#5632) The companion lab repos.yaml is updated separately so local `make sync-repos` matches.
There was a problem hiding this comment.
Good catch, but too many lines of code for something that can be very easy on post-migration scripts:
for xmlid in ("mail_template_gift_card", "mail_template_loyalty_card"):
template = env.ref(xmlid, False)
if template:
template.lang = FalseAnd you can reduce the comments done with AI to something less verbose.
|
@pedrobaeza what do you think on the comments. in the past I would write the code fix and put the comment son the PR and never really but comments in the code. should there be any code comments? seems like they will just be obsolete and left later causing move confusion than good. but I do not recall reading any real convention on it. |
|
Code comments should clarify the "why" or summarize the "what" of the following code block, but not being too verbose stating the obvious, nor letting doubts about why things are done. In this case, a simple docstring of the method can be |
50d63b6 to
4fa0cf1
Compare
|
Thanks for the review. Force-pushed the refactor:
CI should re-run now. |
|
You can put the docstring I recommended. |
…mplates
The 18.0 loyalty mail_template_gift_card and mail_template_loyalty_card
both stored mail.template.lang as '{{ object._get_mail_partner().lang }}'.
The helper was removed in 19.0 and the 19.0 XML doesn't reset the lang
field, so on update load ORM template-syntax validation raises
AttributeError, aborting migration at
loyalty/data/mail_template_data.xml:3.
Reset the lang field to False on the two affected records in
post-migration. The 19.0 design (use_default_to=True) handles recipient
and language resolution at send time.
4fa0cf1 to
258b0a8
Compare
Add the merges introduced by today's PR series so the auto-built image includes them and the lab can `OPENUPGRADE_PULL_POLICY=always` again: - 19.0-fix-hr-null-write-date (OCA#5628) - 19.0-fix-loyalty-stale-mail-template-fields (OCA#5629) - 19.0-fix-hr-obsolete-fields-cleanup (OCA#5630) - 19.0-fix-partner-autocomplete-cleanup (OCA#5631) - 19.0-fix-l10n-fr-cleanup (OCA#5632) The companion lab repos.yaml is updated separately so local `make sync-repos` matches.
What
Add
openupgrade_scripts/scripts/loyalty/19.0.1.0/pre-migration.pyto clearmail.template.langon the two loyalty templates (mail_template_gift_card,mail_template_loyalty_card) when it still references the removedloyalty.card._get_mail_partner()helper.Why
In 18.0 those two templates stored
langas an inline template:```
mail_template.lang = '{{ object._get_mail_partner().lang }}'
```
The helper was removed from
loyalty.cardin 19.0. The 19.0mail_template_data.xmldoes not touch thelangfield — so onmode=updateload, ORM template-syntax validation evaluates the stalevalue against a
loyalty.cardwith no_get_mail_partnerand raises:```
AttributeError: 'loyalty.card' object has no attribute '_get_mail_partner'
```
This aborts the migration at
loyalty/data/mail_template_data.xml:3.How
Single SQL UPDATE that clears
langonly on the two affected templates(identified by XML ID via
ir_model_data) and only whenlangstillcontains
_get_mail_partner. That preserves any customer customisationthat may have replaced the stock value.
Two related 18.0 stale references are intentionally not handled in
pre-migration because the 19.0 XML already overwrites them on load:
mail.template.partner_to— reset via<field name=\"partner_to\" eval=\"False\"/>mail.template.body_html— fully rewritten in the 19.0 XMLThe 19.0 design replaces explicit per-template
lang/partner_towithuse_default_to=True, delegating recipient + language resolution to themodel at send time.
Test plan
loyalty,sale_loyalty,pos_loyaltyinstalled;
-u allmigration to 19.0 crashes as described withoutthis patch.
ir_module_moduleshows
loyalty | 19.0.1.0 | installed. Post-migration the twotemplates have
lang='',partner_to='',use_default_to=True— same state as a fresh 19.0 install.