ODOO的每个一版本中都有显示notify的机制,ODOO18中用多种方式,可以调用服务,也可以调用动作,代码如下:
export function displayNotificationAction(env, action) {
const params = action.params || {};
const options = {
className: params.className || "",
sticky: params.sticky || false,
title: params.title,
type: params.type || "info",
};
const links = (params.links || []).map((link) => {
return `<a href="${escape(link.url)}" target="_blank">${escape(link.label)}</a>`;
});
const message = markup(sprintf(escape(params.message), ...links));
env.services.notification.add(message, options);
return params.next;
}
registry.category("actions").add("display_notification", displayNotificationAction);
可以看到,最终注册成为了一个动作,由于是个动作,所以我们可以在后端返回,至于为什么可以在后端返回可以关注我们的课程
def action_merge(self):
""" Merge each group of accounts in `self.wizard_line_ids`. """
self._check_access_rights(self.account_ids)
for wizard in self:
wizard_lines_selected = wizard.wizard_line_ids.filtered(lambda l: l.display_type == 'account' and l.is_selected and not l.info)
for wizard_lines_group in wizard_lines_selected.grouped('grouping_key').values():
if len(wizard_lines_group) > 1:
# This ensures that if one account in the group has hashed entries, it appears first, ensuring
# that its ID doesn't get changed by the merge.
self._action_merge(wizard_lines_group.sorted('account_has_hashed_entries', reverse=True).account_id)
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'success',
'sticky': False,
'message': _("Accounts successfully merged!"),
'next': {'type': 'ir.actions.act_window_close'},
}
}
如果便参将信息显示在前端,但这里美中不足的是不能以模板的形式进行渲染,同时,如果有js交互的话也无法,所以,有兴趣可以在这方面进行扩展,让它支持模板,同时能和js进行交互,当然,动态js又是另外一个话题。