diff --git a/wizard/push_wizard.py b/wizard/push_wizard.py index 656f624..3f98107 100644 --- a/wizard/push_wizard.py +++ b/wizard/push_wizard.py @@ -18,25 +18,31 @@ class PushNotificationWizard(models.TransientModel): ) def action_send_push(self): - # Determine target partners based on recipient type - partners = self.partner_ids if self.recipient_type == 'specific' else self.env['res.partner'] - - # 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, partners.ids)] - }) + if self.recipient_type == 'specific' and not self.partner_ids: + raise UserError('Please select at least one recipient, or switch to "All Activated Members".') + + if self.recipient_type == 'all': + # Leave partner_ids empty → is_global=True → visible to all app users + self.env['mapan.app.notification'].create({ + 'title': self.title, + 'body': self.body, + }) + target_msg = 'all activated app members' + else: + # Specific recipients only + self.env['mapan.app.notification'].create({ + 'title': self.title, + 'body': self.body, + 'partner_ids': [(6, 0, self.partner_ids.ids)], + }) + target_msg = f'{len(self.partner_ids)} selected member(s)' - recipient_count = len(partners) - target_msg = f"{recipient_count} selected partners" if self.recipient_type == 'specific' 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}!', + 'title': 'Notification Sent', + 'message': f'Notification staged for {target_msg}.', 'type': 'success', 'sticky': False, }