-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from Tecnativa/16.0-ou_add-intrastat_base
[16.0][OU-ADD] intrastat_base: Migration scripts
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2024 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Set proper values for new selection field | ||
old_column = openupgrade.get_legacy_name("intrastat") | ||
openupgrade.logged_query( | ||
env.cr, | ||
f""" | ||
UPDATE account_fiscal_position | ||
SET intrastat = CASE | ||
WHEN NOT {old_column} THEN 'no' | ||
ELSE 'b2b' END | ||
""", | ||
) | ||
# Propagate proper values to the related field | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE account_move am | ||
SET intrastat_fiscal_position = afp.intrastat | ||
FROM account_fiscal_position afp | ||
WHERE afp.id = am.fiscal_position_id | ||
""", | ||
) |
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,10 @@ | ||
# Copyright 2024 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_columns( | ||
env.cr, {"account_fiscal_position": [("intrastat", None)]} | ||
) |