This question has been flagged
1 Reply
6446 Views

This seems like it probably has a basic answer, but its left me baffled. Why do users (res.users) and companies (res.company) each have a many2one 'partner_id' field? From my testing it seems this corresponding partner is what is used to check access rights rather than the user/company itself. But users and companies inherit from res.partner anyway...so why do they need this separate partner object linked to them?

Can anyone tell me what I am missing here?

Avatar
Discard
Best Answer

For generalization purposes res.partner is used for personal data, regardless whether this is a customer, supplier, company or a user. This makes sense, because otherwise contact data will be spread over several tables. So there is for example only one E-Mail field in the whole system.

res.company does not inherit form res.partner.

res.user inherits from res.partner, but there are 2 types of inheritance (see Developer Docu)

  • _inherit and
  • _inherits

Since res.user uses the second type, it only is related to a res.partner with partner_id. But the fields of res.partner are not directly accessible (with _inherit they would be directly accessible, but the fields would then also be in the res.user table).

_inherits in this case assures that the contact data stay in DB table res_partner instead of res_user

Avatar
Discard
Author

Very useful answer, thank you. Can I further ask, why does res_user have a company_id field if res_partner already has the same field and is meant to handle all the 'personal' data?

Author

In response to my own second-question. I believe I now know the answer to this. User's company_id refers to the currently worked on company whereas the user's partners company_id refers to the company to which the user is actually employed (although it defaults to the admins company). Please correct me if I'm wrong :)