44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from odoo import models, fields, api
|
|
|
|
class AppNotification(models.Model):
|
|
_name = 'mapan.app.notification'
|
|
_description = 'Mobile App Promotional Notification'
|
|
_order = 'create_date desc'
|
|
|
|
title = fields.Char(string='Notification Title', required=True)
|
|
body = fields.Html(string='Notification Body', required=True)
|
|
|
|
# Optional promotional image — Odoo auto-generates image_128 thumbnail
|
|
image = fields.Image(
|
|
string='Notification Image',
|
|
max_width=1024,
|
|
max_height=1024,
|
|
help='Optional image shown in the notification detail screen.'
|
|
)
|
|
image_128 = fields.Image(
|
|
string='Thumbnail',
|
|
related='image',
|
|
max_width=128,
|
|
max_height=128,
|
|
store=True,
|
|
readonly=True,
|
|
)
|
|
|
|
# If no partner_ids are selected, it is broadcast to everyone logically
|
|
partner_ids = fields.Many2many(
|
|
'res.partner',
|
|
string='Selected Customers',
|
|
help='Leave empty to broadcast to all app users.'
|
|
)
|
|
|
|
is_global = fields.Boolean(
|
|
string='Broadcast to All?',
|
|
compute='_compute_is_global',
|
|
store=True
|
|
)
|
|
|
|
@api.depends('partner_ids')
|
|
def _compute_is_global(self):
|
|
for rec in self:
|
|
rec.is_global = not bool(rec.partner_ids)
|