From 94c8c6553b8290c017f2963fde78088eec452d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=2E=20D=C3=ADaz?= Date: Wed, 17 Feb 2021 19:01:53 +0100 Subject: [PATCH 1/2] [FIX] web_widget_one2many_product_picker: Auto save --- .../quick_modif_price_form_view.js | 1 + .../js/views/One2ManyProductPicker/record.js | 38 ++++--- .../views/One2ManyProductPicker/renderer.js | 29 ++++- .../widgets/field_one2many_product_picker.js | 100 +++++++++++++++--- .../src/xml/one2many_product_picker.xml | 2 +- 5 files changed, 138 insertions(+), 32 deletions(-) diff --git a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js index 7b6a8f7a2..bb128b730 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js +++ b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js @@ -179,6 +179,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm this.trigger_up("update_quick_record", { id: record.id, }); + self.model.unsetDirty(self.handle); this.getParent().destroy(); } }, diff --git a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js index ab5d15780..a91c9db8d 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js +++ b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js @@ -213,6 +213,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu is_virtual: this.is_virtual, modified: record && record.context.product_picker_modified, active_model: '', + auto_save: this.options.autoSave, }; }, @@ -493,11 +494,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu _calcPriceReduced: function () { var price_reduce = 0; var field_map = this.options.fieldMap; - var state_data = this.state.data; - if (state_data && state_data[field_map.discount]) { + var model = this.options.basicFieldParams.model; + var record = model.get(this.state.id); + if (record && record.data[field_map.discount]) { price_reduce = tools.priceReduce( - state_data[field_map.price_unit], - state_data[field_map.discount]); + record.data[field_map.price_unit], + record.data[field_map.discount]); } return price_reduce && tools.monetary( price_reduce, @@ -516,28 +518,36 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu var model = this.options.basicFieldParams.model; var record = model.get(this.state.id); return model.save(record.id, { + stayInEdit: true, + reload: true, savePoint: true, + viewType: "form", }).then(function () { var record = model.get(self.state.id); self.trigger_up("create_quick_record", { id: record.id, + callback: function () { + self.$card.find('.o_catch_attention').removeClass('o_catch_attention'); + } }); model.unsetDirty(self.state.id); - self.$card.find('.o_catch_attention').removeClass('o_catch_attention'); }); }, /** * @private */ - _updateRecord: function (changes) { + _updateRecord: function () { + var self = this; var model = this.options.basicFieldParams.model; var record = model.get(this.state.id); this.trigger_up("update_quick_record", { id: record.id, + callback: function () { + self.$card.find('.o_catch_attention').removeClass('o_catch_attention'); + } }); model.unsetDirty(this.state.id); - this.$card.find('.o_catch_attention').removeClass('o_catch_attention'); }, /** @@ -546,13 +556,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu */ _addProduct: function () { var self = this; - var changes = {}; - if (this.state.data[this.options.fieldMap.product_uom_qty] === 0) { + var model = this.options.basicFieldParams.model; + var record = model.get(this.state.id); + var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty); + if (changes[this.options.fieldMap.product_uom_qty] === 0) { changes[this.options.fieldMap.product_uom_qty] = 1; } var model = this.options.basicFieldParams.model; this.$card.addClass("blocked"); - return model.notifyChanges(this.state.id, changes).then(function () { + return model.notifyChanges(record.id, changes).then(function () { self._saveRecord(); }); }, @@ -564,12 +576,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu */ _incProductQty: function (amount) { var self = this; - this.state.data[this.options.fieldMap.product_uom_qty] += amount; var model = this.options.basicFieldParams.model; var record = model.get(this.state.id); - var state_data = record.data; - state_data[this.options.fieldMap.product_uom_qty] += amount; - var changes = _.pick(state_data, this.options.fieldMap.product_uom_qty); + var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty); + changes[this.options.fieldMap.product_uom_qty] += amount; return model.notifyChanges(record.id, changes).then(function () { self._processDynamicFields(); diff --git a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js index 48820a031..e5225d0a0 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js +++ b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js @@ -104,8 +104,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", */ updateState: function (state, params) { var self = this; + var force_update = params.force; + delete params.force; var sparams = _.extend({}, params, {noRender: true}); - if (_.isEqual(this.state.data, state.data)) { + if (!force_update && _.isEqual(this.state.data, state.data)) { return this._super(state, sparams); } var old_state = _.clone(this.state.data); @@ -114,6 +116,22 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", }); }, + /** + * Recreate the given widget by the state id + * + * @param {String} state_id + * @param {Object} new_state + */ + updateRecord: function (state_id, new_state) { + for (var eb = this.widgets.length-1; eb>=0; --eb) { + var widget = this.widgets[eb]; + if (widget.state.id === state_id) { + widget.recreate(new_state); + break; + } + } + }, + /** * @private * @param {Array[Object]} states @@ -206,7 +224,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", var found = false; for (var e in this.state.data) { var current_state = this.state.data[e]; - if (current_state.id === old_state.id || (typeof current_state.data.id !== 'undefined' && current_state.data.id === old_state.data.id)) { + if (current_state.id === old_state.id) { found = true; break; } @@ -215,6 +233,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", states_to_destroy.push(old_state); } } + + this.state.data = _.compact(this.state.data); this._removeRecords(states_to_destroy, this.state.data); // Records to Update or Create @@ -232,7 +252,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", // Already processed widget (deleted) continue; } - if (widget.state.id === state.id || (typeof state.data.id !== 'undefined' && widget.state.data.id === state.data.id)) { + if (widget.state.id === state.id) { widget.recreate(state); exists = true; break; @@ -255,6 +275,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", } } + this.state.data = _.compact(this.state.data); + // Need add a new one? if (!exists && search_record_index !== -1) { var new_search_record = _.extend({}, search_record, {__id: state.id}); @@ -362,6 +384,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", showDiscount: this.options.show_discount, editDiscount: this.options.edit_discount, editPrice: this.options.edit_price, + autoSave: this.options.auto_save, }); }, diff --git a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js index f6d089d69..3f2593c8e 100644 --- a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js +++ b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js @@ -37,6 +37,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun update_subtotal: "_onUpdateSubtotal", load_more: "_onLoadMore", loading_records: "_onLoadingRecords", + list_record_remove: "_onListRecordRemove", }), _auto_search_delay: 450, @@ -438,6 +439,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun discount: "discount", }, auto_save: false, + allow_warning: true, }; }, @@ -525,7 +527,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun 'name': 'main_lines', }; this._searchContext.domain = this._getLinesDomain(); - this._searchContext.order = false; + this._searchContext.order = [{'name': 'sequence'}, {'name': 'id'}]; this._searchContext.activeTest = false; this.doRenderSearchRecords(); }, @@ -580,20 +582,45 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun * @param {CustomEvent} evt */ _onCreateQuickRecord: function (evt) { + evt.stopPropagation(); var self = this; this.parent_controller.model.setPureVirtual(evt.data.id, false); - if (!self.options.auto_save) { - self.parent_controller.model.updateRecordContext(evt.data.id, { + + if (this.options.auto_save) { + // Dont trigger state update + this._setValue( + {operation: "ADD", id: evt.data.id}, + {notifyChange: false} + ).then(function () { + if (self.options.auto_save) { + self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function (rrr) { + // Because 'create' generates a new state and we can't know these new id we + // need force update the all the current states. + self._setValue( + {operation: "UPDATE", id: evt.data.id}, + {doNotSetDirty: true} + ).then(function () { + if (evt.data.callback) { + evt.data.callback(); + } + }); + }); + } else if (evt.data.callback) { + evt.data.callback(); + } + }); + } else { + // This is used to know when need use 'yellow' color + this.parent_controller.model.updateRecordContext(evt.data.id, { product_picker_modified: true, }); + // This will trigger an "state" update + this._setValue({operation: "ADD", id: evt.data.id}).then(function () { + if (evt.data.callback) { + evt.data.callback(); + } + }); } - this._setValue({operation: "ADD", id: evt.data.id}).then(function () { - if (self.options.auto_save) { - self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () { - self.renderer.updateState(self.value); - }); - } - }); }, /** @@ -603,17 +630,62 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun * @param {CustomEevent} evt */ _onUpdateQuickRecord: function (evt) { + evt.stopPropagation(); var self = this; - if (!self.options.auto_save) { - self.parent_controller.model.updateRecordContext(evt.data.id, { + + if (this.options.auto_save) { + // Dont trigger state update + this._setValue( + {operation: "UPDATE", id: evt.data.id, data: evt.data.data}, + {notifyChange: false} + ).then(function () { + if (self.options.auto_save) { + self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () { + // Workaround to get updated values + self.parent_controller.model.reload(self.value.id).then(function (result) { + var new_data = self.parent_controller.model.get(result); + self.value.data = new_data.data; + self.renderer.updateState(self.value, {force: true}); + if (evt.data.callback) { + evt.data.callback(); + } + }); + }); + } else if (evt.data.callback) { + evt.data.callback(); + } + }); + } else { + // This is used to know when need use 'yellow' color + this.parent_controller.model.updateRecordContext(evt.data.id, { product_picker_modified: true, }); + // This will trigger an "state" update + this._setValue( + {operation: "UPDATE", id: evt.data.id, data: evt.data.data} + ).then(function () { + if (evt.data.callback) { + evt.data.callback(); + } + }); } - this._setValue({operation: "UPDATE", id: evt.data.id, data: evt.data.data}).then(function () { + }, + + /** + * Handle auto_save when remove a record + */ + _onListRecordRemove: function (evt) { + evt.stopPropagation(); + var self = this; + this._setValue({operation: "DELETE", ids: [evt.data.id]}).then(function () { if (self.options.auto_save) { self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () { - self.renderer.updateState(self.value); + if (evt.data.callback) { + evt.data.callback(); + } }); + } else if (evt.data.callback) { + evt.data.callback(); } }); }, diff --git a/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker.xml b/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker.xml index 481241e91..50133fa6a 100644 --- a/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker.xml +++ b/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker.xml @@ -70,7 +70,7 @@
-
+
From b72d8bd8ccd81c906267df221dce51de198e5609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20D=2E=20D=C3=ADaz?= Date: Fri, 19 Feb 2021 23:56:00 +0100 Subject: [PATCH 2/2] [IMP] web_widget_one2many_product_picker: Add option to ignore onchange warnings --- web_widget_one2many_product_picker/README.rst | 2 + .../readme/CONFIGURE.rst | 2 + .../static/description/index.html | 2 + .../js/views/One2ManyProductPicker/record.js | 12 +- .../views/One2ManyProductPicker/renderer.js | 27 +++ .../static/src/js/views/basic_model.js | 174 ++---------------- .../widgets/field_one2many_product_picker.js | 7 +- 7 files changed, 65 insertions(+), 161 deletions(-) diff --git a/web_widget_one2many_product_picker/README.rst b/web_widget_one2many_product_picker/README.rst index 0587024f2..bd6dc7ef0 100644 --- a/web_widget_one2many_product_picker/README.rst +++ b/web_widget_one2many_product_picker/README.rst @@ -86,6 +86,8 @@ Widget options: will lose part of its functionality as the document will be saved every time you modify/create a record with the widget. +* ignore_warning > Enable/Disable display onchange warnings (False by default) + All widget options are optional. Notice that you can call '_' method to use translations. This only can be used with this widget. diff --git a/web_widget_one2many_product_picker/readme/CONFIGURE.rst b/web_widget_one2many_product_picker/readme/CONFIGURE.rst index 1e5f8698b..29d8e9813 100644 --- a/web_widget_one2many_product_picker/readme/CONFIGURE.rst +++ b/web_widget_one2many_product_picker/readme/CONFIGURE.rst @@ -44,6 +44,8 @@ Widget options: will lose part of its functionality as the document will be saved every time you modify/create a record with the widget. +* ignore_warning > Enable/Disable display onchange warnings (False by default) + All widget options are optional. Notice that you can call '_' method to use translations. This only can be used with this widget. diff --git a/web_widget_one2many_product_picker/static/description/index.html b/web_widget_one2many_product_picker/static/description/index.html index 18ba5686e..de595921c 100644 --- a/web_widget_one2many_product_picker/static/description/index.html +++ b/web_widget_one2many_product_picker/static/description/index.html @@ -471,6 +471,8 @@ You need to define the view fields. The view must be of ignore_warning > Enable/Disable display onchange warnings (False by default)

+

All widget options are optional. Notice that you can call ‘_’ method to use translations. This only can be used with this widget.

diff --git a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js index a91c9db8d..f65ecc85b 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js +++ b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js @@ -557,6 +557,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu _addProduct: function () { var self = this; var model = this.options.basicFieldParams.model; + model.updateRecordContext(this.state.id, {ignore_warning: this.options.ignoreWarning}); var record = model.get(this.state.id); var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty); if (changes[this.options.fieldMap.product_uom_qty] === 0) { @@ -564,7 +565,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu } var model = this.options.basicFieldParams.model; this.$card.addClass("blocked"); - return model.notifyChanges(record.id, changes).then(function () { + return model.notifyChanges( + record.id, + changes + ).then(function () { self._saveRecord(); }); }, @@ -577,11 +581,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu _incProductQty: function (amount) { var self = this; var model = this.options.basicFieldParams.model; + model.updateRecordContext(this.state.id, {ignore_warning: this.options.ignoreWarning}); var record = model.get(this.state.id); var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty); changes[this.options.fieldMap.product_uom_qty] += amount; - return model.notifyChanges(record.id, changes).then(function () { + return model.notifyChanges( + record.id, + changes + ).then(function () { self._processDynamicFields(); self._lazyUpdateRecord(); }); diff --git a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js index e5225d0a0..71750434d 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js +++ b/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js @@ -300,6 +300,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", }); this.$extraButtonsContainer = $(qweb.render("One2ManyProductPicker.ExtraButtons")); this.$btnLoadMore = this.$extraButtonsContainer.find("#productPickerLoadMore"); + this.search_data = this._sort_search_data(this.search_data); return $.Deferred(function (d) { var defs = self.appendSearchRecords(self.search_data, true); defs[0].then(function () { @@ -316,6 +317,31 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", }); }, + /** + * @param {Array} datas + * @returns {Array} + */ + _sort_search_data: function (datas) { + if (this.search_group.name === "main_lines") { + var field_name = this.options.field_map.product; + for (var index_datas in datas) { + var data = datas[index_datas]; + + for (var index_state in this.state.data) { + var state_data = this.state.data[index_state]; + if (state_data.data[field_name].res_id === data.id) { + data._order_value = state_data.res_id; + } + } + } + var sorted_datas = _.chain(datas).sortBy('_order_value').map(function(item) { + return _.omit(item, '_order_value'); + }).value().reverse(); + return sorted_datas; + } + return datas; + }, + /** * Compare search results with current lines. * Link a current state with the 'search record'. @@ -385,6 +411,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", editDiscount: this.options.edit_discount, editPrice: this.options.edit_price, autoSave: this.options.auto_save, + ignoreWarning: this.options.ignore_warning, }); }, diff --git a/web_widget_one2many_product_picker/static/src/js/views/basic_model.js b/web_widget_one2many_product_picker/static/src/js/views/basic_model.js index 9a69b6ccd..9d8fd3f52 100644 --- a/web_widget_one2many_product_picker/static/src/js/views/basic_model.js +++ b/web_widget_one2many_product_picker/static/src/js/views/basic_model.js @@ -79,8 +79,9 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require) self._makeDefaultRecord(list.model, params) .then(function (recordID) { self.setPureVirtual(recordID, true); + self.updateRecordContext(recordID, {ignore_warning: true}); if (options.data) { - self._applyChangeNoWarnings( + self._applyChange( recordID, options.data, params @@ -95,165 +96,26 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require) }, /** - * Cloned '_applyChange' but without warning messages + * Adds support to avoid show onchange warnings. + * The implementation is a pure hack that clone + * the context and do a monkey path the + * 'trigger_up' method. * - * @private - * @param {Number} recordID - * @param {Object} changes - * @param {Object} options - * @returns {Deferred} + * @override */ - _applyChangeNoWarnings: function (recordID, changes, options) { - var self = this; - var record = this.localData[recordID]; - var field; - var defs = []; - options = options || {}; - record._changes = record._changes || {}; - if (!options.doNotSetDirty) { - record._isDirty = true; - } - var initialData = {}; - this._visitChildren(record, function (elem) { - initialData[elem.id] = $.extend(true, {}, _.pick(elem, 'data', '_changes')); - }); - - // Apply changes to local data - for (var fieldName in changes) { - field = record.fields[fieldName]; - if (field && (field.type === 'one2many' || field.type === 'many2many')) { - defs.push(this._applyX2ManyChange( - record, - fieldName, - changes[fieldName], - options.viewType, - options.allowWarning)); - } else if (field && (field.type === 'many2one' || field.type === 'reference')) { - defs.push(this._applyX2OneChange(record, fieldName, changes[fieldName])); - } else { - record._changes[fieldName] = changes[fieldName]; - } - } - - if (options.notifyChange === false) { - return $.Deferred().resolve(_.keys(changes)); - } - - return $.when.apply($, defs).then(function () { - - // The fields that have changed and that have an on_change - var onChangeFields = []; - for (var fieldName in changes) { - field = record.fields[fieldName]; - if (field && field.onChange) { - var isX2Many = ( - field.type === 'one2many' || - field.type === 'many2many' - ); - if ( - !isX2Many || - ( - self._isX2ManyValid( - record._changes[fieldName] || - record.data[fieldName] - ) - ) - ) { - onChangeFields.push(fieldName); - } + _performOnChange: function (record, fields, viewType) { + if (record.context && record.context.ignore_warning) { + var this_mp = _.clone(this); + var super_call = this.trigger_up; + this_mp.trigger_up = function (event_name, data) { + if (event_name === 'warning' && data.type === "dialog") { + return; // Do nothing } - } - var onchangeDef = $.Deferred(); - if (onChangeFields.length) { - self._performOnChangeNoWarnings(record, onChangeFields, options.viewType) - .then(function (result) { - delete record._warning; - onchangeDef.resolve( - _.keys(changes).concat( - Object.keys((result && result.value) || {}))); - }).fail(function () { - self._visitChildren(record, function (elem) { - _.extend(elem, initialData[elem.id]); - }); - - // Safe fix for stable version, for opw-2267444 - if (!options.force_fail) { - onchangeDef.resolve({}); - } else { - onchangeDef.reject({}); - } - }); - } else { - onchangeDef = $.Deferred().resolve(_.keys(changes)); - } - return onchangeDef.then(function (fieldNames) { - _.each(fieldNames, function (name) { - if ( - record._changes && - record._changes[name] === record.data[name] - ) { - delete record._changes[name]; - record._isDirty = !_.isEmpty(record._changes); - } - }); - return self._fetchSpecialData(record).then(function (fieldNames2) { - - // Return the names of the fields that changed (onchange or - // associated special data change) - return _.union(fieldNames, fieldNames2); - }); - }); - }); - }, - - /** - * Cloned '_performOnChange' but without warning messages - * - * @private - * @param {Object} record - * @param {Object} fields - * @param {String} viewType - * @returns {Deferred} - */ - _performOnChangeNoWarnings: function (record, fields, viewType) { - var self = this; - var onchangeSpec = this._buildOnchangeSpecs(record, viewType); - if (!onchangeSpec) { - return $.when(); + return super_call.apply(this, arguments); + }.bind(this); + return this._super.apply(this_mp, arguments); } - var idList = record.data.id ? [record.data.id] : []; - var options = { - full: true, - }; - if (fields.length === 1) { - fields = fields[0]; - - // If only one field changed, add its context to the RPC context - options.fieldName = fields; - } - var context = this._getContext(record, options); - var currentData = this._generateOnChangeData(record, {changesOnly: false}); - - return self._rpc({ - model: record.model, - method: 'onchange', - args: [idList, currentData, fields, onchangeSpec, context], - }).then(function (result) { - if (!record._changes) { - - // If the _changes key does not exist anymore, it means that - // it was removed by discarding the changes after the rpc - // to onchange. So, in that case, the proper response is to - // ignore the onchange. - return; - } - if (result.domain) { - record._domains = _.extend(record._domains, result.domain); - } - return self._applyOnChange(result.value, record).then(function () { - return result; - }); - }); + return this._super.apply(this, arguments); }, }); diff --git a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js index 3f2593c8e..d642a7aea 100644 --- a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js +++ b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js @@ -439,7 +439,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun discount: "discount", }, auto_save: false, - allow_warning: true, + ignore_warning: false, }; }, @@ -662,7 +662,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun }); // This will trigger an "state" update this._setValue( - {operation: "UPDATE", id: evt.data.id, data: evt.data.data} + {operation: "UPDATE", id: evt.data.id, data: evt.data.data}, ).then(function () { if (evt.data.callback) { evt.data.callback(); @@ -746,7 +746,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun * * @override */ - _setValue: function () { + + _setValue: function (value, options) { var self = this; return this._super.apply(this, arguments).then(function () { self.updateBadgeLines();