如何在Odoo的Many2One字段中限制对'create and edit'的访问


< 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 中字段"product_id"create and edit的访问,唯一允许的特定用户可以在采购订单表单中创建/编辑产品

我试过了

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 框架中是不可能的。

在字段视图定义上使用组将显示或隐藏字段。所以这对你来说不是选择。使用您提到的字段选项将始终"隐藏"创建/编辑,而无需其背后的组控件。

我会选择字段选项,因为也可以在其他地方创建产品,例如在产品菜单中,您可以在其中使用正常的 odoo 访问可能性。

最新更新