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.
- Loading branch information
1 parent
ff0aabb
commit ccb0e4c
Showing
3 changed files
with
100 additions
and
38 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
l10n_it_fatturapa_in/migrations/12.0.1.19.0/post-migration.py
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
l10n_it_fatturapa_in/migrations/12.0.2.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2020 Sergio Corato <https://github.com/sergiocorato> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
from psycopg2 import sql | ||
|
||
|
||
def create_withholding_data_lines(env): | ||
# create ftpa_withholding_ids from ftpa_withholding_type and ftpa_withholding_amount | ||
column_name = openupgrade.get_legacy_name('ftpa_withholding_amount') | ||
if openupgrade.column_exists(env.cr, 'account_invoice', column_name): | ||
openupgrade.logged_query( | ||
env.cr, sql.SQL( | ||
""" | ||
INSERT INTO withholding_data_line | ||
( | ||
name, | ||
amount, | ||
invoice_id, | ||
create_uid, | ||
create_date, | ||
write_date, | ||
write_uid | ||
) | ||
SELECT | ||
ai.{ftpa_withholding_type}, | ||
ai.{ftpa_withholding_amount}, | ||
ai.id, | ||
ai.create_uid, | ||
ai.create_date, | ||
ai.write_date, | ||
ai.write_uid | ||
FROM account_invoice ai | ||
WHERE ai.{ftpa_withholding_type} IS NOT NULL; | ||
""" | ||
).format( | ||
ftpa_withholding_type=sql.Identifier( | ||
openupgrade.get_legacy_name( | ||
'ftpa_withholding_type') | ||
), | ||
ftpa_withholding_amount=sql.Identifier( | ||
openupgrade.get_legacy_name( | ||
'ftpa_withholding_amount') | ||
), | ||
) | ||
) | ||
else: | ||
openupgrade.logged_query( | ||
env.cr, sql.SQL( | ||
""" | ||
INSERT INTO withholding_data_line | ||
( | ||
name, | ||
invoice_id, | ||
create_uid, | ||
create_date, | ||
write_date, | ||
write_uid | ||
) | ||
SELECT | ||
ai.{ftpa_withholding_type}, | ||
ai.id, | ||
ai.create_uid, | ||
ai.create_date, | ||
ai.write_date, | ||
ai.write_uid | ||
FROM account_invoice ai | ||
WHERE ai.{ftpa_withholding_type} IS NOT NULL; | ||
""" | ||
).format( | ||
ftpa_withholding_type=sql.Identifier( | ||
openupgrade.get_legacy_name( | ||
'ftpa_withholding_type') | ||
), | ||
) | ||
) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
if not version: | ||
return | ||
create_withholding_data_lines(env) |
18 changes: 18 additions & 0 deletions
18
l10n_it_fatturapa_in/migrations/12.0.2.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,18 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
cr = env.cr | ||
if openupgrade.column_exists(env.cr, 'account_invoice', 'ftpa_withholding_amount'): | ||
openupgrade.copy_columns(cr, { | ||
'account_invoice': [ | ||
('ftpa_withholding_amount', None, None), | ||
], | ||
}) | ||
openupgrade.copy_columns(cr, { | ||
'account_invoice': [ | ||
('ftpa_withholding_type', None, None), | ||
], | ||
}) |