Search code examples
odooodoo-10odoo-view

Show to be deleted items in popup window


I am using Odoo 10e. I want a simple functionality that whenever i wanted to delete one or more then one item from a list view or from a specific list view only. I want to show all of the items which are selected for deleted to show their name in popup window so that user can have a quick review what's he is going to delete. I know user can see details in list view but i want to give a glimpse to user in shape of model window that this is going to be deleted. Are you sure to delete ?

If user click Confirm then normal delete case should work.

As far i research and worked on it, i have idea that it should be something regarding overriding the do_delete method in the list_view.js in the web module. But i didn't know much about javascript overriding for Odoo.


Solution

  • This is an example how I do it.

    I called the name_get for your model and records ids, this names list, I change the text of confirming message with the information of ids selected.

    do_delete: function (ids) {
    
        new Model(this.model)
        .call('name_get', [ids, this.dataset.get_context()]).done(function (names) {
    
    
            var text = _t("Do you really want to remove these records?") + ' '+ names.join(' \n')
            if (!(ids.length && confirm(text))) {
                return;
            }
            var self = this;
    
            return $.when(this.dataset.unlink(ids)).done(function () {
                _(ids).each(function (id) {
                    self.records.remove(self.records.get(id));
                });
                // Hide the table if there is no more record in the dataset
                if (self.display_nocontent_helper()) {
                    self.no_result();
                } else {
                    if (self.records.length && self.current_min === 1) {
                        // Reload the list view if we delete all the records of the first page
                        self.reload();
                    } else if (self.records.length && self.dataset.size() > 0) {
                        // Load previous page if the current one is empty
                        self.pager.previous();
                    }
                    // Reload the list view if we are not on the last page
                    if (self.current_min + self._limit - 1 < self.dataset.size()) {
                        self.reload();
                    }
                }
                self.update_pager(self.dataset);
                self.compute_aggregates();
            });
        });;
    },