Odoo Help


Domain_force expression with one2many

on 11/18/13, 5:49 AM 2,899 views


My goal is to restrict user to access only Partners, which belong to the same company branch as the user. User is linked to company branches through res_users.company_ids field, Partner is linked to company branch through res_partner.branch_id field.

Partner has an additional branch_id field for linking to company branch:

class ResPartner(orm.Model):

    _inherit = 'res.partner'

    _columns = {
        'branch_id': fields.many2one('res.company', 'Branch'),

Access rule:

    <record model="ir.rule" id="partner_rule">
        <field name="name">Access data of partners, which belong to branches that user is assigned to</field>
        <field name="model_id" ref="model_res_partner"/>
        <field name="domain_force">[('branch_id', 'in', [company.id for company in user.company_ids])]</field>
        <field name="groups" eval="[(4, ref('group_employee'))]"/>

This domain_forse expression does work well actually, but my concern is if it is right to do list comprehension, maybe there is another way to achieve this with expressions like 'child_of', etc. without list comprehension?

I have trouble figuring this out, as res_users.company_ids is a one2many.

Thank you in advance.

Mind And Go
On 5/14/14, 5:07 PM


Does the company structure not sufficient for you? Does the branch_id a new data needed by your structure.

If it is child_of works only with parent_id fields (if I remember well) so you won't be able to do better than that except if you override the orm and create new operand to browse hierachy on variable fields

Hope it could help

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/18/13, 5:49 AM
Seen: 2899 times
Last updated: 6/23/17, 4:51 AM