51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

继承一个小部件在js odoo 16中

英文:

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>&lt;details&gt; &lt;summary&gt;英文:&lt;/summary&gt;

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(&amp;#39;customized_m2o_widget.Fields&amp;#39;, function (require) { &amp;quot;use strict&amp;quot;;

var relational_fields = require(&amp;#39;web.relational_fields&amp;#39;); var FieldMany2One = relational_fields.FieldMany2One;

FieldMany2One.include({ _search: async function (searchValue = &amp;quot;&amp;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 &amp;gt;= values.length || this.limit &amp;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

&lt;/details&gt;

答案1

得分: 1

尝试对[many2one_field][0]小部件进行补丁,并将搜索限制设置为-1

示例:

/** @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, }; } }); &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;将以下条目添加到清单文件中:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;'assets': { 'web.assets_backend': [ 'MODULE_NAME/static/src/js/many2one_search_more.js', ], }, &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;更新&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;继承&lt;code&gt;relational_utils&lt;/code&gt;以覆盖&lt;code&gt;loadOptionsSource&lt;/code&gt;函数&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;示例:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;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;
}

}); &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;英文:&lt;/p&gt; &lt;p&gt;Try to patch the &lt;a href=&quot;https://github.com/odoo/odoo/blob/16.0/addons/web/static/src/views/fields/many2one/many2one_field.js#L142&quot;&gt;many2one_field&lt;/a&gt; widget and set the search limit to &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;/** @odoo-module **/

import {patch} from &amp;amp;quot;@web/core/utils/patch&amp;amp;quot;; import {Many2OneField} from &amp;amp;quot;@web/views/fields/many2one/many2one_field&amp;amp;quot;;

patch(Many2OneField.prototype, &amp;amp;quot;Many2OneField.SearchMore&amp;amp;quot;, { get Many2XAutocompleteProps() { return { ...this._super(...arguments), searchLimit: -1, }; } }); &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Add the following entry to the manifest file:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;&amp;amp;#39;assets&amp;amp;#39;: { &amp;amp;#39;web.assets_backend&amp;amp;#39;: [ &amp;amp;#39;MODULE_NAME/static/src/js/many2one_search_more.js&amp;amp;#39;, ], }, &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;Inherit &lt;code&gt;relational_utils&lt;/code&gt; to override &lt;code&gt;loadOptionsSource&lt;/code&gt; function&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;import {patch} from &amp;amp;quot;@web/core/utils/patch&amp;amp;quot;; import { Many2XAutocomplete } from &amp;amp;quot;@web/views/fields/relational_utils&amp;amp;quot;

patch(Many2XAutocomplete.prototype, &amp;amp;quot;Many2XAutocomplete.SearchLimit&amp;amp;quot;, {

async loadOptionsSource(request) {
    var options = this._super(request);
    return options;
}

}); &lt;/code&gt;&lt;/pre&gt; &lt;br /&gt; </code></pre>

赞(3)
未经允许不得转载:工具盒子 » 继承一个小部件在js odoo 16中