Skip to content

Commit 5bd9c9f

Browse files
[FIX] l10n_es_intrastat_report: Incompatibility with other intrastat
TT55417
1 parent c5a8439 commit 5bd9c9f

File tree

2 files changed

+69
-54
lines changed

2 files changed

+69
-54
lines changed

l10n_es_intrastat_report/models/l10n_es_intrastat_product_declaration.py

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,25 @@ def _get_intrastat_state(self, inv_line):
3434

3535
def _update_computation_line_vals(self, inv_line, line_vals, notedict):
3636
result = super()._update_computation_line_vals(inv_line, line_vals, notedict)
37-
intrastat_state = self._get_intrastat_state(inv_line)
38-
if intrastat_state:
39-
line_vals["intrastat_state_id"] = intrastat_state.id
40-
incoterm_id = self._get_incoterm(inv_line, notedict)
41-
if incoterm_id:
42-
line_vals["incoterm_id"] = incoterm_id.id
43-
if self.declaration_type == "dispatches" and int(self.year) >= 2022:
44-
line_vals["partner_vat"] = (
45-
inv_line.move_id.partner_shipping_id.vat or "QV999999999999"
46-
)
47-
fiscal_pos = inv_line.move_id.fiscal_position_id
48-
if fiscal_pos and fiscal_pos.intrastat == "b2c":
49-
return result
50-
if not inv_line.move_id.partner_shipping_id.vat:
51-
msg = _("Missing partner <em>VAT Number</em>")
52-
notedict["partner"][inv_line.move_id.partner_id.display_name][msg].add(
53-
notedict["inv_origin"]
37+
if self.company_id.country_id.code == "ES":
38+
intrastat_state = self._get_intrastat_state(inv_line)
39+
if intrastat_state:
40+
line_vals["intrastat_state_id"] = intrastat_state.id
41+
incoterm_id = self._get_incoterm(inv_line, notedict)
42+
if incoterm_id:
43+
line_vals["incoterm_id"] = incoterm_id.id
44+
if self.declaration_type == "dispatches" and int(self.year) >= 2022:
45+
line_vals["partner_vat"] = (
46+
inv_line.move_id.partner_shipping_id.vat or "QV999999999999"
5447
)
48+
fiscal_pos = inv_line.move_id.fiscal_position_id
49+
if fiscal_pos and fiscal_pos.intrastat == "b2c":
50+
return result
51+
if not inv_line.move_id.partner_shipping_id.vat:
52+
msg = _("Missing partner <em>VAT Number</em>")
53+
notedict["partner"][inv_line.move_id.partner_id.display_name][
54+
msg
55+
].add(notedict["inv_origin"])
5556
return result
5657

5758
def _gather_invoices_init(self, notedict):
@@ -71,21 +72,23 @@ def _prepare_invoice_domain(self):
7172
- companies subject to arrivals or dispatches only
7273
"""
7374
domain = super()._prepare_invoice_domain()[:-1]
74-
if self.declaration_type == "arrivals":
75-
domain.append(("move_type", "in", ("in_invoice", "out_refund")))
76-
elif self.declaration_type == "dispatches":
77-
domain.append(("move_type", "in", ("out_invoice", "in_refund")))
75+
if self.company_id.country_id.code == "ES":
76+
if self.declaration_type == "arrivals":
77+
domain.append(("move_type", "in", ("in_invoice", "out_refund")))
78+
elif self.declaration_type == "dispatches":
79+
domain.append(("move_type", "in", ("out_invoice", "in_refund")))
7880
return domain
7981

8082
def _generate_xml(self):
8183
return self._generate_csv()
8284

8385
def _attach_xml_file(self, xml_string, declaration_name):
8486
attach_id = super()._attach_xml_file(xml_string, declaration_name)
85-
self.ensure_one()
86-
attach = self.env["ir.attachment"].browse(attach_id)
87-
filename = "{}_{}.csv".format(self.year_month, declaration_name)
88-
attach.write({"name": filename})
87+
if self.company_id.country_id.code == "ES":
88+
self.ensure_one()
89+
attach = self.env["ir.attachment"].browse(attach_id)
90+
filename = "{}_{}.csv".format(self.year_month, declaration_name)
91+
attach.write({"name": filename})
8992
return attach.id
9093

9194
def _generate_csv_line(self, line):
@@ -161,21 +164,23 @@ def create_xls(self):
161164
@api.model
162165
def _xls_computation_line_fields(self):
163166
res = super()._xls_computation_line_fields()
164-
if (
165-
self.env.context.get("declaration_type", False) == "dispatches"
166-
and int(self.env.context.get("declaration_year", 0)) >= 2022
167-
):
168-
res.append("partner_vat")
167+
if self.company_id.country_id.code == "ES":
168+
if (
169+
self.env.context.get("declaration_type", False) == "dispatches"
170+
and int(self.env.context.get("declaration_year", 0)) >= 2022
171+
):
172+
res.append("partner_vat")
169173
return res
170174

171175
@api.model
172176
def _xls_declaration_line_fields(self):
173177
res = super()._xls_declaration_line_fields()
174-
if (
175-
self.env.context.get("declaration_type", False) == "dispatches"
176-
and int(self.env.context.get("declaration_year", 0)) >= 2022
177-
):
178-
res.append("partner_vat")
178+
if self.company_id.country_id.code == "ES":
179+
if (
180+
self.env.context.get("declaration_type", False) == "dispatches"
181+
and int(self.env.context.get("declaration_year", 0)) >= 2022
182+
):
183+
res.append("partner_vat")
179184
return res
180185

181186

@@ -190,34 +195,43 @@ class IntrastatProductComputationLine(models.Model):
190195

191196
def _prepare_grouped_fields(self, fields_to_sum):
192197
vals = super()._prepare_grouped_fields(fields_to_sum)
193-
vals["intrastat_state_id"] = self.intrastat_state_id.id
194-
# TODO: Move set incoterm_id to intrastat_product
195-
vals["incoterm_id"] = self.incoterm_id.id
196-
if self.declaration_type == "dispatches" and int(self.parent_id.year) >= 2022:
197-
vals["partner_vat"] = self.partner_vat
198+
if self.company_id.country_id.code == "ES":
199+
vals["intrastat_state_id"] = self.intrastat_state_id.id
200+
# TODO: Move set incoterm_id to intrastat_product
201+
vals["incoterm_id"] = self.incoterm_id.id
202+
if (
203+
self.declaration_type == "dispatches"
204+
and int(self.parent_id.year) >= 2022
205+
):
206+
vals["partner_vat"] = self.partner_vat
198207
return vals
199208

200209
def _prepare_declaration_line(self):
201210
vals = super()._prepare_declaration_line()
202-
# Avoid rounding in weight and fiscal value
203-
vals["weight"] = 0.0
204-
vals["amount_company_currency"] = 0.0
205-
for computation_line in self:
206-
vals["weight"] += computation_line["weight"]
207-
vals["amount_company_currency"] += (
208-
computation_line["amount_company_currency"]
209-
+ computation_line["amount_accessory_cost_company_currency"]
210-
)
211-
if not vals["weight"]:
212-
vals["weight"] = 1
211+
if self.company_id.country_id.code == "ES":
212+
# Avoid rounding in weight and fiscal value
213+
vals["weight"] = 0.0
214+
vals["amount_company_currency"] = 0.0
215+
for computation_line in self:
216+
vals["weight"] += computation_line["weight"]
217+
vals["amount_company_currency"] += (
218+
computation_line["amount_company_currency"]
219+
+ computation_line["amount_accessory_cost_company_currency"]
220+
)
221+
if not vals["weight"]:
222+
vals["weight"] = 1
213223
return vals
214224

215225
@api.model
216226
def _group_line_hashcode_fields(self):
217227
res = super()._group_line_hashcode_fields()
218-
res["intrastat_state_id"] = self.intrastat_state_id.id
219-
if self.declaration_type == "dispatches" and int(self.parent_id.year) >= 2022:
220-
res["partner_vat"] = self.partner_vat
228+
if self.company_id.country_id.code == "ES":
229+
res["intrastat_state_id"] = self.intrastat_state_id.id
230+
if (
231+
self.declaration_type == "dispatches"
232+
and int(self.parent_id.year) >= 2022
233+
):
234+
res["partner_vat"] = self.partner_vat
221235
return res
222236

223237

l10n_es_intrastat_report/views/l10n_es_intrastat_product.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
<field name="name">Spanish Intrastat Product Declaration</field>
173173
<field name="res_model">intrastat.product.declaration</field>
174174
<field name="view_mode">tree,form,graph</field>
175+
<field name="domain">[("company_country_code", "=", "ES")]</field>
175176
</record>
176177
<menuitem
177178
id="l10n_es_intrastat_product_declaration_menu"

0 commit comments

Comments
 (0)