Skip to content

Commit

Permalink
[12.0][FIX] migration e-invoice 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Oct 11, 2020
1 parent ff0aabb commit ccb0e4c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 38 deletions.
38 changes: 0 additions & 38 deletions l10n_it_fatturapa_in/migrations/12.0.1.19.0/post-migration.py

This file was deleted.

82 changes: 82 additions & 0 deletions l10n_it_fatturapa_in/migrations/12.0.2.0.0/post-migration.py
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 l10n_it_fatturapa_in/migrations/12.0.2.0.0/pre-migration.py
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),
],
})

0 comments on commit ccb0e4c

Please sign in to comment.