@@ -302,6 +302,15 @@ def _get_partner_country(self, inv_line, notedict, eu_countries):
302302 notedict ["invoice" ][notedict ["inv_origin" ]].add (msg )
303303 return country
304304
305+ def _get_product_hs_code (self , inv_line , notedict ):
306+ hs_code = inv_line .product_id .get_hs_code_recursively ()
307+ if not hs_code :
308+ msg = _ ("Missing <em>H.S. Code</em>" )
309+ notedict ["product" ][inv_line .product_id .display_name ][msg ].add (
310+ notedict ["invline_origin" ]
311+ )
312+ return hs_code
313+
305314 def _get_intrastat_transaction (self , inv_line , notedict ):
306315 invoice = inv_line .move_id
307316 transaction = invoice .intrastat_transaction_id
@@ -657,9 +666,12 @@ def _gather_invoices(self, notedict):
657666 hs_code = inv_intrastat_line .hs_code_id
658667 elif inv_line .product_id and self ._is_product (inv_line ):
659668 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>" , {}):
669+ if (
670+ notedict ["invline_origin" ]
671+ in notedict ["product" ][inv_line .product_id .display_name ][
672+ "Missing <em>H.S. Code</em>"
673+ ]
674+ ):
663675 continue
664676 else :
665677 _logger .info (
@@ -709,7 +721,7 @@ def _gather_invoices(self, notedict):
709721 "invoice_line_id" : inv_line .id ,
710722 "src_dest_country_id" : partner_country .id ,
711723 "product_id" : inv_line .product_id .id ,
712- "hs_code_id" : hs_code .id ,
724+ "hs_code_id" : hs_code and hs_code .id or False ,
713725 "weight" : weight ,
714726 "suppl_unit_qty" : suppl_unit_qty ,
715727 "amount_company_currency" : amount_company_currency ,
@@ -1208,13 +1220,16 @@ def _prepare_declaration_line(self, line_number):
12081220 vals [field ] = int (round (vals [field ]))
12091221 # the intrastat specs say that, if the value is between 0 and 0.5,
12101222 # it should be rounded to 1
1223+
1224+ self ._get_declaration_weight_suppl_unit (vals )
1225+ vals ["amount_company_currency" ] = int (round (vals ["amount_company_currency" ]))
1226+ return vals
1227+
1228+ def _get_declaration_weight_suppl_unit (self , vals ):
12111229 if not vals ["weight" ]:
12121230 vals ["weight" ] = 1
12131231 if vals ["intrastat_unit_id" ] and not vals ["suppl_unit_qty" ]:
12141232 vals ["suppl_unit_qty" ] = 1
1215- vals ["amount_company_currency" ] = int (round (vals ["amount_company_currency" ]))
1216- vals ["line_number" ] = line_number
1217- return vals
12181233
12191234
12201235class IntrastatProductDeclarationLine (models .Model ):
0 commit comments