Skip to content

Commit bc4f109

Browse files
[MIG] web_widget_product_label_section_and_note: Migration to version 17.0
1 parent 10bd32b commit bc4f109

File tree

4 files changed

+50
-65
lines changed

4 files changed

+50
-65
lines changed

web_widget_product_label_section_and_note/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Web widget product label section and note",
3-
"version": "16.0.1.0.1",
3+
"version": "17.0.1.0.0",
44
"summary": "unify the product and name into a single column",
55
"author": "Tecnativa, Odoo Community Association (OCA), Odoo S.A.",
66
"website": "https://github.com/OCA/web",

web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.esm.js

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import {
77
onMounted,
88
onPatched,
99
onWillUnmount,
10-
onWillUpdateProps,
1110
useEffect,
1211
useRef,
1312
useState,
1413
} from "@odoo/owl";
1514
import {AutoComplete} from "@web/core/autocomplete/autocomplete";
1615
import {Many2OneField} from "@web/views/fields/many2one/many2one_field";
1716
import {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";
2022
import {_t} from "@web/core/l10n/translation";
23+
import {useRecordObserver} from "@web/model/relational_model/utils";
2124
import {getActiveHotkey} from "@web/core/hotkeys/hotkey_service";
2225
import {registry} from "@web/core/registry";
2326
import {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+
};
8188
registry
8289
.category("fields")
8390
.add(
8491
"product_label_section_and_note_field_o2m",
85-
ProductLabelSectionAndNoteOne2Many
92+
productLabelSectionAndNoteOne2Many
8693
);
8794

8895
export class ProductLabelSectionAndNoteAutocomplete extends AutoComplete {
@@ -107,6 +114,19 @@ export class ProductLabelSectionAndNoteAutocomplete extends AutoComplete {
107114
}
108115

109116
export 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-
131144
export 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-
276292
registry
277293
.category("fields")
278-
.add("product_label_section_and_note_field", ProductLabelSectionAndNoteField);
294+
.add("product_label_section_and_note_field", productLabelSectionAndNoteField);

web_widget_product_label_section_and_note/static/src/components/product_label_section_and_note_field/product_label_section_and_note_field.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
<t
55
t-name="web_widget_product_label_section_and_note.ProductLabelSectionAndNoteField"
6-
owl="1"
76
>
87
<div class="o_field_product_label_section_and_note_cell">
98
<t t-if="props.readonly">
@@ -96,12 +95,12 @@
9695
<button
9796
t-if="hasExternalButton"
9897
aria-label="Internal link"
99-
class="btn btn-secondary fa o_external_button"
98+
class="btn btn-link text-action oi o_external_button"
10099
data-tooltip="Internal link"
101100
draggable="false"
102101
tabindex="-1"
103102
type="button"
104-
t-att-class="(props.openTarget === 'current' and !env.inDialog )? 'fa-arrow-right' : 'fa-external-link'"
103+
t-att-class="env.inDialog ? 'oi-launch' : 'oi-arrow-right'"
105104
t-on-click="onExternalBtnClick"
106105
/>
107106
<button
@@ -181,18 +180,18 @@
181180
t-name="web_widget_product_label_section_and_note.ProductLabelSectionAndNoteFieldAutocomplete"
182181
t-inherit="web.Many2XAutocomplete"
183182
t-inherit-mode="primary"
184-
owl="1"
185183
>
186184
<xpath expr="//AutoComplete[@t-else='']" position="replace">
187185
<t t-else="">
188186
<t t-if="!isSectionOrNote">
189187
<AutoComplete
188+
autofocus="props.autofocus"
190189
autoSelect="props.autoSelect"
190+
dropdown="props.dropdown"
191191
id="props.id"
192192
onChange.bind="onChange"
193193
onInput.bind="onInput"
194194
onSelect.bind="onSelect"
195-
onCancel.bind="onCancel"
196195
placeholder="props.placeholder"
197196
resetOnSelect="props.value === ''"
198197
sources="sources"
@@ -211,7 +210,7 @@
211210
</t>
212211
</t>
213212
</xpath>
214-
<xpath expr="//a[@class='o_dropdown_button']" position="attributes">
213+
<xpath expr="//span[hasclass('o_dropdown_button')]" position="attributes">
215214
<attribute name="t-if">!isSectionOrNote</attribute>
216215
</xpath>
217216
</t>

web_widget_product_label_section_and_note/static/src/core/utils/autoresize.esm.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import {useEffect} from "@odoo/owl";
77
import {browser} from "@web/core/browser/browser";
8+
import {resizeTextArea} from "@web/core/utils/autoresize";
89

910
function resizeInput(input) {
1011
// This mesures the maximum width of the input which can get from the flex layout.
@@ -25,37 +26,6 @@ function resizeInput(input) {
2526
input.style.width = input.scrollWidth + 5 + (isSafari16 ? 8 : 0) + "px";
2627
}
2728

28-
export function resizeTextArea(textarea, options = {}) {
29-
const minimumHeight = options.minimumHeight || 0;
30-
let heightOffset = 0;
31-
const style = window.getComputedStyle(textarea);
32-
if (style.boxSizing === "border-box") {
33-
const paddingHeight =
34-
parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
35-
const borderHeight =
36-
parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
37-
heightOffset = borderHeight + paddingHeight;
38-
}
39-
const previousStyle = {
40-
borderTopWidth: style.borderTopWidth,
41-
borderBottomWidth: style.borderBottomWidth,
42-
padding: style.padding,
43-
};
44-
Object.assign(textarea.style, {
45-
height: "auto",
46-
borderTopWidth: 0,
47-
borderBottomWidth: 0,
48-
paddingTop: 0,
49-
paddingRight: style.paddingRight,
50-
paddingBottom: 0,
51-
paddingLeft: style.paddingLeft,
52-
});
53-
textarea.style.height = "auto";
54-
const height = Math.max(minimumHeight, textarea.scrollHeight + heightOffset);
55-
Object.assign(textarea.style, previousStyle, {height: `${height}px`});
56-
textarea.parentElement.style.height = `${height}px`;
57-
}
58-
5929
/**
6030
* This is used on text inputs or textareas to automatically resize it based on its
6131
* content each time it is updated. It takes the reference of the element as

0 commit comments

Comments
 (0)