如何在 Odoo 中基于组隐藏 edit/create 按钮?

How to hide edit/create button based on group in Odoo?

如果我们保留 edit="false"create="false",那么我们可以删除编辑和创建按钮。但是是否可以基于组删除这些按钮?对于管理员来说,它应该是可见的,而对于用户来说,它不应该是可见的。

Security in Odoo

Access Control

Managed by the ir.model.access records, defines access to a whole model.

Each access control has a model to which it grants permissions, the permissions it grants and optionally a group.

Access controls are additive, for a given model a user has access all permissions granted to any of its groups: if the user belongs to one group which allows writing and another which allows deleting, they can both write and delete.

If no group is specified, the access control applies to all users, otherwise it only applies to the members of the given group.

Available permissions are creation (perm_create), searching and reading (perm_read), updating existing records (perm_write) and deleting existing records (perm_unlink)

因此您需要创建一个具有模型权限的文件 (module_name/security/ir.model.access.csv) 才能获得您想要的内容。

这个文件的内容应该是这样的:

顺便说一句,如果你想让某些东西只对管理员可见,那么你应该将这个属性添加到元素中:groups="base.group_no_one"