Update project_task.py

This commit is contained in:
zainab2097 2024-10-10 16:26:00 +03:00 committed by GitHub
parent ffc4316289
commit 54ce329636
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 22 deletions

View File

@ -32,6 +32,30 @@ class ProjectTask(models.Model):
if record.weight < 0 or record.weight > 100:
raise ValidationError(_("The weight must be between 0 and 100."))
def write(self, vals):
res = super(project, self).write(vals)
if 'stage_id' in vals and vals.get('stage_id'):
manager_users = self.env.ref('project.group_project_manager').users
department_manager_users = self.env.ref('project_base.group_project_department_manager').users
# Combine both user sets
user_ids = manager_users | department_manager_users
for task in self:
if task.stage_id.is_closed:
task.env['mail.message'].create({
'message_type': "notification",
'body': _("Task %s is done for project %s and needs your action") % (
task.name, task.project_id.name or ""),
'subject': _("Done Task"),
'partner_ids': [(6, 0, user_ids.mapped('partner_id').ids)],
'notification_ids': [(0, 0, {'res_partner_id': user.partner_id.id, 'notification_type': 'inbox'})
for user in user_ids if user_ids],
'model': task._name,
'res_id': task.id,
'author_id': self.env.user.partner_id and self.env.user.partner_id.id
})
# self._send_state_change_notification()
return res
@api.onchange('weight')
def _onchange_weight(self):
done_task = self.env['project.task'].search([('phase_id', '=', self.phase_id.id),('id','!=',self._origin.id)])
@ -56,25 +80,4 @@ class ProjectTask(models.Model):
_("Total planned hours for all tasks in stage %s must not exceed Total stage hours %s") % (
record.phase_id.display_name, record.phase_hours))
def _send_state_change_notification(self):
manager_users = self.env.ref('project.group_project_manager').users
department_manager_users = self.env.ref('project_base.group_project_department_manager').users
# Combine both user sets
user_ids = manager_users | department_manager_users
if self.stage_id.is_closed:
self.env['mail.message'].create({
'message_type': "notification",
'body': _("Task %s is done for project %s and needs your action") % (self.name, self.project_id.project_no or ""),
'subject': _("Done Task"),
'partner_ids': [(6, 0, user_ids.mapped('partner_id').ids)],
'notification_ids': [(0, 0, {'res_partner_id': user.partner_id.id, 'notification_type': 'inbox'})
for user in user_ids if user_ids],
'model': self._name,
'res_id': self.id,
'author_id': self.env.user.partner_id and self.env.user.partner_id.id
})
@api.onchange('stage_id', 'stage_id.is_closed')
def _compute_stage(self):
self._send_state_change_notification()