feat: add input validation and support for global push notifications in wizard
This commit is contained in:
parent
a37e49e3ed
commit
8737c8a661
@ -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,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user