@@ -7,17 +7,20 @@ import {
77 onMounted ,
88 onPatched ,
99 onWillUnmount ,
10- onWillUpdateProps ,
1110 useEffect ,
1211 useRef ,
1312 useState ,
1413} from "@odoo/owl" ;
1514import { AutoComplete } from "@web/core/autocomplete/autocomplete" ;
1615import { Many2OneField } from "@web/views/fields/many2one/many2one_field" ;
1716import { Many2XAutocomplete } from "@web/views/fields/relational_utils" ;
18- import { SectionAndNoteListRenderer } from "@account/components/section_and_note_fields_backend/section_and_note_fields_backend" ;
19- import { X2ManyField } from "@web/views/fields/x2many/x2many_field" ;
17+ import {
18+ SectionAndNoteListRenderer ,
19+ sectionAndNoteFieldOne2Many ,
20+ } from "@account/components/section_and_note_fields_backend/section_and_note_fields_backend" ;
21+ import { X2ManyField , x2ManyField } from "@web/views/fields/x2many/x2many_field" ;
2022import { _t } from "@web/core/l10n/translation" ;
23+ import { useRecordObserver } from "@web/model/relational_model/utils" ;
2124import { getActiveHotkey } from "@web/core/hotkeys/hotkey_service" ;
2225import { registry } from "@web/core/registry" ;
2326import { useProductAndLabelAutoresize } from "../../core/utils/product_and_label_autoresize.esm" ;
@@ -70,19 +73,23 @@ export class ProductLabelSectionAndNoteListRender extends SectionAndNoteListRend
7073 }
7174}
7275
73- export class ProductLabelSectionAndNoteOne2Many extends X2ManyField { }
74- ProductLabelSectionAndNoteOne2Many . components = {
75- ...X2ManyField . components ,
76- ListRenderer : ProductLabelSectionAndNoteListRender ,
77- } ;
78- ProductLabelSectionAndNoteOne2Many . additionalClasses =
79- SectionAndNoteListRenderer . additionalClasses ;
76+ export class ProductLabelSectionAndNoteOne2Many extends X2ManyField {
77+ static components = {
78+ ...X2ManyField . components ,
79+ ListRenderer : ProductLabelSectionAndNoteListRender ,
80+ } ;
81+ }
8082
83+ export const productLabelSectionAndNoteOne2Many = {
84+ ...x2ManyField ,
85+ component : ProductLabelSectionAndNoteOne2Many ,
86+ additionalClasses : sectionAndNoteFieldOne2Many . additionalClasses ,
87+ } ;
8188registry
8289 . category ( "fields" )
8390 . add (
8491 "product_label_section_and_note_field_o2m" ,
85- ProductLabelSectionAndNoteOne2Many
92+ productLabelSectionAndNoteOne2Many
8693 ) ;
8794
8895export class ProductLabelSectionAndNoteAutocomplete extends AutoComplete {
@@ -107,6 +114,19 @@ export class ProductLabelSectionAndNoteAutocomplete extends AutoComplete {
107114}
108115
109116export class ProductLabelSectionAndNoteFieldAutocomplete extends Many2XAutocomplete {
117+ static components = {
118+ ...Many2XAutocomplete . components ,
119+ AutoComplete : ProductLabelSectionAndNoteAutocomplete ,
120+ } ;
121+ static props = {
122+ ...Many2XAutocomplete . props ,
123+ isNote : { type : Boolean } ,
124+ isSection : { type : Boolean } ,
125+ onFocusout : { type : Function , optional : true } ,
126+ updateLabel : { type : Function , optional : true } ,
127+ } ;
128+ static template =
129+ "web_widget_product_label_section_and_note.ProductLabelSectionAndNoteFieldAutocomplete" ;
110130 setup ( ) {
111131 super . setup ( ) ;
112132 this . input = useRef ( "section_and_note_input" ) ;
@@ -121,14 +141,13 @@ export class ProductLabelSectionAndNoteFieldAutocomplete extends Many2XAutocompl
121141 }
122142}
123143
124- ProductLabelSectionAndNoteFieldAutocomplete . components = {
125- ...Many2XAutocomplete . components ,
126- AutoComplete : ProductLabelSectionAndNoteAutocomplete ,
127- } ;
128- ProductLabelSectionAndNoteFieldAutocomplete . template =
129- "web_widget_product_label_section_and_note.ProductLabelSectionAndNoteFieldAutocomplete" ;
130-
131144export class ProductLabelSectionAndNoteField extends Many2OneField {
145+ static components = {
146+ ...Many2OneField . components ,
147+ Many2XAutocomplete : ProductLabelSectionAndNoteFieldAutocomplete ,
148+ } ;
149+ static template =
150+ "web_widget_product_label_section_and_note.ProductLabelSectionAndNoteField" ;
132151 setup ( ) {
133152 super . setup ( ) ;
134153 this . isPrintMode = useState ( { value : false } ) ;
@@ -183,8 +202,8 @@ export class ProductLabelSectionAndNoteField extends Many2OneField {
183202 window . removeEventListener ( "beforeprint" , this . onBeforePrint ) ;
184203 window . removeEventListener ( "afterprint" , this . onAfterPrint ) ;
185204 } ) ;
186- onWillUpdateProps ( ( newProps ) => {
187- const label = newProps . record . data . name || "" ;
205+ useRecordObserver ( async ( record ) => {
206+ const label = record . data . name || "" ;
188207 this . isProductVisible . value = label . includes ( this . productName ) ;
189208 } ) ;
190209 }
@@ -266,13 +285,10 @@ export class ProductLabelSectionAndNoteField extends Many2OneField {
266285 }
267286}
268287
269- ProductLabelSectionAndNoteField . components = {
270- ...Many2OneField . components ,
271- Many2XAutocomplete : ProductLabelSectionAndNoteFieldAutocomplete ,
288+ export const productLabelSectionAndNoteField = {
289+ ...Many2OneField ,
290+ component : ProductLabelSectionAndNoteField ,
272291} ;
273- ProductLabelSectionAndNoteField . template =
274- "web_widget_product_label_section_and_note.ProductLabelSectionAndNoteField" ;
275-
276292registry
277293 . category ( "fields" )
278- . add ( "product_label_section_and_note_field" , ProductLabelSectionAndNoteField ) ;
294+ . add ( "product_label_section_and_note_field" , productLabelSectionAndNoteField ) ;
0 commit comments