Skip to Content
Menu
This question has been flagged
1 Reply
4715 Views

Hi,


I want to restrict users to create quotations only to customers who work on certain industries.


Example:

I want the salespeople who sells to Supermarkets to only be able to create quotations to customers that have Supermakert as their industry_id.


What I've done:

-----------------------------------------------------------------------------------------------

1- I've created a Many2many field on res.users:

from odoo import models, fields


class res_users(models.Model):
_inherit = 'res.users'

z_allowed_industries = fields.Many2many('res.partner.industry')

-----------------------------------------------------------------------------------------------

2- Added z_allowed_ind to form view:

<record id="view_users_form_inherit" model="ir.ui.view">
<field name="name">res.users.form.inherit</field>
<field name="model">res.users</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">

<xpath expr="//notebook" position="inside">
<page string="Exta Details">
<field name="z_allowed_ind" widget="many2many_tags"/>
</page>
</xpath>
</field>
</record>

-----------------------------------------------------------------------------------------------

3- Changed the domain on Quotation -> partner_id field:

<field name="partner_id" position="replace">
<field name="partner_id"
widget="res_partner_many2one"
domain="[('parent_id', '!=', False),
('parent_id.industry_id', 'in', 'user_id.z_allowed_ind')]"
/>
</field>

-----------------------------------------------------------------------------------------------


I know that ('parent_id.industry_id', 'in', 'user_id.z_allowed_ind') is not the correct way to do this... but I have no idea how to do it XD


Can anyone help me?


Thanks in advance!

Avatar
Discard
Best Answer

There is an OCA module called web_domain_field which will allow you to set the domain dynamically.

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 20
2079
0
Jun 17
3066
1
Sep 23
1076
1
Sep 22
1361
0
Nov 22
80