From 07f318dad9fcc4dc875dd63263c5afb1fa363d1d Mon Sep 17 00:00:00 2001 From: zainab8585 Date: Wed, 9 Oct 2024 16:48:31 +0200 Subject: [PATCH] [ADD]ADD notify for done task+add request in project invoice --- .../project_base/models/project_task.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/odex25_project/project_base/models/project_task.py b/odex25_project/project_base/models/project_task.py index 517c0120b..26d9f0cc3 100644 --- a/odex25_project/project_base/models/project_task.py +++ b/odex25_project/project_base/models/project_task.py @@ -56,9 +56,9 @@ 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)) - @api.depends('stage_id','stage_id.is_closed') + @api.depends('stage_id', 'stage_id.is_closed') def _compute_stage(self): - self.isdone=False + self.isdone = False for rec in self: if rec.stage_id.is_closed: # Get users from both groups @@ -68,22 +68,28 @@ class ProjectTask(models.Model): # Combine both user sets user_ids = manager_users | department_manager_users + # Ensure project exists and is valid + if rec.project_id: + project_no = rec.project_id.project_no or "Unknown Project No" + else: + project_no = "Unknown Project" + # Create a mail notification for users in both groups self.env['mail.message'].create({ 'message_type': "notification", - 'body': _("Invoice request created for project %s and needs your action") % rec.project_id.project_no, + 'body': _("Task %s is done for project %s and needs your action") % (rec._name, project_no), 'subject': _("Invoice Request"), '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.partner_id], + 'notification_ids': [(0, 0, { + 'res_partner_id': user.partner_id.id, + 'notification_type': 'inbox' + }) for user in user_ids if user.partner_id], 'model': rec._name, - 'res_id': rec.id, - 'author_id': self.env.user.partner_id.id if self.env.user.partner_id else False + 'res_id': rec.id if rec.id else False, # Ensure res_id exists + 'author_id': self.env.user.partner_id.id if self.env.user.partner_id else False, + 'email_from': self.env.user.partner_id.email if self.env.user.partner_id else 'noreply@company.com' }) - - -