@@ -576,6 +576,7 @@ def _is_product(self, invoice_line):
576576 def _gather_invoices_init (self , notedict ):
577577 """placeholder for localization modules"""
578578
579+ # flake8: noqa: C901
579580 def _gather_invoices (self , notedict ):
580581 lines = []
581582 qty_prec = self .env ["decimal.precision" ].precision_get (
@@ -637,6 +638,9 @@ def _gather_invoices(self, notedict):
637638 partner_country = self ._get_partner_country (
638639 inv_line , notedict , eu_countries
639640 )
641+ if notedict ["inv_origin" ] in notedict ["invoice" ]:
642+ continue
643+
640644 # When the country is the same as the company's country must be skipped.
641645 if partner_country == self .company_id .country_id :
642646 _logger .info (
@@ -652,12 +656,10 @@ def _gather_invoices(self, notedict):
652656 if inv_intrastat_line :
653657 hs_code = inv_intrastat_line .hs_code_id
654658 elif inv_line .product_id and self ._is_product (inv_line ):
655- hs_code = inv_line .product_id .get_hs_code_recursively ()
656- if not hs_code :
657- msg = _ ("Missing <em>H.S. Code</em>" )
658- notedict ["product" ][inv_line .product_id .display_name ][msg ].add (
659- notedict ["invline_origin" ]
660- )
659+ hs_code = self ._get_product_hs_code (inv_line , notedict )
660+ if notedict ["invline_origin" ] in notedict ["product" ].get (
661+ inv_line .product_id .display_name , {}
662+ ).get ("Missing <em>H.S. Code</em>" , {}):
661663 continue
662664 else :
663665 _logger .info (
@@ -712,8 +714,12 @@ def _gather_invoices(self, notedict):
712714 "suppl_unit_qty" : suppl_unit_qty ,
713715 "amount_company_currency" : amount_company_currency ,
714716 "amount_accessory_cost_company_currency" : 0.0 ,
715- "transaction_id" : intrastat_transaction .id ,
716- "product_origin_country_id" : product_origin_country .id or False ,
717+ "transaction_id" : intrastat_transaction
718+ and intrastat_transaction .id
719+ or False ,
720+ "product_origin_country_id" : product_origin_country
721+ and product_origin_country .id
722+ or False ,
717723 "region_code" : region_code or region .code ,
718724 "region_id" : region and region .id or False ,
719725 "partner_id" : partner .id ,
0 commit comments