Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| link_tracker |Nothing to do |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| loyalty | | |
| loyalty |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| lunch | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
37 changes: 37 additions & 0 deletions openupgrade_scripts/scripts/loyalty/19.0.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
"""Rewrite the removed ``_get_mail_partner`` helper (which returned
``partner_id``, the recipient) to its exact 18.0 equivalent in stored
template fields, as the 19.0 data-load render aborts before the existing
post-migration could clear the field. ``_get_mail_author`` would swap in
the company/internal user instead — wrong partner for custom templates
that are never reset by the module update.
"""
for column in ("lang", "partner_to", "email_to", "body_html"):
if not openupgrade.column_exists(env.cr, "mail_template", column):
continue
env.cr.execute(
"""
SELECT data_type FROM information_schema.columns
WHERE table_name = 'mail_template' AND column_name = %s
""",
(column,),
)
# translated columns (body_html) are jsonb; cast the rewrite back
cast = "::jsonb" if env.cr.fetchone()[0] == "jsonb" else ""
openupgrade.logged_query(
env.cr,
f"""
UPDATE mail_template
SET {column} = REPLACE(
{column}::text,
'object._get_mail_partner()',
'object.partner_id'
){cast}
WHERE model = 'loyalty.card'
AND {column}::text LIKE '%%_get_mail_partner%%'
""",
)
Loading