@@ -82,7 +82,7 @@ def _prepare_intrastat_line(self):
82
82
83
83
def _prepare_intrastat_line_country_payment (self , res ):
84
84
self .ensure_one ()
85
- country_payment_id = self .env ["res.country" ]. browse ()
85
+ country_payment_id = self .env ["res.country" ]
86
86
if self .move_id .is_sale_document ():
87
87
country_payment_id = self .move_id .company_id .partner_id .country_id
88
88
if self .move_id .partner_bank_id :
@@ -105,7 +105,7 @@ def _prepare_intrastat_line_payment(self, res):
105
105
106
106
def _prepare_intrastat_line_province_dest (self , company_id , res ):
107
107
self .ensure_one ()
108
- province_destination_id = self .env ["res.country.state" ]. browse ()
108
+ province_destination_id = self .env ["res.country.state" ]
109
109
if self .move_id .is_sale_document ():
110
110
province_destination_id = self .move_id .partner_id .state_id
111
111
elif self .move_id .is_purchase_document ():
@@ -117,7 +117,7 @@ def _prepare_intrastat_line_province_dest(self, company_id, res):
117
117
118
118
def _prepare_intrastat_line_country_dest (self , res ):
119
119
self .ensure_one ()
120
- country_destination_id = self .env ["res.country" ]. browse ()
120
+ country_destination_id = self .env ["res.country" ]
121
121
if self .move_id .is_sale_document ():
122
122
country_destination_id = self .move_id .partner_id .country_id
123
123
elif self .move_id .is_purchase_document ():
@@ -126,7 +126,7 @@ def _prepare_intrastat_line_country_dest(self, res):
126
126
127
127
def _prepare_intrastat_line_province_origin (self , company_id , res ):
128
128
self .ensure_one ()
129
- province_origin_id = self .env ["res.country.state" ]. browse ()
129
+ province_origin_id = self .env ["res.country.state" ]
130
130
if self .move_id .is_sale_document ():
131
131
province_origin_id = (
132
132
company_id .intrastat_sale_province_origin_id
@@ -143,16 +143,27 @@ 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" ]
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 ):
154
165
self .ensure_one ()
155
- country_origin_id = self .env ["res.country" ]. browse ()
166
+ country_origin_id = self .env ["res.country" ]
156
167
if self .move_id .is_sale_document ():
157
168
country_origin_id = self .move_id .company_id .partner_id .country_id
158
169
elif self .move_id .is_purchase_document ():
@@ -228,10 +239,9 @@ def _prepare_intrastat_line_weight(self, product_template, res):
228
239
def _prepare_intrastat_line_code (self , product_template , res ):
229
240
self .ensure_one ()
230
241
intrastat_data = product_template .get_intrastat_data ()
231
- intrastat_code_model = self .env ["report.intrastat.code" ]
232
- intrastat_code = intrastat_code_model .browse ()
242
+ intrastat_code = self .env ["report.intrastat.code" ]
233
243
if intrastat_data ["intrastat_code_id" ]:
234
- intrastat_code = intrastat_code_model .browse (
244
+ intrastat_code = self . env [ "report.intrastat.code" ] .browse (
235
245
intrastat_data ["intrastat_code_id" ]
236
246
)
237
247
res .update ({"intrastat_code_id" : intrastat_data ["intrastat_code_id" ]})
@@ -412,23 +422,23 @@ def _get_intrastat_lines_to_split(self):
412
422
intra_line = line ._prepare_intrastat_line ()
413
423
i_code_id = intra_line ["intrastat_code_id" ]
414
424
i_code_type = intra_line ["intrastat_code_type" ]
425
+ i_country_good_origin = intra_line ["country_good_origin_id" ]
415
426
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 [
427
+ key = ";" .join (filter (None , [str (i_code_id ), str (i_country_good_origin )]))
428
+ if key in i_line_by_code .keys ():
429
+ i_line_by_code [key ]["amount_currency" ] += intra_line ["amount_currency" ]
430
+ i_line_by_code [key ]["statistic_amount_euro" ] += intra_line [
421
431
"statistic_amount_euro"
422
432
]
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 [
433
+ i_line_by_code [key ]["weight_kg" ] += intra_line ["weight_kg" ]
434
+ i_line_by_code [key ]["additional_units" ] += intra_line [
425
435
"additional_units"
426
436
]
427
437
else :
428
438
intra_line ["statement_section" ] = self .env [
429
439
"account.invoice.intrastat"
430
440
].compute_statement_section (i_code_type , self .move_type )
431
- i_line_by_code [i_code_id ] = intra_line
441
+ i_line_by_code [key ] = intra_line
432
442
return i_line_by_code , lines_to_split
433
443
434
444
0 commit comments