diff --git a/views/app_notification_views.xml b/views/app_notification_views.xml index 865a944..8860141 100644 --- a/views/app_notification_views.xml +++ b/views/app_notification_views.xml @@ -60,13 +60,12 @@ - + sequence="10"/> diff --git a/wizard/push_wizard.py b/wizard/push_wizard.py index 149522b..0115439 100644 --- a/wizard/push_wizard.py +++ b/wizard/push_wizard.py @@ -7,21 +7,29 @@ class PushNotificationWizard(models.TransientModel): title = fields.Char(string='Notification Title', required=True) body = fields.Text(string='Notification Body', required=True) + recipient_type = fields.Selection([ + ('all', 'All Activated Members'), + ('specific', 'Specific Members') + ], string='Send To', default='all', required=True) partner_ids = fields.Many2many( 'res.partner', - string='Recipients' + string='Recipients', + domain=lambda self: [('user_ids.groups_id', 'in', [self.env.ref('base.group_portal').id]), ('user_ids.active', '=', True)] ) 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, self.partner_ids.ids)] + 'partner_ids': [(6, 0, partners.ids)] }) - recipient_count = len(self.partner_ids) - target_msg = f"{recipient_count} selected partners" if recipient_count > 0 else "all app users" + 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', diff --git a/wizard/push_wizard_views.xml b/wizard/push_wizard_views.xml index e7f5918..8e09ec9 100644 --- a/wizard/push_wizard_views.xml +++ b/wizard/push_wizard_views.xml @@ -8,9 +8,10 @@ + - - + +