Reputation: 83
< 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"
/>
in purchase.order form, I want to limit the access of create and edit
of field 'product_id' in odoo 13, the only user allowed of specific can create/edit product in the purchase order form
i have tried
options="{'no_quick_create':True,'no_create_edit':True, 'no_create': True, 'no_open':True}"
in product option, it removes the create/edit option.
I created a group
<record id="po_prd" model="res.groups">
<field name="name">Create/Edit Product</field>
<field name="category_id" ref="module_ia_purchase_product"/>
</record>
and csv file ``` 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
Upvotes: 0
Views: 1007
Reputation: 14801
I think your desired behaviour is not possible with standard odoo framework.
Using a group on field view definition will either show or hide the field. So this is no option for you. And using the field options you've mentionted will always "hide" create/edit without a group control behind it.
I would go with the field options, because products can also be created on other places, for example in the products menues, where you can use the normal odoo access possibilities.
Upvotes: 0