From fec556fab13b55f218ff9dd0e42f93cbc06a6d84 Mon Sep 17 00:00:00 2001 From: Alfredo Zamora Date: Wed, 22 Sep 2021 14:01:42 +0200 Subject: [PATCH] added migration script --- .../migration/14.0.1.0.0/post-migration.py | 10 ------ .../13.0.1.0.0}/noupdate_changes.xml | 0 .../migrations/13.0.1.0.0/post-migration.py | 34 +++++++++++++++++++ 3 files changed, 34 insertions(+), 10 deletions(-) delete mode 100644 l10n_it_intrastat_statement/migration/14.0.1.0.0/post-migration.py rename l10n_it_intrastat_statement/{migration/14.0.1.0.0 => migrations/13.0.1.0.0}/noupdate_changes.xml (100%) create mode 100644 l10n_it_intrastat_statement/migrations/13.0.1.0.0/post-migration.py diff --git a/l10n_it_intrastat_statement/migration/14.0.1.0.0/post-migration.py b/l10n_it_intrastat_statement/migration/14.0.1.0.0/post-migration.py deleted file mode 100644 index 5197dfc6f81a..000000000000 --- a/l10n_it_intrastat_statement/migration/14.0.1.0.0/post-migration.py +++ /dev/null @@ -1,10 +0,0 @@ -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.load_data( - env.cr, - "l10n_it_intrastat_statement", - "migrations/14.0.1.0.0/noupdate_changes.xml", - ) diff --git a/l10n_it_intrastat_statement/migration/14.0.1.0.0/noupdate_changes.xml b/l10n_it_intrastat_statement/migrations/13.0.1.0.0/noupdate_changes.xml similarity index 100% rename from l10n_it_intrastat_statement/migration/14.0.1.0.0/noupdate_changes.xml rename to l10n_it_intrastat_statement/migrations/13.0.1.0.0/noupdate_changes.xml diff --git a/l10n_it_intrastat_statement/migrations/13.0.1.0.0/post-migration.py b/l10n_it_intrastat_statement/migrations/13.0.1.0.0/post-migration.py new file mode 100644 index 000000000000..a77f64ca6e72 --- /dev/null +++ b/l10n_it_intrastat_statement/migrations/13.0.1.0.0/post-migration.py @@ -0,0 +1,34 @@ +from openupgradelib import openupgrade +from psycopg2 import sql + + +def migrate(cr, installed_version): + openupgrade.load_data( + cr, "l10n_it_intrastat_statement", "migrations/13.0.1.0.0/noupdate_changes.xml" + ) + + to_be_updated = ( + ("account_intrastat_statement_sale_section1", "invoice_id"), + ("account_intrastat_statement_sale_section2", "invoice_id"), + ("account_intrastat_statement_sale_section3", "invoice_id"), + ("account_intrastat_statement_sale_section4", "invoice_id"), + ("account_intrastat_statement_purchase_section1", "invoice_id"), + ("account_intrastat_statement_purchase_section2", "invoice_id"), + ("account_intrastat_statement_purchase_section3", "invoice_id"), + ("account_intrastat_statement_purchase_section4", "invoice_id"), + ) + + if openupgrade.table_exists(cr, "account_invoice"): + for table, column in to_be_updated: + openupgrade.logged_query( + cr, + sql.SQL( + """UPDATE {table} t + SET {column} = ai.move_id + FROM account_invoice ai + WHERE t.{column} = ai.id and ai.move_id is NOT NULL""" + ).format( + table=sql.Identifier(table), + column=sql.Identifier(column), + ), + )