@@ -707,21 +707,34 @@ def _l10n_it_fatturapa_in_post_migration(env):
707707 openupgrade .logged_query (env .cr , query )
708708
709709 if openupgrade_tools .table_exists (env .cr , "einvoice_line" ):
710+ l10n_it_edi_line_id_legacy = openupgrade .get_legacy_name ("l10n_it_edi_line_id" )
711+ openupgrade .add_columns (
712+ env ,
713+ [
714+ (
715+ "l10n_it_edi_line" ,
716+ l10n_it_edi_line_id_legacy ,
717+ "integer" ,
718+ ),
719+ ],
720+ )
710721 env .cr .execute ("SELECT * FROM einvoice_line LIMIT 1" )
711722 if env .cr .fetchone ():
712723 openupgrade .logged_query (
713724 env .cr ,
714- """
725+ f """
715726 INSERT INTO
716727 l10n_it_edi_line (
717728 invoice_id, line_number, service_type, name, qty, uom,
718729 period_start_date, period_end_date, unit_price,
719- total_price, tax_amount, wt_amount, tax_kind
730+ total_price, tax_amount, wt_amount, tax_kind,
731+ { l10n_it_edi_line_id_legacy }
720732 )
721733 SELECT
722734 invoice_id, line_number, service_type, name, qty, uom,
723735 period_start_date, period_end_date, unit_price,
724- total_price, tax_amount, wt_amount, tax_kind
736+ total_price, tax_amount, wt_amount, tax_kind,
737+ id
725738 FROM
726739 einvoice_line
727740 """ ,
@@ -732,13 +745,16 @@ def _l10n_it_fatturapa_in_post_migration(env):
732745 if env .cr .fetchone ():
733746 openupgrade .logged_query (
734747 env .cr ,
735- """
748+ f """
736749 INSERT INTO
737750 l10n_it_edi_article_code (name, code_val, l10n_it_edi_line_id)
738751 SELECT
739- name, code_val, e_invoice_line_id
752+ fac. name, fac. code_val, edi_line.id
740753 FROM
741- fatturapa_article_code
754+ fatturapa_article_code AS fac
755+ LEFT JOIN
756+ l10n_it_edi_line AS edi_line
757+ ON fac.e_invoice_line_id = edi_line.{ l10n_it_edi_line_id_legacy }
742758 """ ,
743759 )
744760
@@ -747,17 +763,20 @@ def _l10n_it_fatturapa_in_post_migration(env):
747763 if env .cr .fetchone ():
748764 openupgrade .logged_query (
749765 env .cr ,
750- """
766+ f """
751767 INSERT INTO
752768 l10n_it_edi_discount_rise_price (
753769 name, percentage, amount, invoice_line_id, invoice_id,
754770 l10n_it_edi_line_id
755771 )
756772 SELECT
757- name, percentage, amount, invoice_line_id, invoice_id ,
758- e_invoice_line_id
773+ drp. name, drp. percentage, drp. amount, drp. invoice_line_id,
774+ drp.invoice_id, edi_line.id
759775 FROM
760- discount_rise_price
776+ discount_rise_price AS drp
777+ LEFT JOIN
778+ l10n_it_edi_line AS edi_line
779+ ON drp.e_invoice_line_id = edi_line.{ l10n_it_edi_line_id_legacy }
761780 """ ,
762781 )
763782
@@ -766,15 +785,19 @@ def _l10n_it_fatturapa_in_post_migration(env):
766785 if env .cr .fetchone ():
767786 openupgrade .logged_query (
768787 env .cr ,
769- """
788+ f """
770789 INSERT INTO
771790 l10n_it_edi_line_other_data (
772791 l10n_it_edi_line_id, name, text_ref, num_ref, date_ref
773792 )
774793 SELECT
775- e_invoice_line_id, name, text_ref, num_ref, date_ref::date
794+ edi_line.id, elod.name, elod.text_ref, elod.num_ref,
795+ elod.date_ref::date
776796 FROM
777- einvoice_line_other_data
797+ einvoice_line_other_data AS elod
798+ LEFT JOIN
799+ l10n_it_edi_line AS edi_line
800+ ON elod.e_invoice_line_id = edi_line.{ l10n_it_edi_line_id_legacy }
778801 """ ,
779802 )
780803
0 commit comments