[ADD]ADD notify for done task+add request in project invoice

This commit is contained in:
zainab8585 2024-10-09 16:48:31 +02:00
parent 8bb4059dce
commit 07f318dad9
1 changed files with 16 additions and 10 deletions

View File

@ -56,9 +56,9 @@ class ProjectTask(models.Model):
_("Total planned hours for all tasks in stage %s must not exceed Total stage hours %s") % ( _("Total planned hours for all tasks in stage %s must not exceed Total stage hours %s") % (
record.phase_id.display_name, record.phase_hours)) 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): def _compute_stage(self):
self.isdone=False self.isdone = False
for rec in self: for rec in self:
if rec.stage_id.is_closed: if rec.stage_id.is_closed:
# Get users from both groups # Get users from both groups
@ -68,22 +68,28 @@ class ProjectTask(models.Model):
# Combine both user sets # Combine both user sets
user_ids = manager_users | department_manager_users 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 # Create a mail notification for users in both groups
self.env['mail.message'].create({ self.env['mail.message'].create({
'message_type': "notification", '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"), 'subject': _("Invoice Request"),
'partner_ids': [(6, 0, user_ids.mapped('partner_id').ids)], 'partner_ids': [(6, 0, user_ids.mapped('partner_id').ids)],
'notification_ids': [(0, 0, {'res_partner_id': user.partner_id.id, 'notification_type': 'inbox'}) 'notification_ids': [(0, 0, {
for user in user_ids if user.partner_id], 'res_partner_id': user.partner_id.id,
'notification_type': 'inbox'
}) for user in user_ids if user.partner_id],
'model': rec._name, 'model': rec._name,
'res_id': rec.id, '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 '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'
}) })