31 lines
790 B
Python
31 lines
790 B
Python
from odoo import models,fields
|
|
from ..tools.firebase import send_firebase_notifications
|
|
|
|
class FirebaseService(models.AbstractModel):
|
|
_name = "firebase.service"
|
|
_description = "Firebase Service"
|
|
|
|
def send_notification(self, messages):
|
|
return send_firebase_notifications(messages)
|
|
|
|
|
|
class ResUsers(models.Model):
|
|
_inherit = "res.users"
|
|
|
|
token = fields.Char(string="Firebase Token")
|
|
|
|
def send_push_notification(self, title, body, data=None):
|
|
self.ensure_one()
|
|
|
|
if not self.token:
|
|
return False
|
|
|
|
return self.env['firebase.service'].send_notification([
|
|
{
|
|
'token': self.token,
|
|
'title': title,
|
|
'body': body,
|
|
'data': data or {},
|
|
}
|
|
])
|