[英]how to limit access to 'create and edit' in many2one field in odoo
< field name="product_id"
attrs="{'readonly': [('state', 'in', ('purchase', 'to approve','done', 'cancel'))],
'required': [('display_type', '=', False)],
}"
context="{'partner_id':parent.partner_id,
'quantity':product_qty,
'uom':product_uom,
'company_id': parent.company_id,
'show_for_ia':True}"
force_save="1"
domain="[('purchase_ok', '=', True), '|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]" groups="ia_po_rights.po_prd"
/>
在 purchase.order 表单中,我想限制在 odoo 13 中create and edit
字段“product_id”的访问权限,唯一允许特定的用户可以在采购订单表单中创建/编辑产品
我努力了
options="{'no_quick_create':True,'no_create_edit':True, 'no_create': True, 'no_open':True}"
在产品选项中,它删除了创建/编辑选项。
我创建了一个群组
<record id="po_prd" model="res.groups">
<field name="name">Create/Edit Product</field>
<field name="category_id" ref="module_ia_purchase_product"/>
</record>
和 csv 文件 ``` id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_product_product_user,product.product.user,product.model_product_product,ia_po_rights.po_prd,1,0,0,1
but above removes the field `product_id` from the form.
how to allow it for "po_prd" users to create/edit product in purchase order form without removing the field?
I have tried overriding fields_view_get method
class purchase_po(models.Model):
_inherit="purchase.order"
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(purchase_po, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='product_id']")
if self.env.user.has_group('ia_po_rights.po_prd'):
for node in nodes:
node.set('options', "{'no_create_edit': False}")
res['arch'] = etree.tostring(doc)
return res
but that not set the options to "product_id" field in purchase order
please suggest how to achieve this
我认为使用标准 odoo 框架不可能实现您想要的行为。
在字段视图定义上使用组将显示或隐藏该字段。 所以这不是你的选择。 并且使用您提到的字段选项将始终“隐藏”创建/编辑,而后面没有组控件。
我会使用字段选项 go,因为产品也可以在其他地方创建,例如在产品菜单中,您可以使用正常的 odoo 访问可能性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.