我正在使用 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/