英文:
Inherit a widget in js odoo 16
问题 {#heading}
在odoo 14中,我通过以下代码实现了对搜索选项的修改:
odoo.define('customized_m2o_widget.Fields', function (require) {
"use strict";
var relational_fields = require('web.relational_fields');
var FieldMany2One = relational_fields.FieldMany2One;
FieldMany2One.include({
_search: async function (searchValue = "") {
const value = searchValue.trim();
const domain = this.record.getDomain(this.recordParams);
const context = Object.assign(
this.record.getContext(this.recordParams),
this.additionalContext
);
var values = await this._super.apply(this, arguments);
if (this.limit >= values.length || this.limit < values.length) {
values = this._manageSearchMore(values, value, domain, context);
}
return values;
},
})
});
</code></pre>
<p>现在我需要迁移到odoo 16,有没有办法以正确的语法和语义代码来实现它,让它再次正常工作?谢谢提前</p>
<pre><code><details>
<summary>英文:</summary>
There is an edit that I made on the search more option, I need it to be shown all the time,
in odoo 14, i made it by this code :
</code></pre>
<br />
<pre><code>odoo.define(&#39;customized_m2o_widget.Fields&#39;, function (require) {
&quot;use strict&quot;;
var relational_fields = require(&#39;web.relational_fields&#39;);
var FieldMany2One = relational_fields.FieldMany2One;
FieldMany2One.include({
_search: async function (searchValue = &quot;&quot;) {
const value = searchValue.trim();
const domain = this.record.getDomain(this.recordParams);
const context = Object.assign(
this.record.getContext(this.recordParams),
this.additionalContext
);
var values = await this._super.apply(this, arguments);
if (this.limit &gt;= values.length || this.limit &lt; values.length) {
values = this._manageSearchMore(values, value, domain, context);
}
return values;
},
})
});
now I need to migrate to odoo 16, so anyone have a way to do it in the write syntax and semantic code to let it works again?
thanks in advance
</details>
答案1
得分: 1
尝试对[many2one_field][0]小部件进行补丁,并将搜索限制设置为-1
示例:
/** @odoo-module **/
import {patch} from &quot;@web/core/utils/patch&quot;;
import {Many2OneField} from &quot;@web/views/fields/many2one/many2one_field&quot;;
patch(Many2OneField.prototype, &quot;Many2OneField.SearchMore&quot;, {
get Many2XAutocompleteProps() {
return {
...this._super(...arguments),
searchLimit: -1,
};
}
});
</code></pre>
<p>将以下条目添加到清单文件中:</p>
<pre><code>'assets': {
'web.assets_backend': [
'MODULE_NAME/static/src/js/many2one_search_more.js',
],
},
</code></pre>
<p><em><strong>更新</strong></em></p>
<p>继承<code>relational_utils</code>以覆盖<code>loadOptionsSource</code>函数</p>
<p><em><strong>示例:</strong></em></p>
<pre><code>import {patch} from &quot;@web/core/utils/patch&quot;;
import { Many2XAutocomplete } from &quot;@web/views/fields/relational_utils&quot;;
patch(Many2XAutocomplete.prototype, &quot;Many2XAutocomplete.SearchLimit&quot;, {
async loadOptionsSource(request) {
var options = this._super(request);
return options;
}
});
</code></pre>
<p>英文:</p>
<p>Try to patch the <a href="https://github.com/odoo/odoo/blob/16.0/addons/web/static/src/views/fields/many2one/many2one_field.js#L142">many2one_field</a> widget and set the search limit to <code>-1</code></p>
<p><em><strong>Example:</strong></em></p>
<pre><code>/** @odoo-module **/
import {patch} from &amp;quot;@web/core/utils/patch&amp;quot;;
import {Many2OneField} from &amp;quot;@web/views/fields/many2one/many2one_field&amp;quot;;
patch(Many2OneField.prototype, &amp;quot;Many2OneField.SearchMore&amp;quot;, {
get Many2XAutocompleteProps() {
return {
...this._super(...arguments),
searchLimit: -1,
};
}
});
</code></pre>
<p>Add the following entry to the manifest file:</p>
<pre><code>&amp;#39;assets&amp;#39;: {
&amp;#39;web.assets_backend&amp;#39;: [
&amp;#39;MODULE_NAME/static/src/js/many2one_search_more.js&amp;#39;,
],
},
</code></pre>
<p><em><strong>Update</strong></em></p>
<p>Inherit <code>relational_utils</code> to override <code>loadOptionsSource</code> function</p>
<p><em><strong>Example:</strong></em></p>
<pre><code>import {patch} from &amp;quot;@web/core/utils/patch&amp;quot;;
import { Many2XAutocomplete } from &amp;quot;@web/views/fields/relational_utils&amp;quot;
patch(Many2XAutocomplete.prototype, &amp;quot;Many2XAutocomplete.SearchLimit&amp;quot;, {
async loadOptionsSource(request) {
var options = this._super(request);
return options;
}
});
</code></pre>
<br />
</code></pre>