Skip to content

Commit

Permalink
[IMP] l10n_es_aeat: Add country ISO code mapper function
Browse files Browse the repository at this point in the history
Fulfills the need (seen in l10n_es_aeat_mod369) to obtain the ISO code of a country based on the country code stored in Odoo. It is an inverse function of _map_aeat_country_code.
  • Loading branch information
aritzolea committed Nov 15, 2023
1 parent d77270e commit 4ee2e87
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions l10n_es_aeat/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def _map_aeat_country_code(self, country_code, extended=False):
country_code_map.update({"RE": "FR", "GP": "FR", "MQ": "FR", "GF": "FR"})
return country_code_map.get(country_code, country_code)

def _map_aeat_country_iso_code(self, country_id):
"""Map country ISO code according to AEAT code"""
code = country_id.code
country_iso_code_map = {"GR": "EL"}
return country_iso_code_map.get(code, code)

@ormcache("self.env")
def _get_aeat_europe_codes(self):
europe = self.env.ref("base.europe", raise_if_not_found=False)
Expand Down
14 changes: 14 additions & 0 deletions l10n_es_aeat/tests/test_l10n_es_aeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,17 @@ def test_unique_date_range(self):
self.env["l10n.es.aeat.map.tax"].create(
{"date_to": "2021-01-01", "model": 303}
)

def test_map_aeat_iso_code_greece(self):
res_partner_obj = self.env["res.partner"]
greece_country = self.env.ref("base.gr")
iso_code = "EL"
mapping_return = res_partner_obj._map_aeat_country_iso_code(greece_country)
self.assertEqual(iso_code, mapping_return)

def test_map_aeat_iso_code_no_mapping(self):
res_partner_obj = self.env["res.partner"]
spain_country = self.env.ref("base.es")
iso_code = "ES"
mapping_return = res_partner_obj._map_aeat_country_iso_code(spain_country)
self.assertEqual(iso_code, mapping_return)

0 comments on commit 4ee2e87

Please sign in to comment.