Skip to Content
Menu
This question has been flagged
8 Replies
3986 Views

please tell me i am not able to do this please how would be domain. 

Avatar
Discard
Author

i have added a relation field department_id to project.project model ..and my domain is [('department_id', '=', user.employee_id.department_id.id)]. still i am not able to see projects

Best Answer

Hello Paidy, 

Can you explain more conditions?

Also in the project screen is two scenario - 

1. Project manager 

2. Project Team


Also, there is any field related to the department_id on the project screen?

Avatar
Discard
Author

hi manish yes there is ..i have added department_id to project.project model

Ok so you can add a record rule in the group:

like condition for manager group (assume - project manager can see department wise project)

[('department_id', 'in', user.department_id)]

Author

my domain looks [('department_id','=',user.employee_id.department_id)]...but it is not working

In the project screen - project manager field name is user_id.

so you can try this

[('department_id','=',user_id.employee_id.department_id)]

Author

showing value error manish. there is no user_id

ValueError: <class 'NameError'>: "name 'user_id' is not defined" while evaluating

"[('department_id', 'in', user_id.employee_id.department_id)]"

"[('department_id', '=', user_id.employee_id.department_id.id)]"

you can try this.

Author

small change "[('department_id', '=', 'user_id.employee_id.department_id.id')]....it is worked thanks for your efforts manish

Author

manish now i added more than one department to employee so that based on departments i want to display projects i have added domain[ ('department_id', 'in', ['user_id.employee_id.department_ids'])] but only one department is appearing is my domain correct .in my department_ids field is many2many field it contains 2 departments.

have you added many2many department in project screen or employee screen?

Author

yes added in employee screen please help me i am working on it from morning still i am not able to get it

domain [ ( 'department_id', 'in', user.employee_id.department_ids.ids)]

Try this

[ ( 'your_many2many_filed', 'in', user.employee_id.your_many2many_filed.ids)]

Author

i am not added many2many field in project.project model ..i have added in hr.employee screen.

ur domain throwing error ValueError: Invalid field 'department_ids' in leaf "<osv.ExtendedLeaf: ('department_ids', 'in', []) on project_project (ctx: )>"

Best Answer

You should use record rules. Here is how I did something similar in my own module:

My module had three user groups. Group A, B and C. Records were classified based on their category. Categories A, B and C. A user in groups A and B could see records from categories A and B but could not see records from category C. 

Here is the python code I used in my models and the record rule I created to make it happen.

class MyCategories(models.Model):
    _name = "my.category"
    
    name = fields.Char(string="Category", required=True)
    # You can create your own groups or use existing groups.
    groups = fields.Many2many(comodel_name="res.groups", required=True)

class MyModel(models.Model):
    _name = "my.model"
    
    # All your other fields...
    category = fields.Many2one(string="Category", required=True, comodel_name="my.category")
    allowed_groups = fields.Many2many(comodel_name="res.groups", related="category.groups", store=False)

Now that I have the allowed user groups in my model I can create a record rule to filter them out. 

<record id="document_access" model="ir.rule">
        <field name="name">Documents only in the user's categories</field>
        <field  name="model_id" ref="model_my_model"/>
        <field name="domain_force">[('allowed_groups', 'in', user.groups_id.ids)]</field>
</record>

After a brief look at the source code from the project module in Odoo 12 you will probably have to extend "project.project" to add a field which states the department_ids that are allowed to access it. The domain rule will probably look like this:

<field name="domain_force">[('allowed_departments', 'in', user.department_id)]</field>

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 23
12010
0
Oct 23
33
3
Oct 23
787
1
Oct 23
569
1
Aug 23
983