[FIX] partners user sharing between all companies.
Changelog
- [ADD] New cron to update all
company_ids
of partners with users related to thecompany_ids
of theres.user
model. - [ADD] 3 new
ir.rule
to only show themail.message
,mail.activity
andmail.followers
to thecompany_ids
of the active user. Example - [ADD] Added dependency to
partner_multi_company
in manifest and setuptools. This module modifies some behaviours to be aware:- Modify the field
company_id
tocompany_ids
to allow multiple relations. -
company_id
field can still be used to create partners and is assigned correctly tocompany_ids
- When updated or created, the field
company_ids
of ares.user
thecompany_ids
of the partner is automatically updated, but not the other way around. We can then allow sharing a partner-user to a company that it doesn't have access by manually assigning the company in the partner.
- Modify the field
Known bugs.
- #29 When used at sign "@" to call a user A that is not accessible by the user B, the link is shown without error but cause access error on click. To solve this we should modify some core aspect of the Odoo as this call is not controlled by record relations.
Roadmap
- When removed user from a company, all the historic mail records are invisible we should make them anonymous or something to still show them.
Problem analysis
!76 (closed) related closed merge
Odoo shares res.partner
between all the companies when there are users related to them to be able to show that information when there is interaction in a shared record like in a mail.activity
or last user interaction...
Record rule for partner computes partner_share
and set it True
if user is odoo-bot or has a user related to them and it have internal user group
.
<record model="ir.rule" id="res_partner_rule"> <field name="name">res.partner company</field> <field name="model_id" ref="base.model_res_partner"/> <!-- We exclude partners that have internal users ('partner_share' field) from the multi-company rule because it might interfere with the user's company rule and make some users unselectable in relational fields. This means that partners of internal users are always visible, not matter the company setting. --> <field name="domain_force">['|', '|', ('partner_share', '=', False), ('company_id', 'in', company_ids), ('company_id', '=', False)]/field> </record>
Fix 1
Use partner_multi_company
oca module. https://github.com/OCA/multi-company/tree/14.0/partner_multi_company
This module allows relating multiple companies to partners and modifies.
Also modifies the ir.rule
of partner to ONLY filter by company_ids
, this cause an error when accessing a record that has information related to a user. It does not block access to the record, only to the field related to user.
If we implement this solution we need to be update partner to be the same as the company_ids from the user related as this is not done automatically and can cause these errors.
This fix will work if we can assure that there will be no shared records between a company that relate to a user that is not from that company. But this can happen in a lot of cases like if we remove access to CE will still have old records where this user interacted with them.
Fix 2
Use a domain for the action window of res.partner
. We can filter when entering the views to only show the correct partners, users will still be able to see the partner users via URL but when odoo will be able to show correctly and without error in the shared records.
Fix 3
Apply the 2 solutions. There is no documentation on why the ir.rule
of res.partner
was added that way in partner_multi_company
module but if we change it to contemplate also partners users we can solve the problems of permissions and if we apply the domain it only will show when needed by odoo.