Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD]-desktop_notifications: Module added #588

Open
wants to merge 18 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions desktop_notification/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

====================
Desktop Notification
====================

This module was written to extend the functionality of notification


Credits
=======

Contributors
------------

* Lesmed Gutiérrez <[email protected]>
* Glen Sojo <[email protected]>


Maintainer
----------

.. image:: https://avatars0.githubusercontent.com/u/7594691?v=3&s=200
:alt: ClearCorp
:target: http://clearcorp.cr

This module is maintained by ClearCorp.
5 changes: 5 additions & 0 deletions desktop_notification/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 ClearCorp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
23 changes: 23 additions & 0 deletions desktop_notification/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# © 2016 ClearCorp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Desktop Notification',
'summary': 'Desktop notification',
'version': '8.0.1.0.1',
'category': 'Social Network',
'website': 'http://clearcorp.cr',
'author': 'ClearCorp',
'license': 'AGPL-3',
'sequence': 10,
'application': False,
'installable': True,
'auto_install': False,
'depends': [
'base', 'mail', 'im_chat'
],
'data': [
'views/assets.xml'
]
}
79 changes: 79 additions & 0 deletions desktop_notification/i18n/desktop_notification.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * desktop_notification
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-04 22:49+0000\n"
"PO-Revision-Date: 2016-04-04 22:49+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: desktop_notification
#: field:desktop.message,create_uid:0
#: field:desktop.session,create_uid:0
msgid "Created by"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,create_date:0
#: field:desktop.session,create_date:0
msgid "Created on"
msgstr ""

#. module: desktop_notification
#: field:res.users,desktop_notification_id:0
msgid "Desktop notification id"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,id:0
#: field:desktop.session,id:0
msgid "ID"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,write_uid:0
#: field:desktop.session,write_uid:0
msgid "Last Updated by"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,write_date:0
#: field:desktop.session,write_date:0
msgid "Last Updated on"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,message:0
#: field:desktop.session,message_ids:0
#: model:ir.model,name:desktop_notification.model_mail_message
msgid "Message"
msgstr ""

#. module: desktop_notification
#: field:desktop.session,user_id:0
msgid "Session Users"
msgstr ""

#. module: desktop_notification
#: field:desktop.message,to_id:0
msgid "To id"
msgstr ""

#. module: desktop_notification
#: field:desktop.session,uuid:0
msgid "UUID"
msgstr ""

#. module: desktop_notification
#: model:ir.model,name:desktop_notification.model_res_users
msgid "Users"
msgstr ""

79 changes: 79 additions & 0 deletions desktop_notification/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * desktop_notification
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-04-04 22:49+0000\n"
"PO-Revision-Date: 2016-04-04 22:49+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: desktop_notification
#: field:desktop.message,create_uid:0
#: field:desktop.session,create_uid:0
msgid "Created by"
msgstr "Creado por"

#. module: desktop_notification
#: field:desktop.message,create_date:0
#: field:desktop.session,create_date:0
msgid "Created on"
msgstr "Creado en"

#. module: desktop_notification
#: field:res.users,desktop_notification_id:0
msgid "Desktop notification id"
msgstr "Notificación de escritorio id"

#. module: desktop_notification
#: field:desktop.message,id:0
#: field:desktop.session,id:0
msgid "ID"
msgstr "ID"

#. module: desktop_notification
#: field:desktop.message,write_uid:0
#: field:desktop.session,write_uid:0
msgid "Last Updated by"
msgstr "Última actualización por"

#. module: desktop_notification
#: field:desktop.message,write_date:0
#: field:desktop.session,write_date:0
msgid "Last Updated on"
msgstr "Última actualización en"

#. module: desktop_notification
#: field:desktop.message,message:0
#: field:desktop.session,message_ids:0
#: model:ir.model,name:desktop_notification.model_mail_message
msgid "Message"
msgstr "Mensaje"

#. module: desktop_notification
#: field:desktop.session,user_id:0
msgid "Session Users"
msgstr "Sesión de usuarios"

#. module: desktop_notification
#: field:desktop.message,to_id:0
msgid "To id"
msgstr "Para id"

#. module: desktop_notification
#: field:desktop.session,uuid:0
msgid "UUID"
msgstr "UUID"

#. module: desktop_notification
#: model:ir.model,name:desktop_notification.model_res_users
msgid "Users"
msgstr "Usuarios"

