forked from Techsystech/web
[FIX] web_widget_one2many_product_picker: Show lines with archived products
parent
eb94bd90b5
commit
60be67927b
|
@ -39,9 +39,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
this.mode = parent.mode;
|
this.mode = parent.mode;
|
||||||
this.search_data = parent._searchRecords;
|
this.search_data = parent._searchRecords;
|
||||||
this.last_search_data_count = parent._lastSearchRecordsCount;
|
this.last_search_data_count = parent._lastSearchRecordsCount;
|
||||||
this._lazyOnScrollView = _.debounce(
|
|
||||||
this._onScrollView.bind(this),
|
|
||||||
this.DELAY_GET_RECORDS);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,27 +422,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Auto-load more records (scroll pagination).
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {ScrollEvent} evt
|
|
||||||
*/
|
|
||||||
_onScrollView: function (evt) {
|
|
||||||
var cur_pos = evt.target.scrollTop;
|
|
||||||
var max_pos = evt.target.scrollHeight - evt.target.clientHeight;
|
|
||||||
var perc_pos = cur_pos / max_pos;
|
|
||||||
if (perc_pos > this.MIN_PERC_GET_RECORDS) {
|
|
||||||
if (!this._loadMoreWorking) {
|
|
||||||
this.trigger_up("load_more");
|
|
||||||
this._loadMoreWorking = true;
|
|
||||||
this.$btnLoadMore.attr("disabled", true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this._loadMoreWorking = false;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -83,7 +83,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
domain: this.mode === "readonly" ? this._getLinesDomain() : false,
|
domain: this.mode === "readonly" ? this._getLinesDomain() : false,
|
||||||
text: false,
|
text: false,
|
||||||
order: false,
|
order: false,
|
||||||
|
activeTest: true,
|
||||||
};
|
};
|
||||||
|
if (this.mode === "readonly") {
|
||||||
|
this._activeSearchGroup = {
|
||||||
|
'name': 'main_lines',
|
||||||
|
};
|
||||||
|
this._searchContext.activeTest = false;
|
||||||
|
}
|
||||||
return $.when(this._super.apply(this, arguments), this._getSearchRecords());
|
return $.when(this._super.apply(this, arguments), this._getSearchRecords());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -124,7 +131,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
}) || 0;
|
}) || 0;
|
||||||
total = tools.monetary(
|
total = tools.monetary(
|
||||||
total,
|
total,
|
||||||
this.state.data[this.name].fields[this.options.field_map.price_unit],
|
this.value.fields[this.options.field_map.price_unit],
|
||||||
this.options.currency_field,
|
this.options.currency_field,
|
||||||
this.state.data
|
this.state.data
|
||||||
);
|
);
|
||||||
|
@ -294,12 +301,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
* If merge is true the current records aren't removed.
|
* If merge is true the current records aren't removed.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} domain
|
|
||||||
* @param {Dictionary} options
|
* @param {Dictionary} options
|
||||||
* @param {Boolean} merge
|
* @param {Boolean} merge
|
||||||
* @returns {Deferred}
|
* @returns {Deferred}
|
||||||
*/
|
*/
|
||||||
_getSearchRecords: function (domain, options, merge) {
|
_getSearchRecords: function (options, merge) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var arch = this.view.arch;
|
var arch = this.view.arch;
|
||||||
var field_name = this.options.field_map.product;
|
var field_name = this.options.field_map.product;
|
||||||
|
@ -308,12 +314,13 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
|
|
||||||
// Launch the rpc request and ensures that we wait for the reply
|
// Launch the rpc request and ensures that we wait for the reply
|
||||||
// to continue
|
// to continue
|
||||||
var sdomain = this._getFullSearchDomain(domain);
|
var domain = this._getFullSearchDomain();
|
||||||
var soptions = options || {};
|
var soptions = options || {};
|
||||||
var context = _.extend({
|
var context = _.extend({
|
||||||
'active_search_group_name': this._activeSearchGroup.name,
|
'active_search_group_name': this._activeSearchGroup.name,
|
||||||
'active_search_involved_fields': this._searchContext.involvedFields,
|
'active_search_involved_fields': this._searchContext.involvedFields,
|
||||||
}, this.state.data[this.name].getContext());
|
'active_test': this._searchContext.activeTest,
|
||||||
|
}, this.value.getContext());
|
||||||
|
|
||||||
return $.Deferred(function (d) {
|
return $.Deferred(function (d) {
|
||||||
var limit = soptions.limit || self.options.records_per_page;
|
var limit = soptions.limit || self.options.records_per_page;
|
||||||
|
@ -322,7 +329,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
model: model,
|
model: model,
|
||||||
method: "search_read",
|
method: "search_read",
|
||||||
fields: self.search_read_fields,
|
fields: self.search_read_fields,
|
||||||
domain: sdomain,
|
domain: domain,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
orderBy: self._searchContext.order,
|
orderBy: self._searchContext.order,
|
||||||
|
@ -359,6 +366,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
this._activeSearchGroup = this.searchGroups[groupIndex];
|
this._activeSearchGroup = this.searchGroups[groupIndex];
|
||||||
this._searchContext.domain = this._activeSearchGroup.domain;
|
this._searchContext.domain = this._activeSearchGroup.domain;
|
||||||
this._searchContext.order = this._activeSearchGroup.order;
|
this._searchContext.order = this._activeSearchGroup.order;
|
||||||
|
this._searchContext.activeTest = true;
|
||||||
this.doRenderSearchRecords();
|
this.doRenderSearchRecords();
|
||||||
this.$btnLines.removeClass("active");
|
this.$btnLines.removeClass("active");
|
||||||
$btn.parent().find(".active").removeClass("active");
|
$btn.parent().find(".active").removeClass("active");
|
||||||
|
@ -428,55 +436,52 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
* This domain is used to get the records to display.
|
* This domain is used to get the records to display.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} domain
|
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
_getFullSearchDomain: function (domain) {
|
_getFullSearchDomain: function () {
|
||||||
var sdomain = _.clone(domain);
|
|
||||||
this._searchContext.involvedFields = [];
|
this._searchContext.involvedFields = [];
|
||||||
if (!sdomain) {
|
var domain = _.clone(this._searchContext.domain) || [];
|
||||||
sdomain = _.clone(this._searchContext.domain) || [];
|
if (this._searchContext.text) {
|
||||||
if (this._searchContext.text) {
|
var search_domain = this.options.search;
|
||||||
var search_domain = this.options.search;
|
if (!(search_domain[0] instanceof Array)) {
|
||||||
if (!(search_domain[0] instanceof Array)) {
|
search_domain = search_domain[this._searchMode].domain;
|
||||||
search_domain = search_domain[this._searchMode].domain;
|
|
||||||
}
|
|
||||||
var involved_fields = [];
|
|
||||||
|
|
||||||
// Iterate domain triplets and logic operators
|
|
||||||
for (var index in search_domain) {
|
|
||||||
var domain_cloned = _.clone(search_domain[index]);
|
|
||||||
|
|
||||||
// Is a triplet
|
|
||||||
if (domain_cloned instanceof Array) {
|
|
||||||
|
|
||||||
// Replace right leaf with the current value of the search input
|
|
||||||
if (domain_cloned[2] === "$number_search") {
|
|
||||||
domain_cloned[2] = Number(this._searchContext.text);
|
|
||||||
involved_fields.push({
|
|
||||||
type: 'number',
|
|
||||||
field: domain_cloned[0],
|
|
||||||
oper: domain_cloned[1],
|
|
||||||
});
|
|
||||||
} else if (
|
|
||||||
typeof domain_cloned[2] === "string" &&
|
|
||||||
domain_cloned[2].includes("$search")
|
|
||||||
) {
|
|
||||||
domain_cloned[2] = domain_cloned[2]
|
|
||||||
.replace(/\$search/, this._searchContext.text);
|
|
||||||
involved_fields.push({
|
|
||||||
type: 'text',
|
|
||||||
field: domain_cloned[0],
|
|
||||||
oper: domain_cloned[1],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sdomain.push(domain_cloned);
|
|
||||||
}
|
|
||||||
this._searchContext.involvedFields = involved_fields;
|
|
||||||
}
|
}
|
||||||
|
var involved_fields = [];
|
||||||
|
|
||||||
|
// Iterate domain triplets and logic operators
|
||||||
|
for (var index in search_domain) {
|
||||||
|
var domain_cloned = _.clone(search_domain[index]);
|
||||||
|
|
||||||
|
// Is a triplet
|
||||||
|
if (domain_cloned instanceof Array) {
|
||||||
|
|
||||||
|
// Replace right leaf with the current value of the search input
|
||||||
|
if (domain_cloned[2] === "$number_search") {
|
||||||
|
domain_cloned[2] = Number(this._searchContext.text);
|
||||||
|
involved_fields.push({
|
||||||
|
type: 'number',
|
||||||
|
field: domain_cloned[0],
|
||||||
|
oper: domain_cloned[1],
|
||||||
|
});
|
||||||
|
} else if (
|
||||||
|
typeof domain_cloned[2] === "string" &&
|
||||||
|
domain_cloned[2].includes("$search")
|
||||||
|
) {
|
||||||
|
domain_cloned[2] = domain_cloned[2]
|
||||||
|
.replace(/\$search/, this._searchContext.text);
|
||||||
|
involved_fields.push({
|
||||||
|
type: 'text',
|
||||||
|
field: domain_cloned[0],
|
||||||
|
oper: domain_cloned[1],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
domain.push(domain_cloned);
|
||||||
|
}
|
||||||
|
this._searchContext.involvedFields = involved_fields;
|
||||||
}
|
}
|
||||||
return sdomain || [];
|
|
||||||
|
return domain || [];
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,6 +516,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
};
|
};
|
||||||
this._searchContext.domain = this._getLinesDomain();
|
this._searchContext.domain = this._getLinesDomain();
|
||||||
this._searchContext.order = false;
|
this._searchContext.order = false;
|
||||||
|
this._searchContext.activeTest = false;
|
||||||
this.doRenderSearchRecords();
|
this.doRenderSearchRecords();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -594,7 +600,6 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
}
|
}
|
||||||
var self = this;
|
var self = this;
|
||||||
this._getSearchRecords(
|
this._getSearchRecords(
|
||||||
false,
|
|
||||||
{
|
{
|
||||||
offset: this._searchOffset,
|
offset: this._searchOffset,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue