在弹出窗口中显示要删除的项目

时间:2017-10-23 12:18:57

标签: openerp odoo-10 odoo-view

我正在使用Odoo 10e。我想要一个简单的功能,每当我想从列表视图或从特定的列表视图中删除一个或多个项目时。我想显示所有选中要删除的项目,以便在弹出窗口中显示其名称,以便用户可以快速查看他要删除的内容。我知道用户可以在列表视图中查看详细信息,但我想在模型窗口的形状中向用户一瞥,这将被删除。你确定要删除吗?

如果用户单击“确认”,则正常删除案例应该有效。

至于我研究和研究它,我认为它应该是覆盖Web模块中do_delete中的list_view.js方法。但我对Odoo的javascript覆盖知之甚少。

1 个答案:

答案 0 :(得分:3)

这是我如何做的一个例子。

我为你的模型调用了name_get并记录了id,这个名字列表,我用确定的id信息改变了确认消息的文本。

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();
        });
    });;
},