Skip to content

Commit bba08ad

Browse files
committed
[16.0][FIX] intrastat_product: set the correct country code for Greece
Check correct country code for Greece. The correct is EL instead of GR.
1 parent 3cd4ae5 commit bba08ad

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

intrastat_product/models/intrastat_product_declaration.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
_logger = logging.getLogger(__name__)
1818

1919

20+
COUNTRY_CODE_MAPPING = {
21+
"GB": "XU",
22+
"GR": "EL",
23+
}
24+
25+
2026
class IntrastatProductDeclaration(models.Model):
2127
_name = "intrastat.product.declaration"
2228
_description = "Intrastat Product Declaration"
@@ -1167,8 +1173,7 @@ def _compute_region_code(self):
11671173
def _compute_src_dest_country_code(self):
11681174
for this in self:
11691175
code = this.src_dest_country_id and this.src_dest_country_id.code or False
1170-
if code == "GB":
1171-
code = "XI" # Northern Ireland
1176+
code = self._check_country_code(code)
11721177
this.src_dest_country_code = code
11731178

11741179
@api.depends("product_origin_country_id")
@@ -1179,10 +1184,7 @@ def _compute_product_origin_country_code(self):
11791184
and this.product_origin_country_id.code
11801185
or False
11811186
)
1182-
if code == "GB":
1183-
code = "XU"
1184-
# XU can be used when you don't know if the product
1185-
# originate from Great-Britain or from Northern Ireland
1187+
code = self._check_country_code(code)
11861188
this.product_origin_country_code = code
11871189

11881190
@api.constrains("vat")
@@ -1267,6 +1269,10 @@ def _prepare_declaration_line(self):
12671269
vals["amount_company_currency"] = int(round(vals["amount_company_currency"]))
12681270
return vals
12691271

1272+
def _check_country_code(self, code):
1273+
"""Check and adapt country code for Intrastat purpose"""
1274+
return COUNTRY_CODE_MAPPING.get(code, code)
1275+
12701276

12711277
class IntrastatProductDeclarationLine(models.Model):
12721278
_name = "intrastat.product.declaration.line"

intrastat_product/tests/test_intrastat_product.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def test_declaration_manual_lines(self):
9696
declaration_line = declaration_line_form.save()
9797
self.assertEqual(declaration_line.src_dest_country_code, "FR")
9898

99+
# Test Greece country code conversion
100+
declaration_line_form_greece = Form(
101+
self.env["intrastat.product.declaration.line"].with_context(
102+
default_parent_id=self.declaration.id
103+
)
104+
)
105+
declaration_line_form_greece.src_dest_country_id = self.env.ref("base.gr")
106+
declaration_line_form_greece = declaration_line_form.save()
107+
self.assertEqual(declaration_line_form_greece.src_dest_country_code, "EL")
108+
99109
def test_declaration_no_country(self):
100110
self.demo_company.country_id = False
101111
with self.assertRaises(ValidationError):

0 commit comments

Comments
 (0)