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>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<!-- Menu Item (Ties to the Mobile App Root Menu) -->
|
|
||||||
<menuitem id="menu_mapan_app_notification_history"
|
<menuitem id="menu_mapan_app_notification_history"
|
||||||
name="History"
|
name="History"
|
||||||
parent="menu_mapan_mobile_app_root"
|
parent="menu_mapan_mobile_app_root"
|
||||||
action="action_mapan_app_notification_history"
|
action="action_mapan_app_notification_history"
|
||||||
groups="mapan_loyalty_push.group_mapan_loyalty_push_user"
|
groups="mapan_loyalty_push.group_mapan_loyalty_push_user"
|
||||||
sequence="20"/>
|
sequence="10"/>
|
||||||
|
|
||||||
<!-- Explicit Menu Override to clear and reset group_ids in Database -->
|
<!-- Explicit Menu Override to clear and reset group_ids in Database -->
|
||||||
<record id="menu_mapan_app_notification_history" model="ir.ui.menu">
|
<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)
|
title = fields.Char(string='Notification Title', required=True)
|
||||||
body = fields.Text(string='Notification Body', 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(
|
partner_ids = fields.Many2many(
|
||||||
'res.partner',
|
'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):
|
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
|
# Create the notification record in the DB instead of calling Firebase
|
||||||
self.env['mapan.app.notification'].create({
|
self.env['mapan.app.notification'].create({
|
||||||
'title': self.title,
|
'title': self.title,
|
||||||
'body': self.body,
|
'body': self.body,
|
||||||
'partner_ids': [(6, 0, self.partner_ids.ids)]
|
'partner_ids': [(6, 0, partners.ids)]
|
||||||
})
|
})
|
||||||
|
|
||||||
recipient_count = len(self.partner_ids)
|
recipient_count = len(partners)
|
||||||
target_msg = f"{recipient_count} selected partners" if recipient_count > 0 else "all app users"
|
target_msg = f"{recipient_count} selected partners" if self.recipient_type == 'specific' else "all app users"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.client',
|
'type': 'ir.actions.client',
|
||||||
|
|||||||
@ -8,9 +8,10 @@
|
|||||||
<group>
|
<group>
|
||||||
<field name="title"/>
|
<field name="title"/>
|
||||||
<field name="body"/>
|
<field name="body"/>
|
||||||
|
<field name="recipient_type" widget="radio" options="{'horizontal': true}"/>
|
||||||
</group>
|
</group>
|
||||||
<group string="Recipients">
|
<group string="Recipients" invisible="recipient_type != 'specific'">
|
||||||
<field name="partner_ids" widget="many2many_tags" placeholder="Select customers with app installed..."/>
|
<field name="partner_ids" widget="many2many_tags" placeholder="Select customers who activated their account..." options="{'no_create': True, 'no_open': True}"/>
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
<button name="action_send_push" type="object" string="Send Notification" class="btn-primary" icon="fa-paper-plane"/>
|
<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"
|
parent="menu_mapan_mobile_app_root"
|
||||||
action="action_mapan_push_wizard"
|
action="action_mapan_push_wizard"
|
||||||
groups="mapan_loyalty_push.group_mapan_loyalty_push_manager"
|
groups="mapan_loyalty_push.group_mapan_loyalty_push_manager"
|
||||||
sequence="10"/>
|
sequence="20"/>
|
||||||
|
|
||||||
<!-- Explicit Menu Overrides to clear and reset group_ids in Database -->
|
<!-- Explicit Menu Overrides to clear and reset group_ids in Database -->
|
||||||
<record id="menu_mapan_mobile_app_root" model="ir.ui.menu">
|
<record id="menu_mapan_mobile_app_root" model="ir.ui.menu">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user