[18.0][FIX] mail_activity_team: enhance _get_default_team_id method to handle user and model IDs#167
Conversation
|
@StefanRijnhart I think we broke part of the module with the mast change. Could you review this fix. |
DorianMAG
left a comment
There was a problem hiding this comment.
Code review.
Functional test OK.
Thx for the fix.
LGTM
StefanRijnhart
left a comment
There was a problem hiding this comment.
Give me a moment to check if I can fix this in the wizard itself
|
Here's a solution that reuses the method without reverting to its old signature: #168 It includes tests. What do you think? |
| @api.model | ||
| def _get_default_team_id(self, user_id=None, model_id=None): | ||
| if not user_id: | ||
| user_id = self.user_id.id or self.env.user.id | ||
| if not model_id: | ||
| model_id = self.res_model_id.id if self.res_model_id else None | ||
| domain = [] | ||
| domain.append(("member_ids", "=", self.user_id.id or self.env.user.id)) | ||
| if self.res_model_id: | ||
| domain.append(("member_ids", "=", user_id)) | ||
| if model_id: | ||
| domain += [ | ||
| "|", | ||
| ("res_model_ids", "=", False), | ||
| ("res_model_ids", "=", self.res_model_id.id), | ||
| ("res_model_ids", "=", model_id), | ||
| ] | ||
| if not domain: | ||
| return self.env["mail.activity.team"] | ||
| teams = self.env["mail.activity.team"].search(domain) | ||
| if self.res_model_id: | ||
| if model_id: | ||
| # Prefer teams with a matching model | ||
| teams = ( | ||
| teams.filtered(lambda mat: self.res_model_id in mat.res_model_ids) | ||
| teams.filtered( | ||
| lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids | ||
| ) | ||
| or teams | ||
| ) | ||
| return teams[:1] |
There was a problem hiding this comment.
@StefanRijnhart how about this, and we call _get_default_team_by_user_id from the wizard?
| @api.model | |
| def _get_default_team_id(self, user_id=None, model_id=None): | |
| if not user_id: | |
| user_id = self.user_id.id or self.env.user.id | |
| if not model_id: | |
| model_id = self.res_model_id.id if self.res_model_id else None | |
| domain = [] | |
| domain.append(("member_ids", "=", self.user_id.id or self.env.user.id)) | |
| if self.res_model_id: | |
| domain.append(("member_ids", "=", user_id)) | |
| if model_id: | |
| domain += [ | |
| "|", | |
| ("res_model_ids", "=", False), | |
| ("res_model_ids", "=", self.res_model_id.id), | |
| ("res_model_ids", "=", model_id), | |
| ] | |
| if not domain: | |
| return self.env["mail.activity.team"] | |
| teams = self.env["mail.activity.team"].search(domain) | |
| if self.res_model_id: | |
| if model_id: | |
| # Prefer teams with a matching model | |
| teams = ( | |
| teams.filtered(lambda mat: self.res_model_id in mat.res_model_ids) | |
| teams.filtered( | |
| lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids | |
| ) | |
| or teams | |
| ) | |
| return teams[:1] | |
| def _get_default_team_id(self): | |
| return _get_default_team_by_user_id(self.user_id.id or self.env.user.id, self.res_model_id.id) | |
| @api.model | |
| def _get_default_team_by_user_id(self, user_id=None, model_id=None): | |
| domain.append(("member_ids", "=", user_id)) | |
| if model_id: | |
| domain += [ | |
| "|", | |
| ("res_model_ids", "=", False), | |
| ("res_model_ids", "=", model_id), | |
| ] | |
| if not domain: | |
| return self.env["mail.activity.team"] | |
| teams = self.env["mail.activity.team"].search(domain) | |
| if model_id: | |
| # Prefer teams with a matching model | |
| teams = ( | |
| teams.filtered( | |
| lambda mat, model_id=model_id: model_id in mat.res_model_ids.ids | |
| ) | |
| or teams | |
| ) | |
| return teams[:1] |
…le user and model IDs
fd64c3f to
828362e
Compare
StefanRijnhart
left a comment
There was a problem hiding this comment.
Given the test parity with #168, this seems fine to me. Thanks for fixing my mistake!
Fast tracking due to the impact of the bug .
/ocabot merge patch
|
On my way to merge this fine PR! |
|
Congratulations, your PR was merged at c0a9519. Thanks a lot for contributing to OCA. ❤️ |
Introduced by: #149
