Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][OU-ADD] intrastat_base: Migration scripts #277

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions intrastat_base/migrations/16.0.1.0.0/post-migration.py
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
""",
)
10 changes: 10 additions & 0 deletions intrastat_base/migrations/16.0.1.0.0/pre-migration.py
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)]}
)
Loading