-
-
Notifications
You must be signed in to change notification settings - Fork 105
[18.0][IMP] mail_activity_team: assign plan activities to teams #116
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
Open
StefanRijnhart
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
StefanRijnhart:18.0-mail_activity_team-imp-configure_plan_templates_for_teams
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| from . import ir_actions_server | ||
| from . import mail_activity_team | ||
| from . import mail_activity_team # Has to load early | ||
| from . import mail_activity | ||
| from . import mail_activity_mixin | ||
| from . import res_users | ||
| from . import mail_activity_plan_template | ||
| from . import mail_activity_type | ||
| from . import res_users |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| from odoo import api, fields, models | ||
| from odoo.exceptions import ValidationError | ||
|
|
||
|
|
||
| class MailActivityPlanTemplate(models.Model): | ||
| _inherit = "mail.activity.plan.template" | ||
|
|
||
| activity_team_user_id = fields.Many2one( | ||
| comodel_name="res.users", | ||
| compute="_compute_activity_team_user_id", | ||
| readonly=False, | ||
| help="The team member that the activity will be assigned to specifically", | ||
| store=True, | ||
| string="Team user", | ||
| ) | ||
| activity_team_id = fields.Many2one( | ||
| comodel_name="mail.activity.team", | ||
| compute="_compute_activity_team_id", | ||
| ondelete="restrict", | ||
| readonly=False, | ||
| store=True, | ||
| string="Team assigned to", | ||
| ) | ||
| activity_team_required = fields.Boolean( | ||
| compute="_compute_activity_team_required", | ||
| help="Indicate if this plan template must have an activity team", | ||
| ) | ||
| # Add compute method to existing field | ||
| responsible_id = fields.Many2one( | ||
| compute="_compute_responsible_id", | ||
| readonly=False, | ||
| store=True, | ||
| ) | ||
| responsible_type = fields.Selection( | ||
| ondelete={"team": "set default"}, | ||
| selection_add=[("team", "Team")], | ||
StefanRijnhart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| @api.depends("responsible_type") | ||
| def _compute_activity_team_required(self): | ||
| """Hook to override requiredness of activity team""" | ||
| for template in self: | ||
| template.activity_team_required = template.responsible_type == "team" | ||
|
|
||
| @api.depends("activity_team_id", "responsible_type") | ||
| def _compute_activity_team_user_id(self): | ||
| """Ensure consistency between the activity team and the team user""" | ||
| for template in self: | ||
| user = template.activity_team_user_id | ||
| if template.activity_team_required: | ||
| team = template.activity_team_id | ||
| if team: | ||
| if not user or user not in team.member_ids: | ||
| if team.user_id: | ||
| template.activity_team_user_id = team.user_id | ||
| elif len(team.member_ids) == 1: | ||
| template.activity_team_user_id = team.member_ids | ||
| elif user: | ||
| template.activity_team_user_id = False | ||
| elif user: | ||
| template.activity_team_user_id = False | ||
| elif user: | ||
| template.activity_team_user_id = False | ||
|
|
||
| @api.depends("activity_type_id", "responsible_type") | ||
| def _compute_activity_team_id(self): | ||
| """Assign the default team from the activity type""" | ||
| for template in self: | ||
| if template.activity_team_required: | ||
| if template.activity_type_id.default_team_id: | ||
| template.activity_team_id = ( | ||
| template.activity_type_id.default_team_id | ||
| ) | ||
| elif template.activity_team_id: | ||
| template.activity_team_id = False | ||
|
|
||
| @api.depends("responsible_type") | ||
| def _compute_responsible_id(self): | ||
| """Wipe responsible if field is not visible (c.q. allowed)""" | ||
| for template in self: | ||
| if template.activity_team_required and template.responsible_id: | ||
| template.responsible_id = False | ||
|
|
||
| @api.constrains("responsible_type", "activity_team_id") | ||
| def _check_activity_team(self): | ||
| for template in self: | ||
| if template.activity_team_required and not template.activity_team_id: | ||
| raise ValidationError(self.env._("Please enter an activity team.")) | ||
|
|
||
| def _determine_responsible(self, on_demand_responsible, applied_on_record): | ||
| # Avoid signalling an error for a 'team' template without a user. | ||
| self.ensure_one() | ||
| if self.activity_team_required: | ||
| return {"error": False} | ||
| return super()._determine_responsible(on_demand_responsible, applied_on_record) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Shouldn't the schedule_default_team_id be selectable here when Assignemnt is set to "ask at launch":
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.
That could be a future addition, but it is out of scope for us at this point.