Skip to content

Commit ef37f37

Browse files
committed
fix(spp_hazard_programs,spp_import_match,spp_oauth): beta fixes and import overwrite toggle
- spp_hazard_programs: remove unused ACL file, fix view XML - spp_import_match: migrate legacy JS/XML to OWL components, add overwrite match toggle with per-import control, add import result notifications with match counts - spp_oauth: fix RSA encode/decode and settings view for Odoo 19
1 parent a4f3701 commit ef37f37

21 files changed

Lines changed: 343 additions & 205 deletions

File tree

spp_hazard_programs/README.rst

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ OpenSPP Hazard Programs Integration
1010
!! source digest: sha256:e4ca3f5b5e8c998b833ccd6526f575c07f53a38ac49875511c31201f13122916
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
13-
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1414
:target: https://odoo-community.org/page/development-status
15-
:alt: Alpha
15+
:alt: Beta
1616
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
1717
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1818
:alt: License: LGPL-3
@@ -44,15 +44,15 @@ Key Capabilities
4444
Key Models
4545
~~~~~~~~~~
4646

47-
+----------------------------------+-----------------------------------+
48-
| Model | Description |
49-
+==================================+===================================+
50-
| ``spp.program`` (extend) | Adds target incidents, emergency |
51-
| | mode, damage filter |
52-
+----------------------------------+-----------------------------------+
53-
| ``spp.hazard.incident`` (extend) | Adds reverse relation to response |
54-
| | programs |
55-
+----------------------------------+-----------------------------------+
47+
+----------------------------------+----------------------------------+
48+
| Model | Description |
49+
+==================================+==================================+
50+
| ``spp.program`` (extend) | Adds target incidents, emergency |
51+
| | mode, damage filter |
52+
+----------------------------------+----------------------------------+
53+
| ``spp.hazard.incident`` (extend) | Adds reverse relation to |
54+
| | response programs |
55+
+----------------------------------+----------------------------------+
5656

5757
UI Location
5858
~~~~~~~~~~~
@@ -89,10 +89,6 @@ Dependencies
8989

9090
``spp_hazard``, ``spp_programs``
9191

92-
.. IMPORTANT::
93-
This is an alpha version, the data model and design can change at any time without warning.
94-
Only for development or testing purpose, do not use in production.
95-
9692
**Table of contents**
9793

9894
.. contents::

spp_hazard_programs/__manifest__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
"author": "OpenSPP.org",
1313
"website": "https://github.com/OpenSPP/OpenSPP2",
1414
"license": "LGPL-3",
15-
"development_status": "Alpha",
15+
"development_status": "Beta",
1616
"maintainers": ["jeremi", "gonzalesedwin1123", "reichie020212"],
1717
"depends": [
1818
"spp_hazard",
1919
"spp_programs",
2020
],
2121
"data": [
22-
"security/ir.model.access.csv",
2322
"views/program_views.xml",
2423
"views/incident_views.xml",
2524
],

spp_hazard_programs/security/ir.model.access.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

spp_hazard_programs/static/description/index.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ <h1 class="title">OpenSPP Hazard Programs Integration</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:e4ca3f5b5e8c998b833ccd6526f575c07f53a38ac49875511c31201f13122916
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OpenSPP/OpenSPP2/tree/19.0/spp_hazard_programs"><img alt="OpenSPP/OpenSPP2" src="https://img.shields.io/badge/github-OpenSPP%2FOpenSPP2-lightgray.png?logo=github" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OpenSPP/OpenSPP2/tree/19.0/spp_hazard_programs"><img alt="OpenSPP/OpenSPP2" src="https://img.shields.io/badge/github-OpenSPP%2FOpenSPP2-lightgray.png?logo=github" /></a></p>
373373
<p>Links hazard incidents to emergency response programs. Enables programs
374374
to target affected populations using verified impact data, filter
375375
registrants by damage severity, and automatically enable emergency mode
@@ -393,8 +393,8 @@ <h1>Key Capabilities</h1>
393393
<h1>Key Models</h1>
394394
<table border="1" class="docutils">
395395
<colgroup>
396-
<col width="49%" />
397-
<col width="51%" />
396+
<col width="50%" />
397+
<col width="50%" />
398398
</colgroup>
399399
<thead valign="bottom">
400400
<tr><th class="head">Model</th>
@@ -407,8 +407,8 @@ <h1>Key Models</h1>
407407
mode, damage filter</td>
408408
</tr>
409409
<tr><td><tt class="docutils literal">spp.hazard.incident</tt> (extend)</td>
410-
<td>Adds reverse relation to response
411-
programs</td>
410+
<td>Adds reverse relation to
411+
response programs</td>
412412
</tr>
413413
</tbody>
414414
</table>
@@ -448,11 +448,6 @@ <h1>Extension Points</h1>
448448
<div class="section" id="dependencies">
449449
<h1>Dependencies</h1>
450450
<p><tt class="docutils literal">spp_hazard</tt>, <tt class="docutils literal">spp_programs</tt></p>
451-
<div class="admonition important">
452-
<p class="first admonition-title">Important</p>
453-
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
454-
Only for development or testing purpose, do not use in production.</p>
455-
</div>
456451
<p><strong>Table of contents</strong></p>
457452
<div class="contents local topic" id="contents">
458453
<ul class="simple">

spp_hazard_programs/views/program_views.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
<field name="category_id" />
6464
<field name="status" widget="badge" />
6565
<field name="severity" widget="badge" />
66-
<field name="affected_registrant_count" />
6766
</list>
6867
</field>
6968
</page>

spp_import_match/README.rst

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ OpenSPP Import Match
1010
!! source digest: sha256:b57dea1315fd1f9af8f15720c5332b182c0a01fddd827a3daa73a8e950d41faa
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
13-
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1414
:target: https://odoo-community.org/page/development-status
15-
:alt: Alpha
15+
:alt: Beta
1616
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
1717
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
1818
:alt: License: LGPL-3
@@ -47,15 +47,15 @@ Key Capabilities
4747
Key Models
4848
~~~~~~~~~~
4949

50-
+-----------------------------+----------------------------------------+
51-
| Model | Description |
52-
+=============================+========================================+
53-
| ``spp.import.match`` | Matching rule configuration for a |
54-
| | specific model |
55-
+-----------------------------+----------------------------------------+
56-
| ``spp.import.match.fields`` | Individual fields used in a rule, |
57-
| | supports sub-fields |
58-
+-----------------------------+----------------------------------------+
50+
+-----------------------------+---------------------------------------+
51+
| Model | Description |
52+
+=============================+=======================================+
53+
| ``spp.import.match`` | Matching rule configuration for a |
54+
| | specific model |
55+
+-----------------------------+---------------------------------------+
56+
| ``spp.import.match.fields`` | Individual fields used in a rule, |
57+
| | supports sub-fields |
58+
+-----------------------------+---------------------------------------+
5959

6060
Configuration
6161
~~~~~~~~~~~~~
@@ -106,10 +106,6 @@ Dependencies
106106
``base``, ``spp_base_common``, ``base_import``, ``queue_job``,
107107
``spp_security``
108108

109-
.. IMPORTANT::
110-
This is an alpha version, the data model and design can change at any time without warning.
111-
Only for development or testing purpose, do not use in production.
112-
113109
**Table of contents**
114110

115111
.. contents::

spp_import_match/__manifest__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"author": "OpenSPP.org",
1111
"website": "https://github.com/OpenSPP/OpenSPP2",
1212
"license": "LGPL-3",
13-
"development_status": "Alpha",
13+
"development_status": "Beta",
1414
"maintainers": ["jeremi", "gonzalesedwin1123"],
1515
"depends": ["base", "spp_base_common", "base_import", "queue_job", "spp_security"],
1616
"data": [
@@ -20,10 +20,8 @@
2020
],
2121
"assets": {
2222
"web.assets_backend": [
23-
"spp_import_match/static/src/legacy/js/custom_base_import.js",
24-
],
25-
"web.assets_qweb": [
26-
"spp_import_match/static/src/legacy/xml/custom_base_import.xml",
23+
"spp_import_match/static/src/import_match_selector/import_match_selector.js",
24+
"spp_import_match/static/src/import_match_selector/import_match_selector.xml",
2725
],
2826
},
2927
"demo": [],

spp_import_match/models/base.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
22
import logging
3+
import threading
34

45
from odoo import api, models
56

67
_logger = logging.getLogger(__name__)
78

9+
# Thread-local storage to pass import match counts from load() to execute_import()
10+
_import_match_local = threading.local()
11+
812

913
class Base(models.AbstractModel):
1014
_inherit = "base"
@@ -16,14 +20,13 @@ def load(self, fields, data):
1620
fields,
1721
option_config_ids=self.env.context.get("import_match_ids", []),
1822
)
19-
model_id = self.env["ir.model"].search([("model", "=", self._name)])
20-
overwrite_match = True
21-
import_match = self.env["spp.import.match"].search([("model_id", "=", model_id.id)])
22-
if import_match:
23-
overwrite_match = import_match.overwrite_match
23+
overwrite_match = self.env.context.get("overwrite_match", False)
2424

