Vincent Van Rossem
5 years ago
committed by
Rémy Taymans
2 changed files with 114 additions and 4 deletions
-
42easy_my_coop/migrations/12.0.3.0.1/post-migration.py
-
76easy_my_coop/migrations/12.0.3.0.1/pre-migration.py
@ -0,0 +1,42 @@ |
|||||
|
from openupgradelib import openupgrade |
||||
|
|
||||
|
|
||||
|
def update_records_module_category_cooperator_management(env): |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
UPDATE |
||||
|
res_groups_users_rel_module_category_cooperator_management |
||||
|
SET gid = ( |
||||
|
SELECT id |
||||
|
FROM res_groups |
||||
|
WHERE name = 'User' |
||||
|
AND category_id = ( |
||||
|
SELECT id |
||||
|
FROM ir_module_category |
||||
|
WHERE name = 'Cooperative Management' |
||||
|
) |
||||
|
);""", |
||||
|
) |
||||
|
|
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
INSERT INTO res_groups_users_rel (gid, uid) |
||||
|
SELECT gid, uid FROM res_groups_users_rel_module_category_cooperator_management |
||||
|
ON CONFLICT DO NOTHING;""", |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def drop_records_module_category_cooperator_management(env): |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
DROP TABLE res_groups_users_rel_module_category_cooperator_management;""", |
||||
|
) |
||||
|
|
||||
|
|
||||
|
@openupgrade.migrate() |
||||
|
def migrate(env, version): |
||||
|
update_records_module_category_cooperator_management(env) |
||||
|
drop_records_module_category_cooperator_management(env) |
@ -1,14 +1,82 @@ |
|||||
from openupgradelib import openupgrade |
from openupgradelib import openupgrade |
||||
|
|
||||
xmlid_renames = [ |
xmlid_renames = [ |
||||
('easy_my_coop.group_energiris_user', |
|
||||
'easy_my_coop.group_easy_my_coop_user'), |
|
||||
('easy_my_coop.group_energiris_manager', |
|
||||
'easy_my_coop.group_easy_my_coop_manager'), |
|
||||
|
( |
||||
|
"easy_my_coop.group_energiris_user", |
||||
|
"easy_my_coop.group_easy_my_coop_user", |
||||
|
), |
||||
|
( |
||||
|
"easy_my_coop.group_energiris_manager", |
||||
|
"easy_my_coop.group_easy_my_coop_manager", |
||||
|
), |
||||
] |
] |
||||
|
|
||||
|
|
||||
|
def copy_records_module_category_cooperator_management(env): |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
CREATE TABLE res_groups_users_rel_module_category_cooperator_management AS |
||||
|
SELECT gid, uid |
||||
|
FROM res_groups_users_rel |
||||
|
WHERE gid = ( |
||||
|
SELECT id |
||||
|
FROM res_groups |
||||
|
WHERE name = 'User' |
||||
|
AND category_id = ( |
||||
|
SELECT id |
||||
|
FROM ir_module_category |
||||
|
WHERE name = 'EasyMy Coop' |
||||
|
) |
||||
|
) |
||||
|
ORDER BY gid,uid;""", |
||||
|
) |
||||
|
|
||||
|
|
||||
|
def delete_records_module_category_cooperator_management(env): |
||||
|
""""Since XML-ID module_category_cooperator_management is now flagged as noupdate="1", |
||||
|
we need to manually delete it as well as other records that are linked to it |
||||
|
""" |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
DELETE |
||||
|
FROM res_groups_users_rel |
||||
|
WHERE gid = ( |
||||
|
SELECT id |
||||
|
FROM res_groups |
||||
|
WHERE name = 'User' |
||||
|
AND category_id = ( |
||||
|
SELECT id |
||||
|
FROM ir_module_category |
||||
|
WHERE name = 'EasyMy Coop' |
||||
|
) |
||||
|
);""", |
||||
|
) |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
DELETE |
||||
|
FROM res_groups |
||||
|
WHERE name = 'User' |
||||
|
AND category_id = ( |
||||
|
SELECT id |
||||
|
FROM ir_module_category |
||||
|
WHERE name = 'EasyMy Coop' |
||||
|
);""", |
||||
|
) |
||||
|
openupgrade.logged_query( |
||||
|
env.cr, |
||||
|
""" |
||||
|
DELETE |
||||
|
FROM ir_module_category |
||||
|
WHERE name = 'EasyMy Coop';""", |
||||
|
) |
||||
|
|
||||
|
|
||||
@openupgrade.migrate() |
@openupgrade.migrate() |
||||
def migrate(env, version): |
def migrate(env, version): |
||||
cr = env.cr |
cr = env.cr |
||||
openupgrade.rename_xmlids(cr, xmlid_renames) |
openupgrade.rename_xmlids(cr, xmlid_renames) |
||||
|
copy_records_module_category_cooperator_management(env) |
||||
|
delete_records_module_category_cooperator_management(env) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue