from odoo import models, fields, api from odoo.exceptions import UserError class PushNotificationWizard(models.TransientModel): _name = 'mapan.push.wizard' _description = 'Send Mobile App Notification' title = fields.Char(string='Notification Title', required=True) body = fields.Text(string='Notification Body', required=True) partner_ids = fields.Many2many( 'res.partner', string='Recipients' ) def action_send_push(self): # Create the notification record in the DB instead of calling Firebase self.env['mapan.app.notification'].create({ 'title': self.title, 'body': self.body, 'partner_ids': [(6, 0, self.partner_ids.ids)] }) recipient_count = len(self.partner_ids) target_msg = f"{recipient_count} selected partners" if recipient_count > 0 else "all app users" return { 'type': 'ir.actions.client', 'tag': 'display_notification', 'params': { 'title': 'App Notification Dispatched', 'message': f'Message successfully staged for {target_msg}!', 'type': 'success', 'sticky': False, } }