3
0
Fork 0

Merge PR #1912 into 12.0

Signed-off-by pedrobaeza
12.0
OCA-git-bot 2021-05-03 11:31:00 +00:00
commit 239b7c5fcd
4 changed files with 38 additions and 31 deletions

View File

@ -81,7 +81,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @override
*/
destroy: function () {
this.$card.off("")
this.$el.remove();
this.$card.off("");
const model = this.options.basicFieldParams.model;
if (this.state) {
model.removeVirtualRecord(this.state.id);
}
this._super.apply(this, arguments);
},
@ -182,12 +187,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
this.fields = this.getParent().state.fields;
this.fieldsInfo = this.getParent().state.fieldsInfo.form;
var model = this.options.basicFieldParams.model;
if (this.state) {
model.removeVirtualRecord(this.state.id);
}
this.state = viewState;
if (recordSearch) {
this.recordSearch = recordSearch;
}
var model = this.options.basicFieldParams.model;
this.is_virtual = this.state && model.isPureVirtual(this.state.id) || false;
// Check if has cached qty

View File

@ -63,15 +63,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
_.invoke(this.widgets, 'on_detach_callback');
},
/**
* @param {Object} widget
*/
removeWidget: function (widget) {
var index = this.widgets.indexOf(widget);
widget.destroy();
delete this.widgets[index];
},
/**
* @override
*/

View File

@ -51,6 +51,24 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
});
},
removeVirtualRecord: function (id) {
if (!this.isPureVirtual(id)) {
return false;
}
const data = this.localData[id];
const to_remove = [];
this._visitChildren(data, (item) => {
to_remove.push(item.id);
});
to_remove.reverse();
for (let remove_id of to_remove) {
this.removeLine(remove_id);
delete this.localData[remove_id];
}
},
/**
* Generates a virtual records without link it
*

View File

@ -584,7 +584,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_onCreateQuickRecord: function (evt) {
evt.stopPropagation();
var self = this;
this.parent_controller.model.setPureVirtual(evt.data.id, false);
var model = this.parent_controller.model;
model.setPureVirtual(evt.data.id, false);
if (this.options.auto_save) {
// Dont trigger state update
@ -593,17 +594,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
{notifyChange: false}
).then(function () {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
// Because 'create' generates a new state and we can't know these new id we
// need force update all the current states.
self._setValue(
{operation: "UPDATE", id: evt.data.id},
{doNotSetDirty: true}
).then(function () {
self.renderer.updateState(model.get(self.parent_controller.handle).data[self.name], {force: true});
if (evt.data.callback) {
evt.data.callback();
}
});
});
if (evt.data.callback) {
evt.data.callback();
}
@ -631,16 +626,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
{notifyChange: false}
).then(function () {
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});
self.renderer.updateState(self.parent_controller.model.get(self.parent_controller.handle).data[self.name], {force: true});
if (callback) {
callback();
}
});
});
if (callback) {
callback();
}