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

标签 odoo odoo-10 odoo-view

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

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

据我研究和研究,我认为它应该与覆盖 Web 模块中 list_view.js 中的 do_delete 方法有关。但我对 Odoo 的 javascript 覆盖了解不多。

最佳答案

这是我如何做到这一点的示例。

我为您的模型调用了 name_get 并记录了 ids,此名称列表,我使用所选 ids 的信息更改了确认消息的文本。

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

关于odoo - 在弹出窗口中显示要删除的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46889193/

相关文章:

openerp - Odoo v10 在采购树和表单 View 中以公司货币显示金额

search - 如何在 Odoo 中通过计算字段进行搜索?

xml - Odoo 域无法从域中过滤单元和小时

python - Odoo 10 - 验证合作伙伴的电子邮件

reporting - 在 Odoo 中修改发票

javascript - 对于特定模型,如何始终在编辑模式下打开表单

odoo - 将多对多字段显示为多对一

python - 我们可以用openERp计算净工资吗

python - 向 Odoo 11.0 帐户发票添加额外字段

html - Qweb Report 的 css 在打印页面上不起作用