forked from OCA/l10n-italy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sergiocorato
- Loading branch information
Showing
2 changed files
with
48 additions
and
27 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
l10n_it_intrastat_statement/migrations/13.0.1.0.0/post-migration.py
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 |
---|---|---|
@@ -1,34 +1,7 @@ | ||
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), | ||
), | ||
) |
48 changes: 48 additions & 0 deletions
48
l10n_it_intrastat_statement/migrations/13.0.1.0.0/pre-migration.py
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,48 @@ | ||
from openupgradelib import openupgrade | ||
from psycopg2 import sql | ||
|
||
|
||
def migrate(cr, installed_version): | ||
drop_sql = sql.SQL("ALTER TABLE {} DROP CONSTRAINT {}") | ||
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: | ||
cr.execute( | ||
""" | ||
SELECT constraint_name | ||
FROM information_schema.table_constraints | ||
WHERE constraint_type = 'FOREIGN KEY' AND table_name = %s | ||
AND constraint_name like %s | ||
""", | ||
(table, "%%%s%%" % "invoice_id"), | ||
) | ||
for constraint in (row[0] for row in cr.fetchall()): | ||
openupgrade.logged_query( | ||
cr, | ||
drop_sql.format( | ||
sql.Identifier(table), | ||
sql.Identifier(constraint), | ||
), | ||
) | ||
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), | ||
), | ||
) |