forked from Techsystech/web
Merge pull request #1040 from Tecnativa/11.0-web_advanced_search-fix_x2many
[FIX] web_advanced_search: `undefined` in x2m fields11.0
commit
2e574053c6
|
@ -39,12 +39,21 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
* An almost dummy search proposition, to use with domain widget
|
* An almost dummy search proposition, to use with domain widget
|
||||||
*/
|
*/
|
||||||
var AdvancedSearchProposition = Widget.extend({
|
var AdvancedSearchProposition = Widget.extend({
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
init: function (parent, model, domain) {
|
init: function (parent, model, domain) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.domain = new Domain(domain);
|
this.domain = new Domain(domain);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Produce a filter descriptor for advanced searches.
|
||||||
|
*
|
||||||
|
* @returns {Object} In the format expected by `web.FilterMenu`.
|
||||||
|
*/
|
||||||
get_filter: function () {
|
get_filter: function () {
|
||||||
var domain_array = this.domain.toArray();
|
var domain_array = this.domain.toArray();
|
||||||
return {
|
return {
|
||||||
|
@ -74,6 +83,9 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
"click .o_add_advanced_search": "advanced_search_open",
|
"click .o_add_advanced_search": "advanced_search_open",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
init: function () {
|
init: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.trigger_up("get_dataset");
|
this.trigger_up("get_dataset");
|
||||||
|
@ -131,6 +143,9 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
className: "x2x_container",
|
className: "x2x_container",
|
||||||
attributes: {},
|
attributes: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
init: function () {
|
init: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
// To make widgets work, we need a model and an empty record
|
// To make widgets work, we need a model and an empty record
|
||||||
|
@ -139,8 +154,8 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
// Make equal and not equal appear 1st and 2nd
|
// Make equal and not equal appear 1st and 2nd
|
||||||
this.operators = _.sortBy(
|
this.operators = _.sortBy(
|
||||||
this.operators,
|
this.operators,
|
||||||
function(op) {
|
function (op) {
|
||||||
switch(op.value) {
|
switch (op.value) {
|
||||||
case "=":
|
case "=":
|
||||||
return -2;
|
return -2;
|
||||||
case "!=":
|
case "!=":
|
||||||
|
@ -154,7 +169,6 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
fieldNames: [this.field.name],
|
fieldNames: [this.field.name],
|
||||||
modelName: this.dataset.model,
|
modelName: this.dataset.model,
|
||||||
context: this.dataset.context,
|
context: this.dataset.context,
|
||||||
// res_id: "virtual_0",
|
|
||||||
fields: {},
|
fields: {},
|
||||||
type: "record",
|
type: "record",
|
||||||
viewType: "default",
|
viewType: "default",
|
||||||
|
@ -164,6 +178,10 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
};
|
};
|
||||||
// See https://stackoverflow.com/a/11508530/1468388
|
// See https://stackoverflow.com/a/11508530/1468388
|
||||||
params.fields[this.field.name] = _.omit(this.field, "onChange");
|
params.fields[this.field.name] = _.omit(this.field, "onChange");
|
||||||
|
if (this.field.type.endsWith("2many")) {
|
||||||
|
// X2many fields behave like m2o in the search context
|
||||||
|
params.fields[this.field.name].type = "many2one";
|
||||||
|
}
|
||||||
params.fieldsInfo.default[this.field.name] = {};
|
params.fieldsInfo.default[this.field.name] = {};
|
||||||
// Emulate `model.load()`, without RPC-calling `default_get()`
|
// Emulate `model.load()`, without RPC-calling `default_get()`
|
||||||
this.datapoint_id = this.model._makeDataPoint(params).id;
|
this.datapoint_id = this.model._makeDataPoint(params).id;
|
||||||
|
@ -176,6 +194,9 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
this._fake_id = -1;
|
this._fake_id = -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
start: function () {
|
start: function () {
|
||||||
var result = this._super.apply(this, arguments);
|
var result = this._super.apply(this, arguments);
|
||||||
// Render the initial widget
|
// Render the initial widget
|
||||||
|
@ -183,6 +204,9 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
if (this._field_widget) {
|
if (this._field_widget) {
|
||||||
this._field_widget.destroy();
|
this._field_widget.destroy();
|
||||||
|
@ -192,10 +216,18 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get record object for current datapoint.
|
||||||
|
*
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
_get_record: function () {
|
_get_record: function () {
|
||||||
return this.model.get(this.datapoint_id);
|
return this.model.get(this.datapoint_id);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
show_inputs: function ($operator) {
|
show_inputs: function ($operator) {
|
||||||
// Get widget class to be used
|
// Get widget class to be used
|
||||||
switch ($operator.val()) {
|
switch ($operator.val()) {
|
||||||
|
@ -234,6 +266,9 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
_applyChanges: function (dataPointID, changes, event) {
|
_applyChanges: function (dataPointID, changes, event) {
|
||||||
// Make char updates look like valid x2one updates
|
// Make char updates look like valid x2one updates
|
||||||
if (_.isNaN(changes[this.field.name].id)) {
|
if (_.isNaN(changes[this.field.name].id)) {
|
||||||
|
@ -245,11 +280,17 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
return FieldManagerMixin._applyChanges.apply(this, arguments);
|
return FieldManagerMixin._applyChanges.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
_confirmChange: function (id, fields, event) {
|
_confirmChange: function (id, fields, event) {
|
||||||
this.datapoint_id = id;
|
this.datapoint_id = id;
|
||||||
return this._field_widget.reset(this._get_record(), event);
|
return this._field_widget.reset(this._get_record(), event);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
get_value: function () {
|
get_value: function () {
|
||||||
try {
|
try {
|
||||||
switch (this._field_widget_name) {
|
switch (this._field_widget_name) {
|
||||||
|
@ -265,6 +306,11 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the field's value in a human-readable format.
|
||||||
|
*
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
toString: function () {
|
toString: function () {
|
||||||
try {
|
try {
|
||||||
switch (this._field_widget_name) {
|
switch (this._field_widget_name) {
|
||||||
|
|
Loading…
Reference in New Issue