Skip to content

Commit fded442

Browse files
committed
feat(spp_scoring): add Score Registrant action and improve wizard UI
- Adds an `ir.actions.server` bound to res.partner so the Actions menu on the registrant form and the bulk Actions on the registry list both expose a "Score Registrant" entry-point. The existing smart button only opens prior results; this is the missing trigger for manual scoring. - Reworks `action_score_registrant` to handle both single and multi record selection (previously failed `ensure_one` on bulk list calls). - Wizard form view: shows a count banner when registrants are pre-selected, hides the raw domain filter in that mode, and renders selected registrants as a single-column embedded list so 80+ entries no longer blow out the right column.
1 parent d83e81c commit fded442

5 files changed

Lines changed: 83 additions & 10 deletions

File tree

spp_scoring/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "OpenSPP Scoring",
33
"category": "OpenSPP/Targeting",
4-
"version": "19.0.2.0.0",
4+
"version": "19.0.2.0.1",
55
"sequence": 1,
66
"author": "OpenSPP.org",
77
"website": "https://github.com/OpenSPP/OpenSPP2",

spp_scoring/models/res_partner.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,25 @@ def action_view_scoring_results(self):
3737
}
3838

3939
def action_score_registrant(self):
40-
"""Open the batch scoring wizard pre-filled for this registrant."""
41-
self.ensure_one()
40+
"""Open the batch scoring wizard pre-filled for the selected registrant(s).
41+
42+
Works for both single-record (form view) and multi-record
43+
(list-view bulk selection) calls. The wizard's `registrant_ids`
44+
m2m takes precedence over `registrant_domain` (see
45+
wizard/batch_scoring_wizard.py:70), so we only need to seed the
46+
m2m. The redundant `default_domain` keeps the wizard form's
47+
"Domain" field readable when a user opens it on one record.
48+
"""
49+
if not self:
50+
return False
51+
ctx = {"default_registrant_ids": self.ids}
52+
if len(self) == 1:
53+
ctx["default_registrant_domain"] = f"[('id', '=', {self.id})]"
4254
return {
4355
"name": "Score Registrant",
4456
"type": "ir.actions.act_window",
4557
"res_model": "spp.batch.scoring.wizard",
4658
"view_mode": "form",
4759
"target": "new",
48-
"context": {
49-
"default_registrant_ids": self.ids,
50-
"default_domain": f"[('id', '=', {self.id})]",
51-
},
60+
"context": ctx,
5261
}

spp_scoring/views/res_partner_views.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,31 @@
2525
</xpath>
2626
</field>
2727
</record>
28+
29+
<!-- Action → Score Registrant (cog / Actions dropdown).
30+
31+
The Scores smart button only opens existing results; this server
32+
action exposes the actual "trigger scoring" entry-point in the
33+
form's Actions dropdown and on the registry list view's bulk
34+
Actions menu. Calls the existing `action_score_registrant`
35+
method which opens the batch scoring wizard pre-filled for
36+
the selected registrant(s). See OP#837. -->
37+
<record id="action_score_registrant_server" model="ir.actions.server">
38+
<field name="name">Score Registrant</field>
39+
<field name="model_id" ref="base.model_res_partner" />
40+
<field name="binding_model_id" ref="base.model_res_partner" />
41+
<field name="binding_view_types">form,list</field>
42+
<field
43+
name="group_ids"
44+
eval="[(6, 0, [
45+
ref('spp_scoring.group_scoring_officer'),
46+
ref('spp_scoring.group_scoring_manager'),
47+
ref('spp_scoring.group_scoring_config_admin'),
48+
])]"
49+
/>
50+
<field name="state">code</field>
51+
<field
52+
name="code"
53+
>action = records.action_score_registrant() if records else None</field>
54+
</record>
2855
</odoo>

spp_scoring/wizard/batch_scoring_wizard.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ast
22
import logging
33

4-
from odoo import _, fields, models
4+
from odoo import _, api, fields, models
55
from odoo.exceptions import UserError
66

77
_logger = logging.getLogger(__name__)
@@ -40,6 +40,15 @@ class BatchScoringWizard(models.TransientModel):
4040
default=1000,
4141
help="Maximum number of registrants to process (0 for no limit)",
4242
)
43+
registrant_count = fields.Integer(
44+
string="# Selected",
45+
compute="_compute_registrant_count",
46+
)
47+
48+
@api.depends("registrant_ids")
49+
def _compute_registrant_count(self):
50+
for wizard in self:
51+
wizard.registrant_count = len(wizard.registrant_ids)
4352

4453
# Results
4554
state = fields.Selection(

spp_scoring/wizard/batch_scoring_wizard_views.xml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,46 @@
66
<field name="model">spp.batch.scoring.wizard</field>
77
<field name="arch" type="xml">
88
<form string="Batch Scoring">
9+
<!-- Banner: explicit selection takes precedence over domain filter. -->
10+
<div
11+
class="alert alert-info text-center"
12+
role="alert"
13+
invisible="state != 'draft' or registrant_count == 0"
14+
>
15+
<strong>
16+
<field name="registrant_count" readonly="1" />
17+
</strong>
18+
registrant(s) pre-selected. The domain filter below is
19+
ignored while specific registrants are listed.
20+
</div>
21+
922
<group invisible="state != 'draft'">
1023
<group string="Scoring Configuration">
1124
<field name="model_id" />
1225
<field name="is_fail_fast" />
1326
<field name="max_records" />
1427
</group>
15-
<group string="Registrant Selection">
28+
<group string="Domain Filter" invisible="registrant_count != 0">
1629
<field name="registrant_domain" />
17-
<field name="registrant_ids" widget="many2many_tags" />
1830
</group>
1931
</group>
2032

33+
<!-- Selected registrants — embedded list keeps the wizard
34+
scannable when 80+ partners were pre-selected from a
35+
bulk list-view action. -->
36+
<notebook invisible="state != 'draft' or registrant_count == 0">
37+
<page name="selected_registrants" string="Selected Registrants">
38+
<field
39+
name="registrant_ids"
40+
options="{'no_create': True, 'no_open': True}"
41+
>
42+
<list create="false" delete="true">
43+
<field name="name" />
44+
</list>
45+
</field>
46+
</page>
47+
</notebook>
48+
2149
<group invisible="state != 'done'">
2250
<group string="Results">
2351
<field name="result_count" />

0 commit comments

Comments
 (0)