3
0
Fork 0

[IMP] web_widget_one2many_product_picker: Destroy localData of virtual records

12.0
Alexandre D. Díaz 2021-04-29 14:31:33 +02:00
parent 167db197a2
commit c964295a27
3 changed files with 28 additions and 11 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
*