Browse Source

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

pull/350/head
Adrià Gil Sorribes 6 years ago
committed by Holger Brunn
parent
commit
7ff8d55b6b
  1. 6
      mail_activity_team/models/mail_activity.py
  2. 8
      mail_activity_team/models/mail_activity_team.py
  3. 2
      mail_activity_team/tests/test_mail_activity_team.py
  4. 2
      mail_activity_team/views/mail_activity_team_views.xml

6
mail_activity_team/models/mail_activity.py

@ -46,11 +46,11 @@ 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:
elif len(self.team_id.member_ids.ids) == 1:
self.user_id = self.team_id.member_ids
elif self.env.user.id in self.team_id.member_ids.ids:
self.user_id = self.env.user
else:
self.user_id = self.env['res.users']

8
mail_activity_team/models/mail_activity_team.py

@ -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:

2
mail_activity_team/tests/test_mail_activity_team.py

@ -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,

2
mail_activity_team/views/mail_activity_team_views.xml

@ -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"

Loading…
Cancel
Save