feat(spp_gis_report): metric disaggregation in GIS reports (re-land from #76)#280
feat(spp_gis_report): metric disaggregation in GIS reports (re-land from #76)#280gonzalesedwin1123 wants to merge 3 commits into
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
Code Review — PR #280
|
|
The This PR removes the boolean Merge order: #295 depends on this PR (and #277), so it must merge after both and be rebased onto the result. |
kneckinator
left a comment
There was a problem hiding this comment.
Two issues from review worth addressing before merge (plus minor notes left in the summary review). Both concern the boolean→dimension migration path and the member-expansion area attribution.
| "spp_gis_report/static/src/css/gis_report.css", | ||
| ], | ||
| }, | ||
| "post_init_hook": "_migrate_boolean_disaggregation", |
There was a problem hiding this comment.
The migration never runs on the path that actually has legacy data — and its raw SQL targets a non-existent table.
post_init_hook fires only when the module is installed (odoo/modules/loading.py: the hook is gated on update_operation == 'install'), never on upgrade or reinit. On a fresh install the old boolean columns don't exist, so _migrate_boolean_disaggregation correctly no-ops. On an upgrade of an already-installed module — the only case where disaggregate_by_* data exists — the hook is never invoked, so those settings are silently dropped.
Separately, even if it did run, the INSERT INTO spp_gis_report_spp_demographic_dimension_rel target is wrong: Odoo names an implicit m2m relation table from the alphabetically sorted table names (fields_relational.py: tables = sorted([model._table, comodel._table])), so the real table is spp_demographic_dimension_spp_gis_report_rel. The hardcoded name would raise relation does not exist.
Recommend converting this to a post-migration script at spp_gis_report/migrations/19.0.2.1.0/post-migrate.py (def migrate(cr, version), return early when version is falsy), and deriving the relation/column names from the field metadata (env['spp.gis.report']._fields['dimension_ids'].relation / .column1 / .column2) instead of hardcoding. Then drop post_init_hook here and the migration code from __init__.py.
| JOIN spp_group_membership gm ON gm.%s = grp.id AND NOT gm.%s | ||
| JOIN res_partner ind ON ind.id = gm.%s | ||
| %s | ||
| JOIN area_mapping am ON am.child_id = COALESCE(ind.%s, grp.%s) |
There was a problem hiding this comment.
SQL and Python fallback disagree on member area attribution.
Here the SQL path resolves a member's area as COALESCE(ind.area, grp.area) — the individual's own area takes precedence, falling back to the group's. But _disaggregation_python_expanded only ever reads the group's area (grp_area_id = group_area.get(grp_id)) and never fetches the individual's own area_field.
So the two paths assign different base areas whenever a member's own area differs from their group's. Because _compute_disaggregation routes SQL-compilable dimensions through this path and fallback (e.g. CEL) dimensions through the Python path and then merges by area, the same person can land in area A for one dimension and area B for another — making an area's per-dimension totals mutually inconsistent for the same population.
The docstrings say "area inheritance from the group," and test_member_expansion_area_inheritance only covers the member-has-no-area case, so the divergence is untested. Please make both paths use the same rule and add a test where the member has a different area than its group.
…on script The post_init_hook only runs on fresh install (odoo/modules/loading.py gates it on update_operation == 'install'), never on upgrade -- exactly the path where legacy disaggregate_by_* data exists -- so the migration never fired. Its raw INSERT also targeted spp_gis_report_spp_demographic_dimension_rel, but Odoo names implicit m2m tables from the alphabetically sorted table names, so the real table is spp_demographic_dimension_spp_gis_report_rel and the insert would have raised. Move the logic to migrations/19.0.2.1.0/post-migrate.py so it runs on upgrade, and derive the relation/column names from the dimension_ids field metadata so they can't drift from Odoo's canonical naming.
|
Pushed 3337da9 addressing the migration finding directly (converted the Ran the repo's pre-commit hooks on the changed files — ruff, Odoo-19 compat, bandit, whitespace/EOF all pass. (semgrep couldn't run locally due to a Python 3.14 toolchain crash, unrelated to this change; worth confirming in CI.) Still open for you: the member-expansion area-attribution divergence ( |
Re-lands the spp_gis_report portion of reverted PR #76 (revert: #271). Wave 3 — stacked on the spp_metric_service Wave-2 PR (and transitively #275); merge those first. Base is set to
reland/metric-serviceso this diff shows only spp_gis_report.Summary
Verification
./spp t spp_gis_reporton an integration state with feat(spp_cel_domain): SQL CASE compiler, read-only smart-op lookup, translator cache tests (re-land from #76) #275 + Wave 2 merged: 188 passed, 0 failed