Debian Codegraph @

addons/l10n_de/migrations/2.0/pre-migrate.py

raw
1 # -*- coding: utf-8 -*-
2
3
4 def rename_tag(cr, old_tag, new_tag):
5 cr.execute(
6 """UPDATE ir_model_data
7 SET name=%s
8 WHERE module='l10n_de' AND name=%s
9 """,
10 (new_tag, old_tag),
11 )
12
13
14 def migrate(cr, version):
15 # By deleting tag B from ir_model_data we ensure that the ORM won't try to remove this record.
16 # This is done because the tag might be already used as a FK somewhere else.
17 cr.execute(
18 """DELETE FROM ir_model_data
19 WHERE module='l10n_de'
20 AND name='tag_de_liabilities_bs_B'
21 """
22 )
23
24 # As some people already upgraded, they will have renamed the C_1 tag to B_1. This doesn't come from the script but from the
25 # account_account_tags_data.xml. If they try to run this script now in the fix they get the error that B_1 already exists.
26 # To fix this we can check if it exists or not, and if it does then we don't run the script. This means that the ones
27 # that upgraded won't have the old tags data transferred to the new tags but they will still be able to have the updated sheet.
28 cr.execute(
29 """SELECT 1 FROM ir_model_data
30 WHERE module='l10n_de' AND name='tag_de_liabilities_bs_B_1'
31 """)
32 if cr.rowcount:
33 # If the script didn't run, we should remove the tags that have been replaced from ir_model_data too so they're
34 # not deleted by the ORM if they were already used.
35 cr.execute(
36 """DELETE FROM ir_model_data
37 WHERE module='l10n_de'
38 AND name IN ('tag_de_liabilities_bs_F', 'tag_de_liabilities_bs_D_1', 'tag_de_liabilities_bs_D_2',
39 'tag_de_liabilities_bs_D_3', 'tag_de_liabilities_bs_D_4', 'tag_de_liabilities_bs_D_5',
40 'tag_de_liabilities_bs_D_6', 'tag_de_liabilities_bs_D_7', 'tag_de_liabilities_bs_D_8')
41 """
42 )
43 return
44
45 rename_tag(cr, "tag_de_liabilities_bs_C_1", "tag_de_liabilities_bs_B_1")
46 rename_tag(cr, "tag_de_liabilities_bs_C_2", "tag_de_liabilities_bs_B_2")
47 rename_tag(cr, "tag_de_liabilities_bs_C_3", "tag_de_liabilities_bs_B_3")
48 rename_tag(cr, "tag_de_liabilities_bs_D_1", "tag_de_liabilities_bs_C_1")
49 rename_tag(cr, "tag_de_liabilities_bs_D_2", "tag_de_liabilities_bs_C_2")
50 rename_tag(cr, "tag_de_liabilities_bs_D_3", "tag_de_liabilities_bs_C_3")
51 rename_tag(cr, "tag_de_liabilities_bs_D_4", "tag_de_liabilities_bs_C_4")
52 rename_tag(cr, "tag_de_liabilities_bs_D_5", "tag_de_liabilities_bs_C_5")
53 rename_tag(cr, "tag_de_liabilities_bs_D_6", "tag_de_liabilities_bs_C_6")
54 rename_tag(cr, "tag_de_liabilities_bs_D_7", "tag_de_liabilities_bs_C_7")
55 rename_tag(cr, "tag_de_liabilities_bs_D_8", "tag_de_liabilities_bs_C_8")
56 rename_tag(cr, "tag_de_liabilities_bs_E", "tag_de_liabilities_bs_D")
57 rename_tag(cr, "tag_de_liabilities_bs_F", "tag_de_liabilities_bs_E")