Skip to content

Commit 6a6e6aa

Browse files
committed
feat(cr): lock operation after proceeding and hide disabled radio options
- Add is_operation_locked boolean field set when proceeding to Documents/Review - Show computed operation_display char field when locked instead of radio - Change filterable_radio widget to hide disabled options (d-none) instead of graying them out - Reset lock when operation is changed via onchange
1 parent b5bf01f commit 6a6e6aa

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

spp_base_common/static/src/js/filterable_radio_field.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {registry} from "@web/core/registry";
55
import {_t} from "@web/core/l10n/translation";
66

77
/**
8-
* A radio widget that supports disabling individual options based on
8+
* A radio widget that supports hiding individual options based on
99
* boolean fields on the record.
1010
*
1111
* Usage in XML views:
@@ -22,7 +22,7 @@ import {_t} from "@web/core/l10n/translation";
2222
*
2323
* The `disabled_map` option maps selection values to boolean field names.
2424
* When the boolean field is falsy, the corresponding radio option is
25-
* rendered as disabled (grayed out, not clickable).
25+
* hidden from the user.
2626
*/
2727
export class FilterableRadioField extends RadioField {
2828
static template = "spp_base_common.FilterableRadioField";

spp_base_common/static/src/xml/filterable_radio_field.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
t-att-aria-label="props.label"
99
>
1010
<t t-foreach="items" t-as="item" t-key="item[0]">
11-
<div class="form-check o_radio_item" aria-atomic="true">
11+
<div
12+
t-attf-class="form-check o_radio_item #{isItemDisabled(item[0]) ? 'd-none' : ''}"
13+
aria-atomic="true"
14+
>
1215
<input
1316
type="radio"
1417
class="form-check-input o_radio_input"

spp_change_request_v2/details/update_id.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class SPPCRDetailUpdateID(models.Model):
5555
help="Upload scanned copies or photos of the ID document",
5656
)
5757
remarks = fields.Text(string="Remarks", tracking=True)
58+
is_operation_locked = fields.Boolean(
59+
string="Operation Locked",
60+
default=False,
61+
help="Set to True when user proceeds to Documents or Review stage, locking the operation selection.",
62+
)
63+
operation_display = fields.Char(
64+
string="Operation",
65+
compute="_compute_operation_display",
66+
)
5867

5968
# ══════════════════════════════════════════════════════════════════════════
6069
# COMPUTED FIELDS
@@ -84,6 +93,22 @@ class SPPCRDetailUpdateID(models.Model):
8493
readonly=True,
8594
)
8695

96+
@api.depends("operation")
97+
def _compute_operation_display(self):
98+
labels = dict(self._fields["operation"].selection)
99+
for rec in self:
100+
rec.operation_display = labels.get(rec.operation, "")
101+
102+
def action_next_documents(self):
103+
"""Lock operation before proceeding to documents stage."""
104+
self.write({"is_operation_locked": True})
105+
return super().action_next_documents()
106+
107+
def action_skip_to_review(self):
108+
"""Lock operation before proceeding to review stage."""
109+
self.write({"is_operation_locked": True})
110+
return super().action_skip_to_review()
111+
87112
@api.constrains("operation")
88113
def _check_operation_allowed(self):
89114
"""Validate that the chosen operation is allowed by the CR type config."""
@@ -122,6 +147,9 @@ def _onchange_operation(self):
122147
"message": _("Remove ID is disabled for this change request type."),
123148
}
124149

150+
# Unlock operation when changed (user came back to edit)
151+
self.is_operation_locked = False
152+
125153
if self.operation == "add":
126154
self.existing_id_record_id = False
127155
self.id_type_id = False

spp_change_request_v2/views/detail_update_id_views.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,18 @@
6060
<field name="allow_id_edit" invisible="1" />
6161
<field name="allow_id_remove" invisible="1" />
6262
<field name="approval_state" invisible="1" />
63+
<field name="is_operation_locked" invisible="1" />
6364
<field
6465
name="operation"
6566
widget="filterable_radio"
6667
options="{'disabled_map': {'update': 'allow_id_edit', 'remove': 'allow_id_remove'}}"
6768
readonly="not is_cr_manager or approval_state not in ('draft', 'revision')"
69+
invisible="is_operation_locked"
70+
/>
71+
<field
72+
name="operation_display"
73+
readonly="1"
74+
invisible="not is_operation_locked"
6875
/>
6976
</group>
7077
</group>

0 commit comments

Comments
 (0)