Skip to content

Commit 7816697

Browse files
Borrusomonen17
authored andcommitted
[FIX] l10n_it_edi_extension: fix collision and table checks in migration
1 parent 24de1ba commit 7816697

File tree

1 file changed

+110
-110
lines changed

1 file changed

+110
-110
lines changed

l10n_it_edi_extension/__init__.py

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from odoo.tools import config
99

10-
from openupgradelib import openupgrade
10+
from openupgradelib import openupgrade, openupgrade_tools
1111

1212
from odoo.addons.base.models.ir_qweb_fields import Markup, nl2br, nl2br_enclose
1313

@@ -216,16 +216,6 @@ def _l10n_it_fatturapa_pre_migration(env):
216216
"l10n_it_edi_admin_ref",
217217
),
218218
],
219-
[
220-
(
221-
"account.move.line",
222-
"ftpa_line_number",
223-
),
224-
(
225-
"account.move.line",
226-
"sequence",
227-
),
228-
],
229219
[
230220
(
231221
"res.partner",
@@ -326,16 +316,6 @@ def _l10n_it_fatturapa_pre_migration(env):
326316
"l10n_edi_it_stable_organization",
327317
),
328318
],
329-
[
330-
(
331-
"res.company",
332-
"fatturapa_tax_representative",
333-
),
334-
(
335-
"res.company",
336-
"l10n_it_tax_representative_partner_id",
337-
),
338-
],
339319
]
340320
field_spec = []
341321
for renamed_field in RENAMED_FIELDS:
@@ -622,37 +602,53 @@ def _l10n_it_fatturapa_post_migration(env):
622602
"""
623603
openupgrade.logged_query(env.cr, query)
624604

625-
env.cr.execute("SELECT * FROM fatturapa_activity_progress LIMIT 1")
626-
if env.cr.fetchone():
627-
openupgrade.logged_query(
628-
env.cr,
629-
"""
630-
INSERT INTO
631-
l10n_it_edi_activity_progress (activity_progress, invoice_id)
632-
SELECT
633-
fatturapa_activity_progress, invoice_id
634-
FROM
635-
fatturapa_activity_progress
636-
""",
637-
)
605+
query = """
606+
UPDATE account_move_line
607+
SET sequence = ftpa_line_number
608+
"""
609+
openupgrade.logged_query(env.cr, query)
638610

639-
env.cr.execute("SELECT * FROM fatturapa_summary_data LIMIT 1")
640-
if env.cr.fetchone():
641-
openupgrade.logged_query(
642-
env.cr,
643-
"""
644-
INSERT INTO
645-
l10n_it_edi_summary_data (
611+
query = """
612+
UPDATE res_company
613+
SET l10n_it_tax_representative_partner_id = fatturapa_tax_representative
614+
"""
615+
openupgrade.logged_query(env.cr, query)
616+
617+
if openupgrade_tools.table_exists(env.cr, "fatturapa_activity_progress"):
618+
env.cr.execute("SELECT * FROM fatturapa_activity_progress LIMIT 1")
619+
if env.cr.fetchone():
620+
openupgrade.logged_query(
621+
env.cr,
622+
"""
623+
INSERT INTO
624+
l10n_it_edi_activity_progress (activity_progress, invoice_id)
625+
SELECT
626+
fatturapa_activity_progress, invoice_id
627+
FROM
628+
fatturapa_activity_progress
629+
""",
630+
)
631+
632+
if openupgrade_tools.table_exists(env.cr, "fatturapa_summary_data"):
633+
env.cr.execute("SELECT * FROM fatturapa_summary_data LIMIT 1")
634+
if env.cr.fetchone():
635+
openupgrade.logged_query(
636+
env.cr,
637+
"""
638+
INSERT INTO
639+
l10n_it_edi_summary_data (
640+
tax_rate, non_taxable_nature, incidental_charges, rounding,
641+
amount_untaxed, amount_tax, payability, law_reference,
642+
invoice_id
643+
)
644+
SELECT
646645
tax_rate, non_taxable_nature, incidental_charges, rounding,
647-
amount_untaxed, amount_tax, payability, law_reference, invoice_id
648-
)
649-
SELECT
650-
tax_rate, non_taxable_nature, incidental_charges, rounding,
651-
amount_untaxed, amount_tax, payability, law_reference, invoice_id
652-
FROM
653-
fatturapa_summary_data
654-
""",
655-
)
646+
amount_untaxed, amount_tax, payability, law_reference,
647+
invoice_id
648+
FROM
649+
fatturapa_summary_data
650+
""",
651+
)
656652

657653
_l10n_it_fatturapa_post_migration_related_ddt(env)
658654
_l10n_it_fatturapa_post_migration_delivery_data(env)
@@ -729,73 +725,77 @@ def _l10n_it_fatturapa_in_post_migration(env):
729725
"""
730726
openupgrade.logged_query(env.cr, query)
731727

732-
env.cr.execute("SELECT * FROM einvoice_line LIMIT 1")
733-
if env.cr.fetchone():
734-
openupgrade.logged_query(
735-
env.cr,
736-
"""
737-
INSERT INTO
738-
l10n_it_edi_line (
728+
if openupgrade_tools.table_exists(env.cr, "einvoice_line"):
729+
env.cr.execute("SELECT * FROM einvoice_line LIMIT 1")
730+
if env.cr.fetchone():
731+
openupgrade.logged_query(
732+
env.cr,
733+
"""
734+
INSERT INTO
735+
l10n_it_edi_line (
736+
id, invoice_id, line_number, service_type, name, qty, uom,
737+
period_start_date, period_end_date, unit_price,
738+
total_price, tax_amount, wt_amount, tax_kind
739+
)
740+
SELECT
739741
id, invoice_id, line_number, service_type, name, qty, uom,
740742
period_start_date, period_end_date, unit_price,
741743
total_price, tax_amount, wt_amount, tax_kind
742-
)
743-
SELECT
744-
id, invoice_id, line_number, service_type, name, qty, uom,
745-
period_start_date, period_end_date, unit_price,
746-
total_price, tax_amount, wt_amount, tax_kind
747-
FROM
748-
einvoice_line
749-
""",
750-
)
744+
FROM
745+
einvoice_line
746+
""",
747+
)
751748

