Merge pull request #1722 from expsa/zen_fix_notification_id

Send the notification to appear as a real notification in Odoo
This commit is contained in:
mazenmuhamad 2024-11-10 11:27:07 +02:00 committed by GitHub
commit 53ef65ab82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 3 deletions

View File

@ -122,8 +122,9 @@ class RequestVehicleDelegation(models.Model):
rec.state = 'direct_manager'
def send_notification_to_fleet_tool_group(self):
message_template = 'عزيز {user_name} لديك طلب تفويض بحاجة الى موافقة'
message_template = 'Dear {user_name}, you have an authorization request awaiting approval'
group = self.env.ref('odex_fleet.group_fleet_tool')
users = group.users
@ -131,6 +132,7 @@ class RequestVehicleDelegation(models.Model):
if user.partner_id:
message_body = message_template.format(user_name=user.name)
# Send the notification to appear as a real notification in Odoo
self.env['mail.message'].create({
'message_type': 'notification',
'subtype_id': self.env.ref('mail.mt_comment').id,
@ -140,6 +142,10 @@ class RequestVehicleDelegation(models.Model):
'model': 'request.vehicle.authorization',
'res_id': self.id,
'author_id': self.env.user.partner_id.id,
'notification_ids': [(0, 0, {
'res_partner_id': user.partner_id.id,
'notification_type': 'inbox'
})]
})
def fleet_tool(self):
@ -167,9 +173,9 @@ class RequestVehicleDelegation(models.Model):
vehicle = self.env['vehicle.delegation'].create(vehicle_vals)
_logger.info("Created vehicle delegation: %s", vehicle)
self.state = "fleet_tool"
self.send_notification_to_fleet_tool_group()
self.state = "fleet_tool"
return vehicle