Search code examples
odooodoo-8odoo-9

Pop Up message when deleting contact


If you delete partner from form view. you go actions> delete and then you get the message "Do you really want to delete this records?"

This is original method

on_button_delete: function() {
        var self = this;
        var def = $.Deferred();
        this.has_been_loaded.done(function() {
            if (self.datarecord.id && confirm(_t("Do you really want to delete this recordss?"))) {
                self.dataset.unlink([self.datarecord.id]).done(function() {
                    if (self.dataset.size()) {
                        self.execute_pager_action('next');
                    } else {
                        self.do_action('history_back');
                    }
                    def.resolve();
                });
            } else {
                $.async_when().done(function () {
                    def.reject();
                });
            }
        });
        return def.promise();

but if you add a contact to partner, when you want to delete it(it's in the bottom inside contact & addresses tab) there is no such message, so I want to make the same popup work when I delete a contact from a partner. But as have 0 knowledge in JS I need your help guys.


Solution

  • That could be done using the following js code:

    odoo.define('x2many_kanban_delete_confirm', function (require) {
        "use strict";
    
        var KanbanView = require('web_kanban.KanbanView');
    
        KanbanView.include({
            init: function (parent, dataset, view_id, options) {
                this._super(parent, dataset, view_id, options);
                this.options.confirm_on_delete = true;
            }
        });
    
    });
    

    Just load it into your Odoo and it will allow you to confirm the delete in the kanban view of an x2many field that are the ones that don't allow the confirm check before delete.

    If you wanna you could check for an specific model, using this condition:

    if(this.model == 'res.partner') {
        this.options.confirm_on_delete = true;
    }
    

    But I don't find it necessary as it won't break anything