Odoo Help


This community 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.


Domain_force expression with one2many

on 11/18/13, 5:49 AM 1,687 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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


Asked: 11/18/13, 5:49 AM
Seen: 1687 times
Last updated: 3/16/15, 8:10 AM