-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,6 +129,19 @@ def _get_default_favorite_user_ids(self): | |
| dashboard_button_name = fields.Char(string="Dashboard Button", compute='_compute_dashboard_button_name') | ||
| dashboard_graph_data = fields.Text(compute='_compute_dashboard_graph') | ||
|
|
||
| @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 commentThe reason will be displayed to describe this comment to others. Learn more. Isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The |
||
| invalid_members = team.crm_team_member_ids.filtered( | ||
| lambda m: team.company_id not in m.user_id.company_ids | ||
| ) | ||
| if invalid_members: | ||
| raise UserError(_("The following team members are not allowed in company '%(company)s' of the Sales Team '%(team)s': %(users)s", | ||
| company=team.company_id.display_name, | ||
| team=team.name, | ||
| users=", ".join(invalid_members.mapped('user_id.name')) | ||
| )) | ||
|
|
||
| @api.depends('sequence') # TDE FIXME: force compute in new mode | ||
| def _compute_is_membership_multi(self): | ||
| multi_enabled = self.env['ir.config_parameter'].sudo().get_param('sales_team.membership_multi', False) | ||
|
|
@@ -224,9 +237,10 @@ def create(self, vals_list): | |
|
|
||
| def write(self, values): | ||
| res = super(CrmTeam, self).write(values) | ||
| # manually launch company sanity check | ||
| if values.get('company_id'): | ||
| self.crm_team_member_ids._check_company(fnames=['crm_team_id']) | ||
|
|
||
| if values.get('company_id'): # Force re-check of memberships constraint for this team | ||
| for team in self: | ||
| team.crm_team_member_ids._constrains_membership() | ||
|
|
||
| if values.get('member_ids'): | ||
| self._add_members_to_favorites() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.