Skip to content

Commit

Permalink
added migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
fredzamoabg committed Sep 22, 2021
1 parent 84f2c62 commit fec556f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
10 changes: 0 additions & 10 deletions l10n_it_intrastat_statement/migration/14.0.1.0.0/post-migration.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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),
),
)

0 comments on commit fec556f

Please sign in to comment.