@@ -143,11 +143,22 @@ def _prepare_intrastat_line_province_origin(self, company_id, res):
143
143
144
144
def _prepare_intrastat_line_country_good_origin (self , res ):
145
145
self .ensure_one ()
146
- country_good_origin_id = self .env ["res.country" ].browse ()
147
- if self .move_id .is_sale_document ():
146
+ if self .mapped ("product_id.product_tmpl_id.intrastat_country_origin_id" ):
147
+ country_good_origin_id = (
148
+ self .product_id .product_tmpl_id .intrastat_country_origin_id
149
+ )
150
+ elif self .mapped (
151
+ "product_id.product_tmpl_id.categ_id.intrastat_country_origin_id"
152
+ ):
153
+ country_good_origin_id = (
154
+ self .product_id .product_tmpl_id .categ_id .intrastat_country_origin_id
155
+ )
156
+ elif self .move_id .is_sale_document ():
148
157
country_good_origin_id = self .move_id .company_id .partner_id .country_id
149
158
elif self .move_id .is_purchase_document ():
150
159
country_good_origin_id = self .move_id .partner_id .country_id
160
+ else :
161
+ country_good_origin_id = self .env ["res.country" ].browse ()
151
162
res .update ({"country_good_origin_id" : country_good_origin_id .id })
152
163
153
164
def _prepare_intrastat_line_country_origin (self , res ):
@@ -412,23 +423,23 @@ def _get_intrastat_lines_to_split(self):
412
423
intra_line = line ._prepare_intrastat_line ()
413
424
i_code_id = intra_line ["intrastat_code_id" ]
414
425
i_code_type = intra_line ["intrastat_code_type" ]
426
+ i_country_good_origin = intra_line ["country_good_origin_id" ]
415
427
416
- if i_code_id in i_line_by_code :
417
- i_line_by_code [i_code_id ]["amount_currency" ] += intra_line [
418
- "amount_currency"
419
- ]
420
- i_line_by_code [i_code_id ]["statistic_amount_euro" ] += intra_line [
428
+ key = ";" .join (filter (None , [str (i_code_id ), str (i_country_good_origin )]))
429
+ if key in i_line_by_code .keys ():
430
+ i_line_by_code [key ]["amount_currency" ] += intra_line ["amount_currency" ]
431
+ i_line_by_code [key ]["statistic_amount_euro" ] += intra_line [
421
432
"statistic_amount_euro"
422
433
]
423
- i_line_by_code [i_code_id ]["weight_kg" ] += intra_line ["weight_kg" ]
424
- i_line_by_code [i_code_id ]["additional_units" ] += intra_line [
434
+ i_line_by_code [key ]["weight_kg" ] += intra_line ["weight_kg" ]
435
+ i_line_by_code [key ]["additional_units" ] += intra_line [
425
436
"additional_units"
426
437
]
427
438
else :
428
439
intra_line ["statement_section" ] = self .env [
429
440
"account.invoice.intrastat"
430
441
].compute_statement_section (i_code_type , self .move_type )
431
- i_line_by_code [i_code_id ] = intra_line
442
+ i_line_by_code [key ] = intra_line
432
443
return i_line_by_code , lines_to_split
433
444
434
445
0 commit comments