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

This commit is contained in:
zainab8585 2024-10-10 13:33:55 +02:00
parent cdc8cb98f2
commit 8c17bc70cb
1 changed files with 16 additions and 35 deletions

View File

@ -56,40 +56,21 @@ 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.onchange('stage_id', 'stage_id.is_closed')
def _compute_stage(self):
self.isdone = False
for rec in self:
if rec.stage_id.is_closed:
# Get users from both groups
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
# 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
rec.env['mail.message'].create({
'message_type': "notification",
'body': _("Task %s is done for project %s and needs your action") % (rec.name, project_no),
'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.partner_id],
'model': rec._name,
'res_id': rec.id if rec.id else False, # Ensure res_id exists
'author_id': rec.env.user.partner_id.id if rec.env.user.partner_id else False,
'email_from': rec.env.user.partner_id.email if rec.env.user.partner_id else 'noreply@company.com'
})
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
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
})