From 54ce3296364d6402bc3a84a39a0b771b6d5107f0 Mon Sep 17 00:00:00 2001 From: zainab2097 <149927291+zainab2097@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:26:00 +0300 Subject: [PATCH] Update project_task.py --- .../project_base/models/project_task.py | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/odex25_project/project_base/models/project_task.py b/odex25_project/project_base/models/project_task.py index 4018ba9c7..b886aad22 100644 --- a/odex25_project/project_base/models/project_task.py +++ b/odex25_project/project_base/models/project_task.py @@ -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() - +