-
Notifications
You must be signed in to change notification settings - Fork 1
feat(spp_change_request_v2): improve Update ID Document CR type #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** @odoo-module **/ | ||
|
|
||
| import {RadioField, radioField} from "@web/views/fields/radio/radio_field"; | ||
| import {registry} from "@web/core/registry"; | ||
| import {_t} from "@web/core/l10n/translation"; | ||
|
|
||
| /** | ||
| * A radio widget that supports disabling individual options based on | ||
| * boolean fields on the record. | ||
| * | ||
| * Usage in XML views: | ||
| * <field | ||
| * name="operation" | ||
| * widget="filterable_radio" | ||
| * options="{ | ||
| * 'disabled_map': { | ||
| * 'update': 'allow_id_edit', | ||
| * 'remove': 'allow_id_remove' | ||
| * } | ||
| * }" | ||
| * /> | ||
| * | ||
| * The `disabled_map` option maps selection values to boolean field names. | ||
| * When the boolean field is falsy, the corresponding radio option is | ||
| * rendered as disabled (grayed out, not clickable). | ||
| */ | ||
| export class FilterableRadioField extends RadioField { | ||
| static template = "spp_base_common.FilterableRadioField"; | ||
| static props = { | ||
| ...RadioField.props, | ||
| disabledMap: {type: Object, optional: true}, | ||
| }; | ||
| static defaultProps = { | ||
| ...RadioField.defaultProps, | ||
| disabledMap: {}, | ||
| }; | ||
|
|
||
| /** | ||
| * Check whether a given selection value should be disabled. | ||
| * @param {any} value - The selection key to check | ||
| * @returns {Boolean} | ||
| */ | ||
| isItemDisabled(value) { | ||
| if (this.props.readonly) { | ||
| return true; | ||
| } | ||
| const map = this.props.disabledMap; | ||
| if (!map || !(value in map)) { | ||
| return false; | ||
| } | ||
| const boolField = map[value]; | ||
| return !this.props.record.data[boolField]; | ||
| } | ||
| } | ||
|
|
||
| export const filterableRadioField = { | ||
| ...radioField, | ||
| component: FilterableRadioField, | ||
| displayName: _t("Filterable Radio"), | ||
| supportedOptions: [ | ||
| ...radioField.supportedOptions, | ||
| { | ||
| label: _t("Disabled map (value → boolean field)"), | ||
| name: "disabled_map", | ||
| type: "object", | ||
| }, | ||
| ], | ||
| extractProps: (fieldInfo, dynamicInfo) => { | ||
| const baseProps = radioField.extractProps(fieldInfo, dynamicInfo); | ||
| return { | ||
| ...baseProps, | ||
| disabledMap: fieldInfo.options.disabled_map || {}, | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| registry.category("fields").add("filterable_radio", filterableRadioField); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <templates xml:space="preserve"> | ||
|
|
||
| <t t-name="spp_base_common.FilterableRadioField"> | ||
| <div | ||
| role="radiogroup" | ||
| t-attf-class="o_{{ props.orientation }}" | ||
| t-att-aria-label="props.label" | ||
| > | ||
| <t t-foreach="items" t-as="item" t-key="item[0]"> | ||
| <div class="form-check o_radio_item" aria-atomic="true"> | ||
| <input | ||
| type="radio" | ||
| class="form-check-input o_radio_input" | ||
| t-att-checked="item[0] === value" | ||
| t-att-disabled="isItemDisabled(item[0])" | ||
| t-att-name="id" | ||
| t-att-data-value="item[0]" | ||
| t-att-data-index="item_index" | ||
| t-att-id="`${id}_${item[0]}`" | ||
| t-on-change="() => this.onChange(item)" | ||
| /> | ||
| <label | ||
| t-att-for="`${id}_${item[0]}`" | ||
| t-attf-class="form-check-label o_form_label #{isItemDisabled(item[0]) ? 'text-muted' : ''}" | ||
| t-esc="item[1]" | ||
| /> | ||
| </div> | ||
| </t> | ||
| </div> | ||
| </t> | ||
|
|
||
| </templates> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1147,17 +1147,21 @@ def _generate_review_comparison_html(self): | |
| ) | ||
|
|
||
| action = changes.pop("_action", None) | ||
| header = changes.pop("_header", None) | ||
|
|
||
| # Determine if this is a field-mapping type (has old/new dicts) | ||
| has_comparison = any(isinstance(v, dict) and "old" in v and "new" in v for v in changes.values()) | ||
|
|
||
| if has_comparison: | ||
| return self._render_comparison_table(changes) | ||
| return self._render_action_summary(action, changes) | ||
| return self._render_comparison_table(changes, header=header) | ||
| return self._render_action_summary(action, changes, header=header) | ||
|
Comment on lines
+1158
to
+1159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The functions I recommend updating # In _format_review_value method:
from odoo.tools import html_escape
# ... at the end of the function, instead of just str(value):
return html_escape(str(value))
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 9d94eef — added |
||
|
|
||
| def _render_comparison_table(self, changes): | ||
| def _render_comparison_table(self, changes, header=None): | ||
| """Render a three-column comparison table for field-mapping CR types.""" | ||
| html = ['<table class="table table-sm table-bordered mb-0" style="width:100%">'] | ||
| html = [] | ||
| if header: | ||
| html.append(f"<h4>{header}</h4>") | ||
| html.append('<table class="table table-sm table-bordered mb-0" style="width:100%">') | ||
| html.append( | ||
| "<thead><tr>" | ||
| '<th class="bg-light"></th>' | ||
|
|
@@ -1170,7 +1174,8 @@ def _render_comparison_table(self, changes): | |
| for key, value in changes.items(): | ||
| if key.startswith("_"): | ||
| continue | ||
| display_key = key.replace("_", " ").title() | ||
| # Use key as-is if it contains spaces (human-readable), otherwise convert | ||
| display_key = key if " " in key else key.replace("_", " ").title() | ||
|
|
||
| if isinstance(value, dict) and "old" in value: | ||
| old_val = value.get("old") | ||
|
|
@@ -1203,10 +1208,13 @@ def _render_comparison_table(self, changes): | |
| html.append("</tbody></table>") | ||
| return "".join(html) | ||
|
|
||
| def _render_action_summary(self, action, changes): | ||
| def _render_action_summary(self, action, changes, header=None): | ||
| """Render a summary table for action-based CR types.""" | ||
| html = [] | ||
|
|
||
| if header: | ||
| html.append(f"<h4>{header}</h4>") | ||
|
|
||
| if not changes: | ||
| html.append('<p class="text-muted mb-0"><i class="fa fa-info-circle me-2"></i>No details to display.</p>') | ||
| return "".join(html) | ||
|
|
@@ -1218,7 +1226,7 @@ def _render_action_summary(self, action, changes): | |
| for key, value in changes.items(): | ||
| if key.startswith("_"): | ||
| continue | ||
| display_key = key.replace("_", " ").title() | ||
| display_key = key if " " in key else key.replace("_", " ").title() | ||
| display_value = self._format_review_value(value) | ||
| html.append(f'<tr><td class="bg-light"><strong>{display_key}</strong></td><td>{display_value}</td></tr>') | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some code duplication in how fields are cleared for different operations. The fields
id_type_id,id_value, andexpiry_dateare reset in both theifandelifblocks. You can simplify this by clearing these fields once before the conditional logic to improve readability and maintainability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 9d94eef — deduplicated the field clearing.