Skip to content

Commit 141568e

Browse files
committed
[ADD] l10n_it_intrastat: aggiunto paese di origine su prodotto e categoria
1 parent a48f413 commit 141568e

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

l10n_it_intrastat/models/account.py

+28-18
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _prepare_intrastat_line(self):
8282

8383
def _prepare_intrastat_line_country_payment(self, res):
8484
self.ensure_one()
85-
country_payment_id = self.env["res.country"].browse()
85+
country_payment_id = self.env["res.country"]
8686
if self.move_id.is_sale_document():
8787
country_payment_id = self.move_id.company_id.partner_id.country_id
8888
if self.move_id.partner_bank_id:
@@ -105,7 +105,7 @@ def _prepare_intrastat_line_payment(self, res):
105105

106106
def _prepare_intrastat_line_province_dest(self, company_id, res):
107107
self.ensure_one()
108-
province_destination_id = self.env["res.country.state"].browse()
108+
province_destination_id = self.env["res.country.state"]
109109
if self.move_id.is_sale_document():
110110
province_destination_id = self.move_id.partner_id.state_id
111111
elif self.move_id.is_purchase_document():
@@ -117,7 +117,7 @@ def _prepare_intrastat_line_province_dest(self, company_id, res):
117117

118118
def _prepare_intrastat_line_country_dest(self, res):
119119
self.ensure_one()
120-
country_destination_id = self.env["res.country"].browse()
120+
country_destination_id = self.env["res.country"]
121121
if self.move_id.is_sale_document():
122122
country_destination_id = self.move_id.partner_id.country_id
123123
elif self.move_id.is_purchase_document():
@@ -126,7 +126,7 @@ def _prepare_intrastat_line_country_dest(self, res):
126126

127127
def _prepare_intrastat_line_province_origin(self, company_id, res):
128128
self.ensure_one()
129-
province_origin_id = self.env["res.country.state"].browse()
129+
province_origin_id = self.env["res.country.state"]
130130
if self.move_id.is_sale_document():
131131
province_origin_id = (
132132
company_id.intrastat_sale_province_origin_id
@@ -143,16 +143,27 @@ def _prepare_intrastat_line_province_origin(self, company_id, res):
143143

144144
def _prepare_intrastat_line_country_good_origin(self, res):
145145
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():
148157
country_good_origin_id = self.move_id.company_id.partner_id.country_id
149158
elif self.move_id.is_purchase_document():
150159
country_good_origin_id = self.move_id.partner_id.country_id
160+
else:
161+
country_good_origin_id = self.env["res.country"]
151162
res.update({"country_good_origin_id": country_good_origin_id.id})
152163

153164
def _prepare_intrastat_line_country_origin(self, res):
154165
self.ensure_one()
155-
country_origin_id = self.env["res.country"].browse()
166+
country_origin_id = self.env["res.country"]
156167
if self.move_id.is_sale_document():
157168
country_origin_id = self.move_id.company_id.partner_id.country_id
158169
elif self.move_id.is_purchase_document():
@@ -228,10 +239,9 @@ def _prepare_intrastat_line_weight(self, product_template, res):
228239
def _prepare_intrastat_line_code(self, product_template, res):
229240
self.ensure_one()
230241
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"]
233243
if intrastat_data["intrastat_code_id"]:
234-
intrastat_code = intrastat_code_model.browse(
244+
intrastat_code = self.env["report.intrastat.code"].browse(
235245
intrastat_data["intrastat_code_id"]
236246
)
237247
res.update({"intrastat_code_id": intrastat_data["intrastat_code_id"]})
@@ -412,23 +422,23 @@ def _get_intrastat_lines_to_split(self):
412422
intra_line = line._prepare_intrastat_line()
413423
i_code_id = intra_line["intrastat_code_id"]
414424
i_code_type = intra_line["intrastat_code_type"]
425+
i_country_good_origin = intra_line["country_good_origin_id"]
415426

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[
421431
"statistic_amount_euro"
422432
]
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[
425435
"additional_units"
426436
]
427437
else:
428438
intra_line["statement_section"] = self.env[
429439
"account.invoice.intrastat"
430440
].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
432442
return i_line_by_code, lines_to_split
433443

434444

l10n_it_intrastat/models/product.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class ProductCategory(models.Model):
1010
intrastat_code_id = fields.Many2one(
1111
"report.intrastat.code", string="Nomenclature Code"
1212
)
13+
intrastat_country_origin_id = fields.Many2one(
14+
"res.country", string="Origin Country"
15+
)
1316
intrastat_type = fields.Selection(
1417
[
1518
("good", "Goods"),
@@ -27,6 +30,9 @@ class ProductTemplate(models.Model):
2730
intrastat_code_id = fields.Many2one(
2831
comodel_name="report.intrastat.code", string="Intrastat Code"
2932
)
33+
intrastat_country_origin_id = fields.Many2one(
34+
"res.country", string="Origin Country"
35+
)
3036
intrastat_type = fields.Selection(
3137
selection=[
3238
("good", "Goods"),
@@ -44,12 +50,20 @@ def get_intrastat_data(self):
4450
- Intrastat Code on product template
4551
- Intrastat Code on product category
4652
"""
47-
res = {"intrastat_code_id": False, "intrastat_type": False}
53+
res = {
54+
"intrastat_code_id": False,
55+
"intrastat_country_origin_id": False,
56+
"intrastat_type": False,
57+
}
4858
# From Product
4959
if self.intrastat_type:
5060
res["intrastat_code_id"] = self.intrastat_code_id.id
61+
res["intrastat_country_origin_id"] = self.intrastat_country_origin_id.id
5162
res["intrastat_type"] = self.intrastat_type
5263
elif self.categ_id and self.categ_id.intrastat_code_id:
5364
res["intrastat_code_id"] = self.categ_id.intrastat_code_id.id
65+
res[
66+
"intrastat_country_origin_id"
67+
] = self.categ_id.intrastat_country_origin_id.id
5468
res["intrastat_type"] = self.categ_id.intrastat_type
5569
return res

l10n_it_intrastat/views/product.xml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
attrs="{'invisible':[('intrastat_type','!=', 'good'),('intrastat_type','!=', 'service')],
1818
'required':[('intrastat_type','in', ['good', 'service'])]}"
1919
/>
20+
<field name="intrastat_country_origin_id" />
2021
</group>
2122

2223
</group>
@@ -38,6 +39,7 @@
3839
attrs="{'invisible':[('intrastat_type','!=', 'good'),('intrastat_type','!=', 'service')],
3940
'required':[('intrastat_type','in', ['good', 'service'])]}"
4041
/>
42+
<field name="intrastat_country_origin_id" />
4143
</group>
4244
</group>
4345
</xpath>

0 commit comments

Comments
 (0)