forked from beescoop/Obeesdoo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrename_beesdoo.py
60 lines (51 loc) · 1.81 KB
/
rename_beesdoo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright 2022 Coop IT Easy SC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
"""This module was previously beesdoo_worker_status before it was moved to the OCA.
beesdoo_worker_status is presently an empty module that depends on this module. When
this module is installed, it should convert all data from the beesdoo_worker_status
module to be useable by this module.
"""
import logging
_logger = logging.getLogger(__name__)
XMLIDS_TO_RENAME = [
(
"beesdoo_worker_status.beesdoo_shift_task_template_1_demo",
"shift.shift_task_template_1_demo",
),
(
"beesdoo_worker_status.beesdoo_shift_task_template_2_demo",
"shift.shift_task_template_2_demo",
),
(
"beesdoo_worker_status.beesdoo_shift_task_template_3_demo",
"shift.shift_task_template_3_demo",
),
]
OLD_MODULE_NAME = "beesdoo_worker_status"
NEW_MODULE_NAME = "shift_worker_status"
def rename_beesdoo(cr):
cr.execute(
"SELECT id FROM ir_module_module "
"WHERE name=%s and state IN ('installed', 'to upgrade')",
(OLD_MODULE_NAME,),
)
if not cr.fetchone():
return
from openupgradelib import openupgrade
_logger.info("renaming xmlids")
openupgrade.rename_xmlids(cr, XMLIDS_TO_RENAME)
_logger.info(
"transferring ir_model_data from {} to {}".format(
OLD_MODULE_NAME, NEW_MODULE_NAME
)
)
# this query comes from openupgrade.update_module_names(), which cannot be
# used directly here because the module with the old name still exists.
openupgrade.logged_query(
cr,
"""
UPDATE ir_model_data SET module = %s
WHERE module = %s AND name NOT IN
(SELECT name FROM ir_model_data WHERE module = %s)""",
(NEW_MODULE_NAME, OLD_MODULE_NAME, NEW_MODULE_NAME),
)