feat: add recipient type selection to push wizard and reorder menu sequences
This commit is contained in:
parent
b6684e34ad
commit
851673d81b
@ -60,13 +60,12 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Menu Item (Ties to the Mobile App Root Menu) -->
|
||||
<menuitem id="menu_mapan_app_notification_history"
|
||||
name="History"
|
||||
parent="menu_mapan_mobile_app_root"
|
||||
action="action_mapan_app_notification_history"
|
||||
groups="mapan_loyalty_push.group_mapan_loyalty_push_user"
|
||||
sequence="20"/>
|
||||
sequence="10"/>
|
||||
|
||||
<!-- Explicit Menu Override to clear and reset group_ids in Database -->
|
||||
<record id="menu_mapan_app_notification_history" model="ir.ui.menu">
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -8,9 +8,10 @@
|
||||
<group>
|
||||
<field name="title"/>
|
||||
<field name="body"/>
|
||||
<field name="recipient_type" widget="radio" options="{'horizontal': true}"/>
|
||||
</group>
|
||||
<group string="Recipients">
|
||||
<field name="partner_ids" widget="many2many_tags" placeholder="Select customers with app installed..."/>
|
||||
<group string="Recipients" invisible="recipient_type != 'specific'">
|
||||
<field name="partner_ids" widget="many2many_tags" placeholder="Select customers who activated their account..." options="{'no_create': True, 'no_open': True}"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_send_push" type="object" string="Send Notification" class="btn-primary" icon="fa-paper-plane"/>
|
||||
@ -40,7 +41,7 @@
|
||||
parent="menu_mapan_mobile_app_root"
|
||||
action="action_mapan_push_wizard"
|
||||
groups="mapan_loyalty_push.group_mapan_loyalty_push_manager"
|
||||
sequence="10"/>
|
||||
sequence="20"/>
|
||||
|
||||
<!-- Explicit Menu Overrides to clear and reset group_ids in Database -->
|
||||
<record id="menu_mapan_mobile_app_root" model="ir.ui.menu">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user