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 }