Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][FIX] migration e-invoice 1.6 #1914

Merged
merged 3 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions l10n_it_fatturapa_in/migrations/12.0.1.19.0/post-migration.py

This file was deleted.

45 changes: 45 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,45 @@
# Copyright 2020 Sergio Corato <https://github.com/sergiocorato>
# Copyright 2020 Alex Comba - Agile Business Group
# 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_wht_amount = openupgrade.get_legacy_name('ftpa_withholding_amount')
column_wht_type = openupgrade.get_legacy_name('ftpa_withholding_type')
exists = openupgrade.column_exists(env.cr, 'account_invoice', column_wht_amount)
mapping = {
'name': 'ai.{ftpa_withholding_type}'.format(
ftpa_withholding_type=column_wht_type),
'invoice_id': 'ai.id',
'create_uid': 'ai.create_uid',
'create_date': 'ai.create_date',
'write_date': 'ai.write_date',
'write_uid': 'ai.write_uid',
}
if exists:
mapping.update(
{'amount': 'ai.{ftpa_withholding_amount}'.format(
ftpa_withholding_amount=column_wht_amount)})
query = """
INSERT INTO withholding_data_line
({columns})
SELECT {values}
FROM account_invoice AS ai
WHERE ai.{ftpa_withholding_type} IS NOT NULL;""".format(
columns=','.join(mapping.keys()),
values=','.join(mapping.values()),
ftpa_withholding_type=column_wht_type)
openupgrade.logged_query(env.cr, sql.SQL(query))


@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),
],
})