mapan_loyalty_push/controllers/main.py
2026-03-21 15:21:52 +07:00

35 lines
1.0 KiB
Python

from odoo import http
from odoo.http import request
class AppNotificationController(http.Controller):
@http.route('/api/loyalty/fetch_notifications', type='json', auth='user', methods=['POST'], csrf=False)
def fetch_notifications(self, **kw):
"""
Endpoint for the Flutter app Background Task and In-App notification center.
"""
user = request.env.user
partner = user.partner_id
last_id = kw.get('last_id', 0)
# Give them global notifications OR notifications tagged explicitly to them
domain = [
('id', '>', last_id),
'|',
('partner_ids', 'in', [partner.id]),
('is_global', '=', True)
]
notifications = request.env['mapan.app.notification'].sudo().search_read(
domain,
['id', 'title', 'body', 'create_date'],
order='create_date desc',
limit=50
)
return {
'status': 'success',
'data': notifications
}