From 65af83d508e8ebb6f337bdd53180f33a688dea7f Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Thu, 6 Feb 2025 09:36:47 -0500 Subject: [PATCH] [FIX] web_widget_product_label_section_and_note: Use a flag to change the icon based on product visibility. Before this commit, when isProductVisible was disabled and the user changed the label, this caused isProductVisible to change its value. After this commit, changing the label no longer modifies isProductVisible. --- .../product_label_section_and_note_field.esm.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.esm.js b/web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.esm.js index 3eb56929e..4d2bdc032 100644 --- a/web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.esm.js +++ b/web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.esm.js @@ -154,6 +154,7 @@ export class ProductLabelSectionAndNoteField extends Many2OneField { this.labelVisibility = useState({value: false}); this.isProductVisible = useState({value: false}); this.switchToLabel = false; + this.changeProductVisibility = true; this.columnIsProductAndLabel = useState({ value: this.props.record.columnIsProductAndLabel, }); @@ -203,8 +204,10 @@ export class ProductLabelSectionAndNoteField extends Many2OneField { window.removeEventListener("afterprint", this.onAfterPrint); }); useRecordObserver(async (record) => { - const label = record.data.name || ""; - this.isProductVisible.value = label.includes(this.productName); + if (this.changeProductVisibility) { + const label = record.data.name || ""; + this.isProductVisible.value = label.includes(this.productName); + } }); } @@ -276,9 +279,12 @@ export class ProductLabelSectionAndNoteField extends Many2OneField { } updateLabel(value) { + this.changeProductVisibility = false; this.props.record.update({ name: - this.productName && this.productName !== value + this.productName && + this.productName !== value && + this.isProductVisible.value ? `${this.productName}\n${value}` : value, });