In odoo, when you show a One2many field as a tree view, there is always a trash icon at the right side, that is used to delete the selected One2Many record. When you click that icon it deletes the record without confirmation. I was wondering if it is possible to show a confirmation dialog ("Are you sure you want to delete the record?") when clicking the trash icon in the One2Many fields tree list.
Asked
Active
Viewed 665 times
1

Gautam Bothra
- 565
- 1
- 8
- 23

Ernesto Ruiz
- 736
- 9
- 31
1 Answers
1
You can override the _onRemoveRecord
function to show a confirmation dialog when an attribute (confirmOnDelete
) is set on the One2many field in the form view.
Example:
var core = require('web.core');
var FieldOne2Many = require('web.relational_fields').FieldOne2Many;
var Dialog = require('web.Dialog');
var _t = core._t;
FieldOne2Many.include({
_onRemoveRecord: function (ev) {
var _super = this._super.bind(this);
if (this.attrs.confirmOnDelete) {
Dialog.confirm(this, _t("Are you sure you want to delete the record ?"), {
confirm_callback: () => _super(ev),
});
} else {
_super(ev);
}
},
});
A similar option is available for tree view and implemented in the controller, but the One2many widget only uses list renderer

Kenly
- 24,317
- 7
- 44
- 60