Skip to content

Commit

Permalink
[OU-ADD] loyalty
Browse files Browse the repository at this point in the history
TT44332
  • Loading branch information
pilarvargas-tecnativa committed Nov 8, 2023
1 parent 0c2b804 commit 824798f
Show file tree
Hide file tree
Showing 3 changed files with 1,056 additions and 0 deletions.
62 changes: 62 additions & 0 deletions openupgrade_scripts/scripts/loyalty/16.0.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

from odoo.tools.translate import _

_deleted_xml_records = [
"loyalty.sale_coupon_generate_rule",
]


def convert_loyalty_program_rewards(env):
openupgrade.m2o_to_x2m(
env.cr, env["loyalty.program"], "loyalty_program", "reward_ids", "reward_id"
)


def convert_loyalty_program_rules(env):
openupgrade.m2o_to_x2m(
env.cr, env["loyalty.program"], "loyalty_program", "rule_ids", "rule_id"
)


def compute_portal_point_name(env):
"""This is a computed field, but the _program_type_default_values method of the
loyalty module sets the following values in portal_point_name depending on the
program_type field. This is done in post so that the language context can be used."""
portal_point_names = {
"coupons": _("Coupon point(s)"),
"promotion": _("Promo point(s)"),
"gift_card": _("Gift Card"),
"loyalty": _("Loyalty point(s)"),
"ewallet": _("eWallet"),
"promo_code": _("Discount point(s)"),
"buy_x_get_y": _("Credit(s)"),
"next_order_coupons": _("Coupon point(s)"),
}
openupgrade.logged_query(
env.cr,
""" SELECT id FROM loyalty_program """,
)
loyalty_program_ids = env.cr.fetchall()
for program_id in loyalty_program_ids:
program = env["loyalty.program"].browse(program_id)
if program.program_type in portal_point_names:
translated_name = portal_point_names[program.program_type]
# By default when the module is installed it contains the terms in the
# language code "en_US".
program.with_context(lang="en_US").write(
{"portal_point_name": translated_name}
)


@openupgrade.migrate()
def migrate(env, version):
convert_loyalty_program_rewards(env)
convert_loyalty_program_rules(env)
compute_portal_point_name(env)
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
)
Loading

0 comments on commit 824798f

Please sign in to comment.