2

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.

skink
  • 5,133
  • 6
  • 37
  • 58
Ancient
  • 3,007
  • 14
  • 55
  • 104

1 Answers1

3

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();
        });
    });;
},
jo541
  • 1,155
  • 6
  • 10
  • I am getting this error `ReferenceError: Model is not defined`. Also can you let me know if i want to get any field other then `Name` from model – Ancient Oct 23 '17 at 13:48
  • You need import `var Model = require('web.DataModel');`and you can replace `.call('name_get', ... ` by `.call('read', [ids, ['name', 'display_name'], this.dataset.get_context()])` – jo541 Oct 23 '17 at 14:05
  • Thanks Sir, You're Awesome ! – Ancient Oct 23 '17 at 14:54
  • Slowly and safely compliments, I'll end up loving it! :D – jo541 Oct 23 '17 at 15:10
  • I am having an issue that it only works when in enable `debug mode`. Is there any way around for this ? – Ancient Oct 24 '17 at 15:34