forked from tvtma/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [OA-ADD] loyalty: migration * [FIX] loyalty: fix migration * [FIX] loyalty: pre migration - fix SQL syntax * [FIX] loyalty: re-fill data for program_type column * [IMP] loyalty: format SQL query * [IMP] loyalty: fill program_id column of table loyalty_rule - fill reward_point_mode column to default value - use reward_point_mode value insert loyalty_rule rows * [FIX] loyalty: pre-commit syntax * [FIX] loyalty: fix pre-migration script * [FIX] loyalty: fill data before create SQL constraint * add migration script * correct seq * fix --------- Co-authored-by: nguyenvietlam0640 <[email protected]> Co-authored-by: Roy Le <[email protected]>
- Loading branch information
1 parent
d292641
commit f1781f9
Showing
4 changed files
with
830 additions
and
3 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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
def _move_gift_cart_to_loyalty_card(env): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
ALTER TABLE loyalty_card | ||
ADD COLUMN IF NOT EXISTS old_gift_card_id INTEGER | ||
""", | ||
) | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
WITH inserted_loyalty_program AS ( | ||
INSERT INTO loyalty_program ( | ||
company_id, | ||
currency_id, | ||
name, | ||
active, | ||
program_type, | ||
applies_on, | ||
trigger, | ||
portal_visible | ||
) | ||
SELECT | ||
DISTINCT(card.company_id), | ||
company.currency_id, | ||
jsonb_object_agg('en_US', 'Gift Cards'), | ||
true, | ||
'gift_card', | ||
'future', | ||
'auto', | ||
true | ||
FROM gift_card card | ||
JOIN res_company company ON company.id = card.company_id | ||
GROUP BY card.company_id, company.currency_id | ||
RETURNING id, company_id | ||
) | ||
INSERT INTO loyalty_card ( | ||
old_gift_card_id, | ||
program_id, | ||
company_id, | ||
partner_id, | ||
code, | ||
expiration_date, | ||
points, | ||
create_uid, | ||
create_date, | ||
write_uid, | ||
write_date | ||
) | ||
SELECT | ||
card.id, | ||
program.id, | ||
card.company_id, | ||
card.partner_id, | ||
card.code, | ||
card.expired_date, | ||
card.initial_amount, | ||
card.create_uid, | ||
card.create_date, | ||
card.write_uid, | ||
card.write_date | ||
FROM gift_card card | ||
JOIN inserted_loyalty_program program ON program.company_id = card.company_id | ||
""", | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
_move_gift_cart_to_loyalty_card(env) |
Oops, something went wrong.