-
Couldn't load subscription status.
- Fork 30.2k
[FIX] sales_team: align team member company to team company #189441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 18.0
Are you sure you want to change the base?
[FIX] sales_team: align team member company to team company #189441
Conversation
8bea5a0 to
18968fa
Compare
|
Don't we need to generate translations for the error that you added 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would add note that "crm" module is needed to reproduce.
b5c7352 to
77ccaf3
Compare
78543f4 to
471e474
Compare
|
Taking over the PR, recap: on the write
Reconsidering STPA solution, it was rather deep for 16 version as it modified field. Experiment: can we actually skip thee additional check in the |
87a1bdb to
6941f8a
Compare
|
Experiment 1: Not sure what's the purpose of that manual check, but it doesn't matter in this case. reverting EDIT: The purpose of the manual check was the same as in my PR, so to enforce constraint both ways (when writing on crm_team) |
6941f8a to
0257bbf
Compare
Moved company check into a constraintInferred SpecsBefore doing so grabbing all requirements from tests and related task to ensure consistency MotivationSeems like this case wasn't considered at the time and it is possible to fix that and by using api.constraint, so why not since we don't touch db schema, and make constraints cleaner |
c0d050c to
bb41d93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewer, if we're willing to ask for an exception for old stable we could probably just add a related "company_ids" field and get framework support for free.
Probably not worth it though, current fix seems ok.
Leaving mostly documentation comments, just one thing for the test we usually prefer using the test helpers in our modules.
Tested manually, seems to work fine otherwise.
@jeh-odoo 🍞 hi
Do you have an opinion on this? It's relatively touchy so not sure for old stable but it could block valid flows (this comes from a ticket, in the first place)
Would say worth fixing at least in more recent versions, if nothing else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello there
Not the first time I see this feedback I think, and the fix seems ok to me so why not.
I remember reading some mail about fix in older version and the need to be more strict.
So is it considered a bug? I would say yes.
Is it a traceback or a critical issue ? I would say no to this one, and there should be some workaround if I'm not wrong.
Is it a touchy behavior ? Yes.
So I think that I would be more at ease to fix this in a newish version than in 16.0. As a side note, it made me think about the task 2951093.
Cheers!
Re-Target: 16 -> 18Agreed, moving the fix into 18.0 |
bbbc817 to
9d49c47
Compare
4081770 to
d33b416
Compare
d33b416 to
44f4654
Compare
|
oop 🆙 |
|
hey @jeh-odoo, can we merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @nd-dew
Thanks for the reminder on this one 🙂
Had another look and retested the whole thing. Seems good enough for me, just one last picky comment that I saw.
Cheers!
This change ensures users can be members of the Sales Teams
as long as the team's company is in their `company_ids`,
regardless of their default company.
Previously, membership checks relied on the user's default company
(`company_id`), which was too strict in multi-company setups.
This led to errors when assigning a user to a team that belongs to
a company they had access to, but wasn't their default.
Now, validations are handled via an explicit `@api.constrains`,
and enforced on write for both user assignments and team company changes.
Visual specs
---
entities entities
connected connected
to to
company 1 company 2
│ │
│ │
┌─────────────────────────┐
│ │ UserC1C2 │ │
│ default │ │
│ │ │ │
│ allowed allowed │
└─────────────────────────┘
│ │
│ ┌───┴────┐
│ │ TeamC2 │
│ └────────┘
In the above scenario UserC1C2 should be allowed to join TeamC2
- - - - - - - - - - - - - - - -
│ │
┌───┴──────┐ │
│ UserC1 │ │
│ default │ │
│ │ │ │
│ allowed │ │
└───┬──────┘ ┌───┴────┐
│ │ TeamC2 │
│ └────────┘
In the above scenario UserC1 should NOT be allowed to join TeamC2
- - - - - - - - - - - - - - - - - -
│ │
┌───┴──────┐ ─ ─┴─ ─ ──
│ UserC1 │ │ │
│ default ├──X─►
│ │ │ │ │
│ allowed │
└───┬──────┘ └─ ─┬─ ─ ─ ┘
┌───┴────┐ ┌ ─ └─ ─ ┐
│ TeamC1 ├───X─►│
└───┬────┘ ─ ─┬─ ─ ┘
In the above scenario UserC1 should be allowed to joing TeamC1
,but after he does:
we can't move him to another company (case above)
nor we can't switch team to another company (also case above)
- - - - - - - - - - - - - - - - - -
Reproduce
---
1. Create Second Company
2. Create New User with Current Company as Default Company and Second Company in Allowed Companies
3. Create CRM Team belonging to Second Company <--- HERE I can't do that, need to be in the 2nd company
4. Add New User to Members of CRM Team
5. Receive error:
Error
```
[New User] belongs to company [Current Company] and "Sales Team" (crm_team_id: [CRM Team]) belongs to another company.
```
References
---
(ref.1)
[REF] sales_team: improve multi company management
6bacc1c
opw-4214192
|
Revisiting this! Thanks you all for reviews. Applied all suggestions. I went over this one more time and I've noticed one edge-case that isn't covered. I solve that by one more constraint on the CrmTeam ;) |
44f4654 to
0f345d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zboing
|
|
||
| @api.constrains('company_id') | ||
| def _constrain_company_members(self): | ||
| for team in self.filtered('company_id'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't _check_company called by _check_company_auto sufficient ? Looking quickly at the code, if we change company_id, it should recompute constraints of relational fields. But I see we did not define check_company on specific fields ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, seems like moving it to crm_team_mamber_ids field seem to work in the same way
The check_company cannot replace the custom constrains method because it only checks the company_id against the main record's company_id.
It does not consider allowed companies unless the model defines company_ids, which crm.team does not.
... it would take us back to the error we started with
Trying tor reduce the constrains method with
|


Steps to reproduce the issue:
(Easier to reproduce client side with CRM installed)
Explanation:
crm.team.memberis created when addingres.userstocrm.team.member_ids. Contrary tores.users, a company_check is done when linkingcrm.teamandcrm.team.membertogether.crm.team.member.company_idis related touser_id.company_idand, in the case above, does not matchcrm.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.
opw-4214192
@nd-dew note:

Situation recap
So it was proposed to modify the field definition, seems to me that removing
check_companyfrom 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.