-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] loyalty_partner_applicability: Add post migration script
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
Showing
3 changed files
with
36 additions
and
2 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
loyalty_partner_applicability/migrations/16.0.3.0.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,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}" | ||
) |
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