752-
env.cr.execute("SELECT * FROM fatturapa_article_code LIMIT 1")
753-
if env.cr.fetchone():
754-
openupgrade.logged_query(
755-
env.cr,
756-
"""
757-
INSERT INTO
758-
l10n_it_edi_article_code (name, code_val, l10n_it_edi_line_id)
759-
SELECT
760-
name, code_val, e_invoice_line_id
761-
FROM
762-
fatturapa_article_code
763-
""",
764-
)
749+
if openupgrade_tools.table_exists(env.cr, "fatturapa_article_code"):
750+
env.cr.execute("SELECT * FROM fatturapa_article_code LIMIT 1")
751+
if env.cr.fetchone():
752+
openupgrade.logged_query(
753+
env.cr,
754+
"""
755+
INSERT INTO
756+
l10n_it_edi_article_code (name, code_val, l10n_it_edi_line_id)
757+
SELECT
758+
name, code_val, e_invoice_line_id
759+
FROM
760+
fatturapa_article_code
761+
""",
762+
)
765763

766-
env.cr.execute("SELECT * FROM discount_rise_price LIMIT 1")
767-
if env.cr.fetchone():
768-
openupgrade.logged_query(
769-
env.cr,
770-
"""
771-
INSERT INTO
772-
l10n_it_edi_discount_rise_price (
764+
if openupgrade_tools.table_exists(env.cr, "discount_rise_price"):
765+
env.cr.execute("SELECT * FROM discount_rise_price LIMIT 1")
766+
if env.cr.fetchone():
767+
openupgrade.logged_query(
768+
env.cr,
769+
"""
770+
INSERT INTO
771+
l10n_it_edi_discount_rise_price (
772+
name, percentage, amount, invoice_line_id, invoice_id,
773+
l10n_it_edi_line_id
774+
)
775+
SELECT
773776
name, percentage, amount, invoice_line_id, invoice_id,
774-
l10n_it_edi_line_id
775-
)
776-
SELECT
777-
name, percentage, amount, invoice_line_id, invoice_id,
778-
e_invoice_line_id
779-
FROM
780-
discount_rise_price
781-
""",
782-
)
777+
e_invoice_line_id
778+
FROM
779+
discount_rise_price
780+
""",
781+
)
783782

784-
env.cr.execute("SELECT * FROM einvoice_line_other_data LIMIT 1")
785-
if env.cr.fetchone():
786-
openupgrade.logged_query(
787-
env.cr,
788-
"""
789-
INSERT INTO
790-
l10n_it_edi_line_other_data (
791-
l10n_it_edi_line_id, name, text_ref, num_ref, date_ref
792-
)
793-
SELECT
794-
e_invoice_line_id, name, text_ref, num_ref, date_ref
795-
FROM
796-
einvoice_line_other_data
797-
""",
798-
)
783+
if openupgrade_tools.table_exists(env.cr, "einvoice_line_other_data"):
784+
env.cr.execute("SELECT * FROM einvoice_line_other_data LIMIT 1")
785+
if env.cr.fetchone():
786+
openupgrade.logged_query(
787+
env.cr,
788+
"""
789+
INSERT INTO
790+
l10n_it_edi_line_other_data (
791+
l10n_it_edi_line_id, name, text_ref, num_ref, date_ref
792+
)
793+
SELECT
794+
e_invoice_line_id, name, text_ref, num_ref, date_ref
795+
FROM
796+
einvoice_line_other_data
797+
""",
798+
)
799799

800800
env.cr.execute("""
801801
SELECT

0 commit comments

Comments
 (0)