3
0
Fork 0

[MIG] web_m2x_options: Migration to 13.0

13.0
Jeroen Evens 2019-10-02 15:02:18 +02:00
parent d97392e20b
commit fbcad35c32
3 changed files with 149 additions and 137 deletions

View File

@ -5,7 +5,7 @@
{ {
"name": 'web_m2x_options', "name": 'web_m2x_options',
"version": "12.0.1.0.0", "version": "13.0.1.0.0",
'category': 'Web', 'category': 'Web',
"author": "ACSONE SA/NV, " "author": "ACSONE SA/NV, "
"0k.io, " "0k.io, "

View File

@ -4,8 +4,8 @@
* Nicolas JEUDY <nicolas@sudokeys.com> * Nicolas JEUDY <nicolas@sudokeys.com>
* Yannick Vaucher <yannick.vaucher@camptocamp.com> * Yannick Vaucher <yannick.vaucher@camptocamp.com>
* Zakaria Makrelouf <z.makrelouf@gmail.com> * Zakaria Makrelouf <z.makrelouf@gmail.com>
* `Tecnativa <https://www.tecnativa.com>`_: * Tecnativa <https://www.tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com> * Jairo Llopis <jairo.llopis@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com> * David Vidal <david.vidal@tecnativa.com>
* Ernesto Tejeda <ernesto.tejeda87@gmail.com> * Ernesto Tejeda <ernesto.tejeda87@gmail.com>
* Jeroen Evens <jeroen.evens@dynapps.be>

View File

@ -91,7 +91,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
if (_.isUndefined(this.ir_options_loaded)) { if (_.isUndefined(this.ir_options_loaded)) {
this.ir_options_loaded = $.Deferred(); this.ir_options_loaded = $.Deferred();
this.ir_options = {}; this.ir_options = {};
web_m2x_options.done(function (records) { web_m2x_options.then(function (records) {
_(records).each(function(record) { _(records).each(function(record) {
self.ir_options[record.key] = record.value; self.ir_options[record.key] = record.value;
}); });
@ -120,39 +120,37 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
_search: function (search_val) { _search: function (search_val) {
var self = this; var self = this;
var def = $.Deferred(); var def = new Promise(function (resolve) {
this.orderer.add(def);
// add options limit used to change number of selections record // add options limit used to change number of selections record
// returned. // returned.
if (!_.isUndefined(this.ir_options['web_m2x_options.limit'])) { if (!_.isUndefined(self.ir_options['web_m2x_options.limit'])) {
this.limit = parseInt(this.ir_options['web_m2x_options.limit'], 10); self.limit = parseInt(self.ir_options['web_m2x_options.limit'], 10);
} }
if (typeof this.nodeOptions.limit === 'number') { if (typeof self.nodeOptions.limit === 'number') {
this.limit = this.nodeOptions.limit; self.limit = self.nodeOptions.limit;
} }
// add options field_color and colors to color item(s) depending on field_color value // add options field_color and colors to color item(s) depending on field_color value
this.field_color = this.nodeOptions.field_color; self.field_color = self.nodeOptions.field_color;
this.colors = this.nodeOptions.colors; self.colors = self.nodeOptions.colors;
var context = this.record.getContext(this.recordParams); var context = self.record.getContext(self.recordParams);
var domain = this.record.getDomain(this.recordParams); var domain = self.record.getDomain(self.recordParams);
var blacklisted_ids = this._getSearchBlacklist(); var blacklisted_ids = self._getSearchBlacklist();
if (blacklisted_ids.length > 0) { if (blacklisted_ids.length > 0) {
domain.push(['id', 'not in', blacklisted_ids]); domain.push(['id', 'not in', blacklisted_ids]);
} }
this._rpc({ self._rpc({
model: this.field.relation, model: self.field.relation,
method: "name_search", method: "name_search",
kwargs: { kwargs: {
name: search_val, name: search_val,
args: domain, args: domain,
operator: "ilike", operator: "ilike",
limit: this.limit + 1, limit: self.limit + 1,
context: context, context: context,
} }
}).then(function (result) { }).then(function (result) {
@ -191,7 +189,7 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
} }
} }
} }
def.resolve(values); resolve(values);
}) })
} }
@ -207,21 +205,33 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
values.push({ values.push({
label: _t("Search More..."), label: _t("Search More..."),
action: function () { action: function () {
// limit = 80 for improving performance, similar var prom;
// to Odoo implementation here: if (search_val !== '') {
// https://github.com/odoo/odoo/commit/8c3cdce539d87775b59b3f2d5ceb433f995821bf prom = self._rpc({
self._rpc({
model: self.field.relation, model: self.field.relation,
method: 'name_search', method: 'name_search',
kwargs: { kwargs: {
name: search_val, name: search_val,
args: domain, args: domain,
operator: "ilike", operator: "ilike",
limit: 80, limit: self.SEARCH_MORE_LIMIT,
context: context, context: context,
}, },
}) });
.then(self._searchCreatePopup.bind(self, "search")); }
Promise.resolve(prom).then(function (results) {
var dynamicFilters;
if (results) {
var ids = _.map(results, function (x) {
return x[0];
});
dynamicFilters = [{
description: _.str.sprintf(_t('Quick search: %s'), search_val),
domain: [['id', 'in', ids]],
}];
}
self._searchCreatePopup("search", false, {}, dynamicFilters);
});
}, },
classname: 'o_m2o_dropdown_option', classname: 'o_m2o_dropdown_option',
}); });
@ -271,10 +281,12 @@ odoo.define('web_m2x_options.web_m2x_options', function (require) {
} }
// Check if colors specified to wait for RPC // Check if colors specified to wait for RPC
if (!(self.field_color && self.colors)) { if (!(self.field_color && self.colors)) {
def.resolve(values); resolve(values);
} }
}); });
});
this.orderer.add(def);
return def; return def;
} }
}); });