Skip to content

Commit 876cb31

Browse files
committed
[MIG] web_m2x_options: Migration to 19.0
1 parent 36a39b5 commit 876cb31

File tree

6 files changed

+106
-140
lines changed

6 files changed

+106
-140
lines changed

web_m2x_options/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ web_m2x_options
2121
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2222
:alt: License: AGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
24-
:target: https://github.com/OCA/web/tree/18.0/web_m2x_options
24+
:target: https://github.com/OCA/web/tree/19.0/web_m2x_options
2525
:alt: OCA/web
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_m2x_options
27+
:target: https://translation.odoo-community.org/projects/web-19-0/web-19-0-web_m2x_options
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -146,7 +146,7 @@ Bug Tracker
146146
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
147147
In case of trouble, please check there if your issue has already been reported.
148148
If you spotted it first, help us to smash it by providing a detailed and welcomed
149-
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
149+
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
150150

151151
Do not contact contributors directly about support or help with technical issues.
152152

@@ -220,6 +220,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
220220
mission is to support the collaborative development of Odoo features and
221221
promote its widespread use.
222222

223-
This module is part of the `OCA/web <https://github.com/OCA/web/tree/18.0/web_m2x_options>`_ project on GitHub.
223+
This module is part of the `OCA/web <https://github.com/OCA/web/tree/19.0/web_m2x_options>`_ project on GitHub.
224224

225225
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

