-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
[16.0][OU-ADD] loyalty #4187
Merged
Merged
[16.0][OU-ADD] loyalty #4187
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
openupgrade_scripts/scripts/loyalty/16.0.1.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# 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)"), | ||
} | ||
loyalty_programs = env["loyalty.program"].search([]) | ||
for program in loyalty_programs: | ||
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, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, these translation are never going to apply, as they are not included in the standard PO/POT files (the reference is by file name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/odoo/odoo/blob/16.0/addons/loyalty/i18n/es.po#L746
But they are in the standard translation files and that is how the loyalty programs are named:
https://github.com/odoo/odoo/blob/16.0/addons/loyalty/models/loyalty_program.py#L197
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But as said, translations work referring the file:
so this is not going to work.