[英]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.