Skip to content

Commit bdf9a4f

Browse files
Merge pull request #14 from OpenSPP/fix/spp-area-hdx-country-iso3
fix(spp_area_hdx): derive ISO3 code from hdx_dataset_id
2 parents 843b1b8 + 135302c commit bdf9a4f

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

spp_area_hdx/README.rst

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ OpenSPP HDX COD Integration
1414
!! source digest: sha256:cf138e08394d940c78e288afd34fd606ac55ac16203d679b29c392b02aa4bdae
1515
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1616
17-
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1818
:target: https://odoo-community.org/page/development-status
19-
:alt: Alpha
19+
:alt: Beta
2020
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
@@ -119,11 +119,6 @@ Dependencies
119119

120120
``spp_area``, ``spp_gis``
121121

122-
.. IMPORTANT::
123-
This is an alpha version, the data model and design can change at any time without warning.
124-
Only for development or testing purpose, do not use in production.
125-
`More details on development status <https://odoo-community.org/page/development-status>`_
126-
127122
**Table of contents**
128123

129124
.. contents::
@@ -150,6 +145,23 @@ Authors
150145
Maintainers
151146
-----------
152147

148+
.. |maintainer-jeremi| image:: https://github.com/jeremi.png?size=40px
149+
:target: https://github.com/jeremi
150+
:alt: jeremi
151+
.. |maintainer-gonzalesedwin1123| image:: https://github.com/gonzalesedwin1123.png?size=40px
152+
:target: https://github.com/gonzalesedwin1123
153+
:alt: gonzalesedwin1123
154+
.. |maintainer-reichie020212| image:: https://github.com/reichie020212.png?size=40px
155+
:target: https://github.com/reichie020212
156+
:alt: reichie020212
157+
.. |maintainer-emjay0921| image:: https://github.com/emjay0921.png?size=40px
158+
:target: https://github.com/emjay0921
159+
:alt: emjay0921
160+
161+
Current maintainers:
162+
163+
|maintainer-jeremi| |maintainer-gonzalesedwin1123| |maintainer-reichie020212| |maintainer-emjay0921|
164+
153165
This module is part of the `OpenSPP/OpenSPP2 <https://github.com/OpenSPP/OpenSPP2/tree/19.0/spp_area_hdx>`_ project on GitHub.
154166

155167
You are welcome to contribute.

spp_area_hdx/__manifest__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"author": "OpenSPP.org",
1111
"website": "https://github.com/OpenSPP/OpenSPP2",
1212
"license": "LGPL-3",
13-
"development_status": "Alpha",
13+
"development_status": "Beta",
14+
"maintainers": ["jeremi", "gonzalesedwin1123", "reichie020212", "emjay0921"],
1415
"depends": [
1516
"spp_area",
1617
"spp_gis",

spp_area_hdx/models/hdx_cod_source.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ class HdxCodSource(models.Model):
4040

4141
_country_unique = models.Constraint("UNIQUE(country_id)", "Only one COD source per country is allowed")
4242

43-
@api.depends("country_id")
43+
@api.depends("country_id", "hdx_dataset_id")
4444
def _compute_country_iso3(self):
45-
"""Compute ISO3 code from country."""
45+
"""Compute ISO3 code from HDX dataset ID or country.
46+
47+
HDX dataset IDs follow the pattern ``cod-ab-{iso3}`` (e.g., ``cod-ab-phl``),
48+
which contains the correct 3-letter ISO code. Falls back to the 2-letter
49+
``res.country.code`` when the dataset ID is not set.
50+
"""
4651
for record in self:
47-
if record.country_id:
52+
if record.hdx_dataset_id and record.hdx_dataset_id.startswith("cod-ab-"):
53+
record.country_iso3 = record.hdx_dataset_id[len("cod-ab-"):].upper()
54+
elif record.country_id:
4855
record.country_iso3 = record.country_id.code
4956
else:
5057
record.country_iso3 = False
@@ -63,7 +70,12 @@ def action_sync_from_hdx(self):
6370

6471
try:
6572
client = HdxClient()
66-
dataset = client.search_cod_datasets(self.country_iso3)
73+
74+
# Use existing dataset ID if available, otherwise search by ISO3
75+
if self.hdx_dataset_id:
76+
dataset = client.get_dataset(self.hdx_dataset_id)
77+
else:
78+
dataset = client.search_cod_datasets(self.country_iso3)
6779

6880
if not dataset:
6981
raise UserError(_("No COD dataset found for country %s") % self.country_id.name)
@@ -88,8 +100,9 @@ def action_sync_from_hdx(self):
88100
admin_level = client.detect_admin_level(resource_name)
89101

90102
# Check if resource already exists
103+
_rid, _lvl = resource_id, admin_level
91104
existing_resource = self.resource_ids.filtered(
92-
lambda r: r.hdx_resource_id == resource_id or r.admin_level == admin_level
105+
lambda r, rid=_rid, lvl=_lvl: r.hdx_resource_id == rid or r.admin_level == lvl
93106
)
94107

95108
resource_vals = {

spp_area_hdx/tests/test_hdx_cod_source.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def setUp(self):
1818
self.source = self.env.ref("spp_area_hdx.cod_source_lka")
1919

2020
def test_compute_country_iso3(self):
21-
"""Test ISO3 code computation."""
22-
self.assertEqual(self.source.country_iso3, "LK")
21+
"""Test ISO3 code computation from hdx_dataset_id."""
22+
self.assertEqual(self.source.country_iso3, "LKA")
2323

2424
def test_unique_country_constraint(self):
2525
"""Test that only one source per country is allowed."""
@@ -31,13 +31,13 @@ def test_unique_country_constraint(self):
3131
}
3232
)
3333

34-
@patch("odoo.addons.spp_area_hdx.services.hdx_client.HdxClient.search_cod_datasets")
34+
@patch("odoo.addons.spp_area_hdx.services.hdx_client.HdxClient.get_dataset")
3535
@patch("odoo.addons.spp_area_hdx.services.hdx_client.HdxClient.get_geojson_resources")
3636
@patch("odoo.addons.spp_area_hdx.services.hdx_client.HdxClient.detect_admin_level")
37-
def test_action_sync_from_hdx(self, mock_detect_level, mock_get_resources, mock_search):
37+
def test_action_sync_from_hdx(self, mock_detect_level, mock_get_resources, mock_get_dataset):
3838
"""Test syncing resources from HDX."""
39-
# Mock HDX API responses
40-
mock_search.return_value = {
39+
# Mock HDX API responses — source has hdx_dataset_id set, so get_dataset is called
40+
mock_get_dataset.return_value = {
4141
"name": "cod-ab-lka",
4242
"title": "Sri Lanka Administrative Boundaries",
4343
}

0 commit comments

Comments
 (0)