|
@@ -0,0 +1,65 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import datetime
|
|
|
+from openerp import SUPERUSER_ID, api
|
|
|
+from openerp.osv import osv, orm, fields
|
|
|
+
|
|
|
+class mail_notification(osv.Model):
|
|
|
+ _inherit = 'mail.notification'
|
|
|
+
|
|
|
+ _columns = {
|
|
|
+ 'is_notified': fields.boolean('Notified')
|
|
|
+ }
|
|
|
+
|
|
|
+ _defaults = {
|
|
|
+ 'is_notified': False
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @api.cr_uid_ids_context
|
|
|
+ def get_message_notification(self, cr, uid, context=None):
|
|
|
+ notification_data = {}
|
|
|
+ message_obj = self.pool.get('mail.message')
|
|
|
+ current_date = datetime.datetime.utcnow()
|
|
|
+ delta = datetime.timedelta(minutes=5)
|
|
|
+ before_time = (current_date - delta).strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ msg_ids = message_obj.search(cr, uid, [('date', '>=', before_time), ('date', '<', current_date.strftime("%Y-%m-%d %H:%M:%S"))], context=context)
|
|
|
+ if msg_ids:
|
|
|
+ user_id = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
|
|
|
+ domain = [('partner_id', '=', user_id.partner_id and user_id.partner_id.id), ('message_id', 'in', msg_ids), ('is_read', '=', False), ('is_notified', '=', False)]
|
|
|
+ notif_ids = self.search(cr, uid, domain, context=context) or False
|
|
|
+ for notif_id in self.browse(cr, uid, notif_ids, context=context):
|
|
|
+ message_id = message_obj.browse(cr, uid, notif_id.message_id and notif_id.message_id.id or False, context=context)
|
|
|
+ notification_data[notif_id.id] = {
|
|
|
+ 'id': notif_id.id,
|
|
|
+ 'email_from': message_id.email_from.split('<')[0],
|
|
|
+ 'subject': message_id.subject or '-- No Subject --',
|
|
|
+ 'company_id': user_id.company_id.id or False
|
|
|
+ }
|
|
|
+ return notification_data or {}
|
|
|
+ return {}
|
|
|
+
|
|
|
+
|
|
|
+
|