web_m2x_options/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{
88
"name": "web_m2x_options",
9-
"version": "18.0.1.0.1",
9+
"version": "19.0.1.0.0",
1010
"category": "Web",
1111
"author": "initOS GmbH,"
1212
"ACSONE SA/NV, "

web_m2x_options/static/description/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>web_m2x_options</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:881a75e6602b8037ae91fff6ff77e99caff9cba4b1ccda3dff174f64f4e42824
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/18.0/web_m2x_options"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_m2x_options"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/19.0/web_m2x_options"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-19-0/web-19-0-web_m2x_options"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This modules modifies “many2one” and “many2manytags” form widgets so as
379379
to add some new display control options.</p>
380380
<p>Options provided includes possibility to remove “Create…” and/or
@@ -488,7 +488,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Bug Tracker</a></h2>
488488
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
489489
In case of trouble, please check there if your issue has already been reported.
490490
If you spotted it first, help us to smash it by providing a detailed and welcomed
491-
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
491+
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_m2x_options%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
492492
<p>Do not contact contributors directly about support or help with technical issues.</p>
493493
</div>
494494
<div class="section" id="credits">
@@ -549,7 +549,7 @@ <h3><a class="toc-backref" href="#toc-entry-11">Maintainers</a></h3>
549549
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
550550
mission is to support the collaborative development of Odoo features and
551551
promote its widespread use.</p>
552-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/18.0/web_m2x_options">OCA/web</a> project on GitHub.</p>
552+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/19.0/web_m2x_options">OCA/web</a> project on GitHub.</p>
553553
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
554554
</div>
555555
</div>

web_m2x_options/static/src/components/base.xml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
t-inherit="web.AutoComplete"
99
t-inherit-mode="extension"
1010
>
11-
<xpath expr="//t[@t-foreach='source.options']/li/a" position="attributes">
11+
<xpath expr="//t[@t-foreach='source.options']/li/t" position="attributes">
1212
<attribute name="t-attf-style">{{ option.style }}</attribute>
1313
</xpath>
1414
</t>
@@ -25,14 +25,4 @@
2525
</xpath>
2626
</t>
2727

28-
<t
29-
t-name="web_m2x_options.Many2ManyTagsAvatarFieldPopover"
30-
t-inherit="web.Many2ManyTagsAvatarField"
31-
t-inherit-mode="extension"
32-
>
33-
<Many2XAutocomplete position="attributes">
34-
<attribute name="noSearchMore">props.noSearchMore</attribute>
35-
</Many2XAutocomplete>
36-
</t>
37-
3828
</templates>

web_m2x_options/static/src/components/form.esm.js

Lines changed: 96 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import {
2-
AvatarMany2XAutocomplete,
3-
Many2XAutocomplete,
4-
} from "@web/views/fields/relational_utils";
5-
import {Many2OneField, many2OneField} from "@web/views/fields/many2one/many2one_field";
6-
import {Many2OneReferenceField} from "@web/views/fields/many2one_reference/many2one_reference_field";
1+
import * as many2OneField from "@web/views/fields/many2one/many2one_field";
72
import {FormController} from "@web/views/form/form_controller";
3+
import {Many2One} from "@web/views/fields/many2one/many2one";
4+
import {Many2OneReferenceField} from "@web/views/fields/many2one_reference/many2one_reference_field";
5+
import {Many2XAutocomplete} from "@web/views/fields/relational_utils";
86
import {evaluateBooleanExpr} from "@web/core/py_js/py";
97
import {fieldColorProps} from "../views/fields/standard_field_props.esm";
108
import {isX2Many} from "@web/views/utils";
@@ -13,10 +11,6 @@ import {patch} from "@web/core/utils/patch";
1311
import {registry} from "@web/core/registry";
1412
import {session} from "@web/session";
1513

16-
AvatarMany2XAutocomplete.props = {
17-
...AvatarMany2XAutocomplete.props,
18-
...fieldColorProps,
19-
};
2014
Many2XAutocomplete.props = {
2115
...Many2XAutocomplete.props,
2216
...fieldColorProps,
@@ -26,96 +20,88 @@ function evaluateSystemParameterDefaultTrue(option) {
2620
const isOptionSet = session.web_m2x_options[`web_m2x_options.${option}`];
2721
return isOptionSet ? evaluateBooleanExpr(isOptionSet) : true;
2822
}
23+
function evaluateSystemParameterNumber(option) {
24+
const isOptionSet = session.web_m2x_options[`web_m2x_options.${option}`];
25+
return isOptionSet ? Number(isOptionSet) : false;
26+
}
2927

30-
patch(many2OneField, {
31-
m2o_options_props_create(props, attrs, options) {
32-
const canQuickCreate = evaluateSystemParameterDefaultTrue("create");
33-
if (options.no_quick_create) {
34-
props.canQuickCreate = false;
35-
} else if ("no_quick_create" in options) {
36-
props.canQuickCreate = attrs.can_create
37-
? evaluateBooleanExpr(attrs.can_create)
38-
: true;
39-
} else if (!canQuickCreate && props.canQuickCreate) {
40-
props.canQuickCreate = false;
41-
} else if (canQuickCreate && !props.canQuickCreate) {
42-
props.canQuickCreate = attrs.can_create
43-
? evaluateBooleanExpr(attrs.can_create)
44-
: true;
45-
}
46-
return props;
47-
},
28+
export function m2o_options_props_create(props, attrs, options) {
29+
const canQuickCreate = evaluateSystemParameterDefaultTrue("create");
30+
if (options.no_quick_create) {
31+
props.canQuickCreate = false;
32+
} else if ("no_quick_create" in options) {
33+
props.canQuickCreate = attrs.can_create
34+
? evaluateBooleanExpr(attrs.can_create)
35+
: true;
36+
} else if (!canQuickCreate && props.canQuickCreate) {
37+
props.canQuickCreate = false;
38+
} else if (canQuickCreate && !props.canQuickCreate) {
39+
props.canQuickCreate = attrs.can_create
40+
? evaluateBooleanExpr(attrs.can_create)
41+
: true;
42+
}
43+
return props;
44+
}
4845

49-
m2o_options_props_create_edit(props, attrs, options) {
50-
const canCreateEdit = evaluateSystemParameterDefaultTrue("create_edit");
51-
if (options.no_create_edit) {
52-
props.canCreateEdit = false;
53-
} else if ("no_create_edit" in options) {
54-
// Same condition set in web/views/fields/many2one/many2one_field
55-
props.canCreateEdit = attrs.can_create
56-
? evaluateBooleanExpr(attrs.can_create)
57-
: true;
58-
} else if (!canCreateEdit && props.canCreateEdit) {
59-
props.canCreateEdit = false;
60-
} else if (canCreateEdit && !props.canCreateEdit) {
61-
// Same condition set in web/views/fields/many2one/many2one_field
62-
props.canCreateEdit = attrs.can_create
63-
? evaluateBooleanExpr(attrs.can_create)
64-
: true;
65-
}
66-
return props;
67-
},
46+
export function m2o_options_props_create_edit(props, attrs, options) {
47+
const canCreateEdit = evaluateSystemParameterDefaultTrue("create_edit");
48+
if (options.no_create_edit) {
49+
props.canCreateEdit = false;
50+
} else if ("no_create_edit" in options) {
51+
// Same condition set in web/views/fields/many2one/many2one_field
52+
props.canCreateEdit = attrs.can_create
53+
? evaluateBooleanExpr(attrs.can_create)
54+
: true;
55+
} else if (!canCreateEdit && props.canCreateEdit) {
56+
props.canCreateEdit = false;
57+
} else if (canCreateEdit && !props.canCreateEdit) {
58+
// Same condition set in web/views/fields/many2one/many2one_field
59+
props.canCreateEdit = attrs.can_create
60+
? evaluateBooleanExpr(attrs.can_create)
61+
: true;
62+
}
63+
return props;
64+
}
6865

69-
m2o_options_props_limit(props, attrs, options) {
70-
const ir_options = session.web_m2x_options;
71-
if (Number(options.limit)) {
72-
props.searchLimit = Number(options.limit);
73-
} else if (Number(ir_options["web_m2x_options.limit"])) {
74-
props.searchLimit = Number(ir_options["web_m2x_options.limit"]);
75-
}
76-
return props;
77-
},
66+
export function m2o_options_props_limit(props, attrs, options) {
67+
const ir_options = session.web_m2x_options;
68+
if (Number(options.limit)) {
69+
props.searchLimit = Number(options.limit);
70+
} else if (Number(ir_options["web_m2x_options.limit"])) {
71+
props.searchLimit = Number(ir_options["web_m2x_options.limit"]);
72+
}
73+
return props;
74+
}
7875

79-
m2o_options_props_search_more(props, attrs, options) {
80-
const noSearchMore = !evaluateSystemParameterDefaultTrue("search_more");
81-
if (options.search_more) {
82-
props.noSearchMore = false;
83-
} else if ("search_more" in options) {
84-
props.noSearchMore = true;
85-
} else if (!noSearchMore && props.noSearchMore) {
86-
props.noSearchMore = false;
87-
} else if (noSearchMore) {
88-
props.noSearchMore = true;
89-
}
90-
return props;
91-
},
76+
export function m2o_options_props_open(props, attrs, options) {
77+
if (!("no_open" in options)) {
78+
props.canOpen = evaluateSystemParameterDefaultTrue("open");
79+
}
80+
return props;
81+
}
9282

93-
m2o_options_props_open(props, attrs, options) {
94-
if (!("no_open" in options)) {
95-
props.canOpen = evaluateSystemParameterDefaultTrue("open");
96-
}
97-
return props;
98-
},
83+
export function m2o_options_props(props, attrs, options) {
84+
let newProps = props;
85+
newProps = m2o_options_props_create(newProps, attrs, options);
86+
newProps = m2o_options_props_create_edit(newProps, attrs, options);
87+
newProps = m2o_options_props_limit(newProps, attrs, options);
88+
newProps = m2o_options_props_open(newProps, attrs, options);
89+
newProps.fieldColor = options.field_color;
90+
newProps.fieldColorOptions = options.colors;
91+
return newProps;
92+
}
9993

100-
m2o_options_props(props, attrs, options) {
101-
let newProps = props;
102-
newProps = this.m2o_options_props_create(newProps, attrs, options);
103-
newProps = this.m2o_options_props_create_edit(newProps, attrs, options);
104-
newProps = this.m2o_options_props_limit(newProps, attrs, options);
105-
newProps = this.m2o_options_props_search_more(newProps, attrs, options);
106-
newProps = this.m2o_options_props_open(newProps, attrs, options);
107-
newProps.fieldColor = options.field_color;
108-
newProps.fieldColorOptions = options.colors;
109-
return newProps;
110-
},
111-
extractProps({attrs, context, decorations, options, string}, dynamicInfo) {
112-
const props = super.extractProps(
113-
{attrs, context, decorations, options, string},
114-
dynamicInfo
115-
);
116-
return this.m2o_options_props(props, attrs, options);
117-
},
118-
});
94+
const oldBuildM2OFieldDescription = many2OneField.buildM2OFieldDescription;
95+
many2OneField.buildM2OFieldDescription = (component) => {
96+
const _super = oldBuildM2OFieldDescription(component);
97+
return {
98+
..._super,
99+
extractProps(staticInfo, dynamicInfo) {
100+
const props = many2OneField.extractM2OFieldProps(staticInfo, dynamicInfo);
101+
return m2o_options_props(props, staticInfo.attrs, staticInfo.options);
102+
},
103+
};
104+
};
119105

120106
// FIXME: Many2OneReferenceField does not support m2o_options_props.
121107
// This no-op prevents crashes, but proper option support is still missing.
@@ -127,20 +113,16 @@ patch(Many2OneReferenceField, {
127113
},
128114
});
129115

130-
patch(Many2OneField.prototype, {
131-
get Many2XAutocompleteProps() {
132-
const search_limit = this.props.searchLimit;
133-
const no_search_more = this.props.noSearchMore;
116+
patch(Many2One.prototype, {
117+
get many2XAutocompleteProps() {
118+
const search_limit = evaluateSystemParameterNumber("limit");
134119
const field_color = this.props.fieldColor;
135120
const field_color_options = this.props.fieldColorOptions;
136-
const props = super.Many2XAutocompleteProps;
121+
const props = super.many2XAutocompleteProps;
137122
const ret_props = {...props};
138123
if (Number(search_limit) && Number(search_limit) > 1) {
139124
ret_props.searchLimit = search_limit - 1;
140125
}
141-
if (no_search_more) {
142-
ret_props.noSearchMore = no_search_more;
143-
}
144126
if (field_color && field_color_options) {
145127
ret_props.fieldColor = field_color;
146128
ret_props.fieldColorOptions = field_color_options;
@@ -198,26 +180,11 @@ patch(many2ManyTagsField, {
198180
return props;
199181
},
200182

201-
m2m_options_props_search_more(props, attrs, options) {
202-
const noSearchMore = !evaluateSystemParameterDefaultTrue("search_more");
203-
if (options.search_more) {
204-
props.noSearchMore = false;
205-
} else if ("search_more" in options) {
206-
props.noSearchMore = true;
207-
} else if (!noSearchMore && props.noSearchMore) {
208-
props.noSearchMore = false;
209-
} else if (noSearchMore) {
210-
props.noSearchMore = true;
211-
}
212-
return props;
213-
},
214-
215183
m2m_options_props(props, attrs, options) {
216184
let newProps = props;
217185
newProps = this.m2m_options_props_create(newProps, attrs, options);
218186
newProps = this.m2m_options_props_create_edit(newProps, attrs, options);
219187
newProps = this.m2m_options_props_limit(newProps, attrs, options);
220-
newProps = this.m2m_options_props_search_more(newProps, attrs, options);
221188
newProps.fieldColor = options.field_color;
222189
newProps.fieldColorOptions = options.colors;
223190
return newProps;
@@ -317,12 +284,22 @@ patch(registry.category("fields").validationSchema, {
317284
m2o_options_props_create: {type: Function, optional: true},
318285
m2o_options_props_create_edit: {type: Function, optional: true},
319286
m2o_options_props_limit: {type: Function, optional: true},
320-
m2o_options_props_search_more: {type: Function, optional: true},
321287
m2o_options_props_open: {type: Function, optional: true},
322288
m2o_options_props: {type: Function, optional: true},
323289
m2m_options_props_create: {type: Function, optional: true},
324290
m2m_options_props_create_edit: {type: Function, optional: true},
325291
m2m_options_props_limit: {type: Function, optional: true},
326-
m2m_options_props_search_more: {type: Function, optional: true},
327292
m2m_options_props: {type: Function, optional: true},
328293
});
294+
295+
registry.category("fields").add(
296+
"many2one",
297+
{
298+
...many2OneField.buildM2OFieldDescription(many2OneField.Many2OneField),
299+
extractProps(staticInfo, dynamicInfo) {
300+
const props = many2OneField.extractM2OFieldProps(staticInfo, dynamicInfo);
301+
return m2o_options_props(props, staticInfo.attrs, staticInfo.options);
302+
},
303+
},
304+
{force: true}
305+
);

web_m2x_options/static/src/views/fields/standard_field_props.esm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ export const fieldColorProps = {
88

99
patch(standardFieldProps, {
1010
...fieldColorProps,
11-
noSearchMore: {type: Boolean, optional: true},
1211
searchLimit: {type: Number, optional: true},
1312
});

0 commit comments

Comments
 (0)