2525
if usable:
2626
newdata = list()
27+
match_created = 0
28+
match_skipped = 0
29+
match_overwritten = 0
2730
if ".id" in fields:
2831
column = fields.index(".id")
2932
fields[column] = "id"
@@ -70,6 +73,7 @@ def load(self, fields, data):
7073
row["id"] = ext_id[match.id] if match else row.get("id", "")
7174
if match:
7275
if overwrite_match:
76+
match_overwritten += 1
7377
flat_fields_to_remove = [item for sublist in field_to_match for item in sublist]
7478
for fields_pop in flat_fields_to_remove:
7579
# Set one2many and many2many fields to False if matched
@@ -80,19 +84,25 @@ def load(self, fields, data):
8084
]:
8185
row[fields_pop] = False
8286
newdata.append(tuple(row[f] for f in clean_fields))
87+
else:
88+
match_skipped += 1
8389
else:
90+
match_created += 1
8491
newdata.append(tuple(row[f] for f in fields))
8592
data = newdata
93+
if self.env.context.get("import_match_ids"):
94+
_import_match_local.counts = {
95+
"created": match_created,
96+
"skipped": match_skipped,
97+
"overwritten": match_overwritten,
98+
}
8699
return super().load(fields, data)
87100

88101
def write(self, vals):
89-
# nosemgrep: odoo-sudo-without-context - reading model metadata requires sudo
90-
model = self.env["ir.model"].sudo().search([("model", "=", self._name)])
91102
new_vals = vals.copy()
92-
for rec in vals:
93-
field_name = rec
94-
if not vals[field_name]:
95-
field = self.env["ir.model.fields"].search([("model_id", "=", model.id), ("name", "=", field_name)])
96-
if field and field.ttype in ("one2many", "many2many"):
97-
new_vals.pop(rec)
103+
for field_name, value in vals.items():
104+
if not value and field_name in self._fields:
105+
field_meta = self._fields[field_name]
106+
if field_meta.type in ("one2many", "many2many"):
107+
new_vals.pop(field_name)
98108
return super().write(new_vals)

spp_import_match/models/base_import.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from odoo.addons.queue_job.exception import FailedJobError
1111

12+
from .base import _import_match_local
13+
1214
_logger = logging.getLogger(__name__)
1315
# options defined in base_import/import.js
1416
OPT_HAS_HEADER = "headers"
@@ -62,18 +64,30 @@ def execute_import(self, fields, columns, options, dryrun=False):
6264
_logger.info("Started Import: %s with rows %d", self.res_model, len(input_file_data))
6365

6466
import_match_ids = options.get("import_match_ids", [])
67+
overwrite_match = options.get("overwrite_match", False)
68+
_import_match_local.counts = None
6569

6670
if dryrun:
6771
_logger.info("Doing dry-run import")
6872
if import_match_ids:
69-
self = self.with_context(import_match_ids=import_match_ids)
70-
return super().execute_import(fields, columns, options, dryrun=True)
73+
self = self.with_context(import_match_ids=import_match_ids, overwrite_match=overwrite_match)
74+
result = super().execute_import(fields, columns, options, dryrun=True)
75+
counts = getattr(_import_match_local, "counts", None)
76+
if counts:
77+
result["import_match_counts"] = counts
78+
_import_match_local.counts = None
79+
return result
7180

7281
if len(input_file_data) <= 100:
7382
_logger.info("Doing normal import")
7483
if import_match_ids:
75-
self = self.with_context(import_match_ids=import_match_ids)
76-
return super().execute_import(fields, columns, options, dryrun=False)
84+
self = self.with_context(import_match_ids=import_match_ids, overwrite_match=overwrite_match)
85+
result = super().execute_import(fields, columns, options, dryrun=False)
86+
counts = getattr(_import_match_local, "counts", None)
87+
if counts:
88+
result["import_match_counts"] = counts
89+
_import_match_local.counts = None
90+
return result
7791

7892
_logger.info("Started Asynchronous Import: %s", self.res_model)
7993
# asynchronous import

spp_import_match/models/import_match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _match_find(self, model, converted_row, imported_row):
7070
if len(match) == 1:
7171
return match
7272
elif len(match) > 1:
73-
raise ValidationError(_("Multiple matches found for '%s'!").format(match[0].name))
73+
raise ValidationError(_("Multiple matches found for '%s'!") % match[0].name)
7474

7575
return model
7676

0 commit comments

Comments
 (0)