Odoo Help


commercial_partner_id field on res.user instead of res.partner

David Bertha
on 7/17/15, 6:03 AM 2,337 views

Some ir.rules have a reference to user.commercial_partner_id but this is not an attribute of res.user, this is an attribute of res.partner.

Example in base module :

<record model="ir.rule" id="res_partner_portal_public_rule">
<field name="name">res_partner: portal/public: read access on my commercial partner</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="domain_force">[('id', 'child_of', user.commercial_partner_id.id)]</field>
<field name="groups" eval="[(4, ref('base.group_portal')), (4, ref('base.group_public'))]"/>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
<field name="perm_write" eval="False"/>

A correct example in portal_project :

<record id="portal_project_rule" model="ir.rule">
<field name="name">Project: portal users: public, portal or following</field>
<field name="model_id" ref="project.model_project_project"/>
<field name="domain_force">[
'|','|', ('privacy_visibility', '=', 'public'),
'&', ('privacy_visibility', '=', 'portal'),
('message_follower_ids', 'child_of', [user.partner_id.commercial_partner_id.id]),
('privacy_visibility', '=', 'followers'),
('message_follower_ids', 'in', [user.partner_id.id])
<field name="groups" eval="[(4, ref('base.group_portal'))]"/>

The first rule should throw an error in my opinion, but it doesn't.




The reason why it is not throwing error is due to following fact,

res.user class is itself inherited from res.partner. ( You can see this /openerp/addons/base/res/res_users.py file )

class res_users(osv.osv):
""" User class. A res.users record models an OpenERP user and is different
from an employee.
res.users class now inherits from res.partner. The partner model is
used to store the data related to the partner: lang, name, address,
avatar, ... The user model is now dedicated to technical data.
__admin_ids = {}
_uid_cache = {}
_inherits = {
'res.partner': 'partner_id',

_name = "res.users"
_description = 'Users'

So just like relation between,

1. Product & Product template

2. Project & Analytic Account

3. Mail & Message 

there is relation between User & Partner

So when system is going to evaluate user.commercial_partner_id.id field, actually commercial_partner_id field of the partner, which is associated with that user, will be accessed. 

That is why there is no error. 

I hope this is clear now.

Thanks for clearing my head about this. I was relying on "Settings ->Technical -> Database Structure -> Models" to know what fields a model have, but it doesn't show inherited fields nor inherited models. Can we consider this as a one2one relationship, mandatory for user ? What's the benefit ? Just reducing the string length to access partner data ?

David Bertha
on 7/17/15, 7:58 AM

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: 7/17/15, 6:03 AM
Seen: 2337 times
Last updated: 7/17/15, 7:43 AM