odoo/odoo#189441
Created by Stroobant Paul (stpa)
Blocked
- Merge method
- Review
- 
                CI
                - legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
 
- label
- odoo-dev:16.0-opw-4214192-crm_team_member_company-stpa
- head
- 0f345d8f0285a91b3f05cc973a54bd51508c446c
| odoo/odoo | |
|---|---|
| 18.0 | #189441 missing r+ | 
| saas-18.2 | |
| saas-18.3 | |
| saas-18.4 | |
| 19.0 | |
| master | 
[FIX] sales_team: align team member company to team company
Steps to reproduce the issue:
(Easier to reproduce client side with CRM installed)
- Install crm
- Create Second Company
- Create New User with Current Company as Default Company and Second Company in Allowed Companies
- Create CRM Team belonging to Second Company
- Add New User to Members of CRM Team
- Receive error:
> [New User] belongs to company [Current Company] and "Sales Team" (crm_team_id: [CRM Team]) belongs to another company.
Explanation:
crm.team.member is created when adding res.users to crm.team.member_ids. Contrary to res.users, a company_check is done when linking crm.team and crm.team.member together. crm.team.member.company_id is related to user_id.company_id and, in the case above, does not match crm.team.company_id, raising an error because of it.
Fix reasoning:
Removing restriction, as we want to avoid other multi-company issues by changing the behaviour.
@nd-dew note:
Situation recap
So it was proposed to modify the field definition, seems to me that removing check_company from the field definition is a legal move, since it is an ORM level constraint (doesn't change db schema). 
However looking at the tests it seems like this is desired limitation.
Note that #171079 introduced checking for allowed companies, but the default company still takes priority.