[FIX] web_widget_one2many_product_picker: Confirm changes

pull/1917/head
Alexandre D. Díaz 2021-05-04 15:09:09 +02:00
parent 80020e8c7b
commit 37992bb486
1 changed files with 25 additions and 11 deletions

View File

@ -588,17 +588,24 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
model.setPureVirtual(evt.data.id, false); model.setPureVirtual(evt.data.id, false);
if (this.options.auto_save) { if (this.options.auto_save) {
// Dont trigger state update // Don't notifyChange because we already have all the onchange data for 1 qty
this._setValue( this._setValue(
{operation: "ADD", id: evt.data.id}, {operation: "ADD", id: evt.data.id},
{notifyChange: false} {notifyChange: false}
).then(function () { ).then(function () {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () { self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
self.renderer.updateState(model.get(self.parent_controller.handle).data[self.name], {force: true}); // When call 'saveRecord' with 'stayInEdit' the changes aren't confirmed so we force it
var parent_record = model.get(self.parent_controller.handle);
self.parent_controller.renderer.confirmChange(parent_record, parent_record.id, [self.name]).then(function() {
// Second call to callback method.
// We call two times because the first is for fast update
// this second is the update after parent changes
if (evt.data.callback) { if (evt.data.callback) {
evt.data.callback(); evt.data.callback();
} }
}); });
});
// First call to callback method
if (evt.data.callback) { if (evt.data.callback) {
evt.data.callback(); evt.data.callback();
} }
@ -620,17 +627,24 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_doUpdateQuickRecord: function (id, data, callback) { _doUpdateQuickRecord: function (id, data, callback) {
if (this.options.auto_save) { if (this.options.auto_save) {
var self = this; var self = this;
// Dont trigger state update var model = this.parent_controller.model;
this._setValue( this._setValue(
{operation: "UPDATE", id: id, data: data}, {operation: "UPDATE", id: id, data: data},
{notifyChange: false} {notifyChange: true}
).then(function () { ).then(function () {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () { self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
self.renderer.updateState(self.parent_controller.model.get(self.parent_controller.handle).data[self.name], {force: true}); // When call 'saveRecord' with 'stayInEdit' the changes aren't confirmed so we force it
var parent_record = model.get(self.parent_controller.handle);
self.parent_controller.renderer.confirmChange(parent_record, parent_record.id, [self.name]).then(function() {
// Second call to callback method.
// We call two times because the first is for fast update
// this second is the update after parent changes
if (callback) { if (callback) {
callback(); callback();
} }
}); });
});
// First call to callback method
if (callback) { if (callback) {
callback(); callback();
} }