5 changes: 5 additions & 0 deletions desktop_notification/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © <YEAR(S)> ClearCorp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models, desktop_notification
80 changes: 80 additions & 0 deletions desktop_notification/models/desktop_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-
# © 2016 ClearCorp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, api
from Tkconstants import CASCADE
import uuid
import simplejson


class DesktopMessage(models.Model):
_name = 'desktop.message'
to_id = fields.Many2one('desktop.session', ondelete=CASCADE)
message = fields.Char(string='Message', ondelete=CASCADE)

def post(self, uid, uuid, message):
message_id = False
session_obj = self.env['desktop.message']
sessions = session_obj.search([('uuid', '=', uuid)])
notifications = []
for session in sessions:
vals = {
'to_id': session.id,
'message': message
}
message_id = self.create(vals)
data = self.read(['to_id', 'message'])
notifications.append([message_id, data])
self.env['bus.bus'].sendmany(notifications)
return message_id


class DesktopSession(models.Model):
_name = 'desktop.session'
_order = 'id desc'
_rec_name = 'uuid'

@api.one
@api.depends("user_id")
def _compute_uuid(self):
_uuid = uuid.uuid4()
self.uuid = _uuid

uuid = fields.Char(
string='UUID', size=50, select=True, readonly=True,
compute='_compute_uuid', store=True)
message_ids = fields.One2many('desktop.message', 'to_id', string='Message',
ondelete=CASCADE)
user_id = fields.Many2one('res.users', string='Session Users',
ondelete=CASCADE)

@api.model
def session_get(self, user_id):
if user_id:
user_id = self._uid
session_id = self.sudo().search([('user_id', '=', user_id)],
limit=1)
if session_id:
return simplejson.dumps(
{
'id': session_id.id,
'uuid': session_id.uuid,
'user_id': user_id,
})
else:
session_id = self.sudo().create({'user_id': user_id})
return simplejson.dumps(
{
'id': session_id.id,
'uuid': session_id.uuid,
'user_id': user_id,
})


class DesktopUser(models.Model):

_inherit = 'res.users'

desktop_notification_id = fields.One2many(
'desktop.session', 'user_id', required=True)
71 changes: 71 additions & 0 deletions desktop_notification/models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
# © 2016 ClearCorp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, api


class MailMessage(models.Model):
_inherit = 'mail.message'

@api.model
def create(self, vals):
message_id = super(MailMessage, self).create(vals)
bus_obj = self.env['bus.bus']
model = self.env['ir.model'].sudo().search(
[('model', '=', message_id.model)], limit=1)
for partner in message_id.notified_partner_ids:
for user in partner.user_ids:
desktop_session = self.env['desktop.session'].sudo().search(
[('user_id', '=', user.id)])
for session in desktop_session:
notification = [[
session.uuid,
{
'create_date': message_id.create_date,
'to_id': (session.user_id.id, session.uuid),
'message': message_id.body,
'model': model.name,
'record_name': message_id.record_name,
'type': 'notification',
'id': message_id.id,
'from_id': (message_id.author_id.id,
message_id.author_id.name)
}]]
bus_obj.sendmany(notification)
desktop_notification_obj = self.env['desktop.message']
desktop_notification_obj.sudo().create(
{'to_id': session.id, 'message': message_id.body})
return message_id


class ImChatMessage(models.Model):
_inherit = 'im_chat.message'

@api.model
def create(self, vals):
message_id = super(ImChatMessage, self).create(vals)
bus_obj = self.env['bus.bus']
for user in message_id.to_id.user_ids:
if message_id.from_id.id != user.id:
desktop_session = self.env['desktop.session'].sudo().search(
[('user_id', '=', user.id)])
for session in desktop_session:
notification = [[
session.uuid,
{
'create_date': message_id.create_date,
'to_id': (session.user_id.id, session.uuid),
'message': message_id.message,
'model': 'Chat',
'record_name': message_id.message,
'type': 'notification',
'id': message_id.id,
'from_id': (message_id.id,
user.name)
}]]
bus_obj.sendmany(notification)
desktop_notification_obj = self.env['desktop.message']
desktop_notification_obj.sudo().create(
{'to_id': session.id, 'message': message_id.message})
return message_id
Binary file added desktop_notification/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading