diff --git a/addons/lunch/data/lunch_data.xml b/addons/lunch/data/lunch_data.xml index 5e9d0f55e41..4a7c4284977 100644 --- a/addons/lunch/data/lunch_data.xml +++ b/addons/lunch/data/lunch_data.xml @@ -53,6 +53,15 @@ code records.action_cancel() + + + Lunch: Send notifications + + + list + code + records.action_notify() + diff --git a/addons/lunch/models/lunch_order.py b/addons/lunch/models/lunch_order.py index 794b00803c0..d2ea25a8723 100644 --- a/addons/lunch/models/lunch_order.py +++ b/addons/lunch/models/lunch_order.py @@ -35,6 +35,7 @@ class LunchOrder(models.Model): ('confirmed', 'Received'), ('cancelled', 'Cancelled')], 'Status', readonly=True, index=True, default='new') + notified = fields.Boolean(default=False) company_id = fields.Many2one('res.company', default=lambda self: self.env.company.id) currency_id = fields.Many2one(related='company_id.currency_id', store=True) quantity = fields.Float('Quantity', required=True, default=1) @@ -229,3 +230,29 @@ class LunchOrder(models.Model): def action_reset(self): self.write({'state': 'ordered'}) + + def action_notify(self): + self -= self.filtered('notified') + if not self: + return + notified_users = set() + # (company, lang): (subject, body) + translate_cache = dict() + for order in self: + user = order.user_id + if user in notified_users: + continue + _key = (order.company_id, user.lang) + if _key not in translate_cache: + context = {'lang': user.lang} + translate_cache[_key] = (_('Lunch notification'), order.company_id.with_context(lang=user.lang).lunch_notify_message) + del context + subject, body = translate_cache[_key] + user.partner_id.message_notify( + subject=subject, + body=body, + partner_ids=user.partner_id.ids, + email_layout_xmlid='mail.mail_notification_light', + ) + notified_users.add(user) + self.write({'notified': True}) diff --git a/addons/lunch/models/res_company.py b/addons/lunch/models/res_company.py index 95d91d09596..fe9df868291 100644 --- a/addons/lunch/models/res_company.py +++ b/addons/lunch/models/res_company.py @@ -8,3 +8,6 @@ class Company(models.Model): _inherit = 'res.company' lunch_minimum_threshold = fields.Float() + lunch_notify_message = fields.Html( + default="""Your lunch has been delivered. +Enjoy your meal!""", translate=True) diff --git a/addons/lunch/models/res_config_settings.py b/addons/lunch/models/res_config_settings.py index faa8f256f49..8c65ad579e4 100644 --- a/addons/lunch/models/res_config_settings.py +++ b/addons/lunch/models/res_config_settings.py @@ -9,3 +9,4 @@ class ResConfigSettings(models.TransientModel): currency_id = fields.Many2one('res.currency', related='company_id.currency_id') company_lunch_minimum_threshold = fields.Float(string="Maximum Allowed Overdraft", readonly=False, related='company_id.lunch_minimum_threshold') + company_lunch_notify_message = fields.Html(string="Lunch notification message", readonly=False, related="company_id.lunch_notify_message") diff --git a/addons/lunch/views/lunch_orders_views.xml b/addons/lunch/views/lunch_orders_views.xml index 7ee821f4c44..f88744e6e2f 100644 --- a/addons/lunch/views/lunch_orders_views.xml +++ b/addons/lunch/views/lunch_orders_views.xml @@ -46,10 +46,12 @@ + + @@ -66,6 +68,7 @@ + @@ -97,6 +100,9 @@ + + + diff --git a/addons/lunch/views/res_config_settings.xml b/addons/lunch/views/res_config_settings.xml index 27e79e30349..e454a423005 100644 --- a/addons/lunch/views/res_config_settings.xml +++ b/addons/lunch/views/res_config_settings.xml @@ -28,6 +28,22 @@ + + + + Reception notification + + + Send this message to your users when their order has been delivered. + + + + + + + + +