Skip to content

Commit

Permalink
[IMP] loyalty_partner_applicability: Add post migration script
Browse files Browse the repository at this point in the history
Since the previous implementation  was not correct and defacto defined
the applicability of the rule at program level (If a rule was restricted
to a partner, all the rules of the program was available to the partner
even if the other rules where restricted to other partners), this change
add a migration script to aggreate the partner domain of the rules of the
program and set it at the program level. The new domain is the OR of the
domain of the rules of the program.
  • Loading branch information
lmignon committed Jan 27, 2025
1 parent 24f8fdf commit a73a208
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion loyalty_partner_applicability/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Loyalty Partner Applicability",
"summary": "Enables the definition of a customer filter for promotion rules that will "
"only be applied to customers who meet the specified conditions in the filter.",
"version": "16.0.2.0.2",
"version": "16.0.3.0.0",
"category": "Sale",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa,ACSONE SA/NV,Odoo Community Association (OCA)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import ast
import logging

from odoo import SUPERUSER_ID, api
from odoo.osv import expression

_logger = logging.getLogger(__name__)


def migrate(cr, version):
_logger.info(
"Migrating loyalty partners applicability domain from rules to programs"
)
env = api.Environment(cr, SUPERUSER_ID, {})
programs = env["loyalty.program"].search([])
for program in programs:
program_partner_domains = []
for rule in program.rule_ids:
domain = rule.partner_domain
py_domain = ast.literal_eval(domain)
if py_domain and py_domain not in program_partner_domains:
program_partner_domains.append(py_domain)
_logger.info(
f"Adding domain {py_domain} to program {program.name} "
"from rule {rule.display_name}"
)
rule.write({"partner_domain": "[]"})
if program_partner_domains:
program.write(
{"partner_domain": str(expression.OR(program_partner_domains))}
)
_logger.info(
f"Set domain {program.partner_domain} to program {program.name}"
)
2 changes: 1 addition & 1 deletion sale_loyalty_partner_applicability/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Sale Loyalty Partner Applicability",
"summary": "Enables the definition of a customer filter for promotion rules that will "
"only be applied to customers who meet the specified conditions in the filter.",
"version": "16.0.1.0.3",
"version": "16.0.2.0.0",
"category": "Sale",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa,ACSONE SA/NV,Odoo Community Association (OCA)",
Expand Down

0 comments on commit a73a208

Please sign in to comment.