[IMP] Set team responsible as default user when activity is created

This commit is contained in:
Adrià Gil Sorribes 2018-12-21 16:05:49 +01:00 committed by Bernat Puig Font
parent 8458364644
commit 45f7b44848
4 changed files with 18 additions and 12 deletions

View File

@ -46,14 +46,13 @@ class MailActivity(models.Model):
if not self.team_id:
return res
res['domain']['user_id'] = [('id', 'in', self.team_id.member_ids.ids)]
if self.user_id and self.user_id in self.team_id.member_ids:
return res
if self.team_id.user_id:
self.user_id = self.team_id.user_id
elif self.env.user in self.team_id.member_ids.ids:
self.user_id = self.env.user
else:
self.user_id = self.env['res.users']
if self.user_id not in self.team_id.member_ids:
if self.team_id.user_id:
self.user_id = self.team_id.user_id
elif len(self.team_id.member_ids) == 1:
self.user_id = self.team_id.member_ids
else:
self.user_id = self.env['res.users']
return res
@api.multi

View File

@ -46,7 +46,6 @@ class MailActivityTeam(models.Model):
user_id = fields.Many2one(
comodel_name='res.users',
string='Team Leader',
domain="[('id', 'in', member_ids)]",
)
count_missing_activities = fields.Integer(
string="Missing Activities",
@ -59,6 +58,13 @@ class MailActivityTeam(models.Model):
if self.user_id and self.user_id not in self.member_ids:
self.user_id = False
@api.onchange('user_id')
def _onchange_user_id(self):
if self.user_id and self.user_id not in self.member_ids:
members_ids = self.member_ids.ids
members_ids.append(self.user_id.id)
self.member_ids = [(4, member) for member in members_ids]
def assign_team_to_unassigned_activities(self):
activity_model = self.env['mail.activity']
for team in self:
@ -68,4 +74,5 @@ class MailActivityTeam(models.Model):
if team.res_model_ids:
domain.append(('res_model_id', 'in', team.res_model_ids.ids))
missing_activities = activity_model.search(domain)
missing_activities.write({'team_id': team.id})
for missing_activity in missing_activities:
missing_activity.write({'team_id': team.id})

View File

@ -100,7 +100,7 @@ class TestMailActivityTeam(TransactionCase):
self.assertEqual(self.act2.team_id, self.team2)
self.act2.team_id = self.team1
self.act2._onchange_team_id()
self.assertFalse(self.act2.user_id)
self.assertEqual(self.act2.user_id, self.team1.member_ids)
with self.assertRaises(ValidationError):
self.act2.write({
'user_id': self.employee2.id,

View File

@ -27,7 +27,7 @@
<group>
<group name="base">
<field name="name"/>
<field name="user_id" attrs="{'invisible': [('member_ids', '=', [])]}"/>
<field name="user_id"/>
</group>
<group name="models">
<field name="res_model_ids" widget="many2many_tags"