Skip to Content
Menu
This question has been flagged
1 Reply
12826 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"/>
</record>

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>
<field name="groups" eval="[(4, ref('base.group_portal'))]"/>
</record>

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

 

Avatar
Discard
Best Answer

David,

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.

Avatar
Discard
Author

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 ?

Related Posts Replies Views Activity
1
Aug 24
265
1
Jul 24
564
2
Aug 24
2564
1
Sep 24
553
1
Jan 24
343