From ac7d351627563979bf8d572ea94aede952f8afd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 28 Feb 2012 16:29:01 +0100 Subject: [PATCH 1/6] [ADD] First add of base_needaction file that will serve to get need_action engine out of mail.thread before being eventually moved into server if necessary. bzr revid: tde@openerp.com-20120228152901-biee23bw3ircq6c9 --- addons/mail/__init__.py | 1 + addons/mail/base_needaction.py | 37 ++++++++++++++++++++++++++++ addons/mail/base_needaction_view.xml | 5 ++++ 3 files changed, 43 insertions(+) create mode 100644 addons/mail/base_needaction.py create mode 100644 addons/mail/base_needaction_view.xml diff --git a/addons/mail/__init__.py b/addons/mail/__init__.py index 2474c321946..d74ee2cb644 100644 --- a/addons/mail/__init__.py +++ b/addons/mail/__init__.py @@ -19,6 +19,7 @@ # ############################################################################## +import base_needaction import mail_message import mail_thread import mail_group diff --git a/addons/mail/base_needaction.py b/addons/mail/base_needaction.py new file mode 100644 index 00000000000..887b77faa2e --- /dev/null +++ b/addons/mail/base_needaction.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2009-Today OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see +# +############################################################################## + +import time +import tools +import logging +from osv import osv, fields +from tools.translate import _ + +class base_needaction(osv.osv): + '''TODO + ''' + _name = 'base.needaction' + _description = 'Need action Engine' + + _columns = { + } + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/mail/base_needaction_view.xml b/addons/mail/base_needaction_view.xml new file mode 100644 index 00000000000..cc8d30d080d --- /dev/null +++ b/addons/mail/base_needaction_view.xml @@ -0,0 +1,5 @@ + + + + + From 6763a012051b4922dd5f0eeb41413e0620e2f1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 28 Feb 2012 16:34:55 +0100 Subject: [PATCH 2/6] [IMP] Changed class name to mail.needaction while it is in mail module. bzr revid: tde@openerp.com-20120228153455-zi7rdcwd8ugsot40 --- addons/mail/base_needaction.py | 4 ++-- addons/mail/mail_thread.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/mail/base_needaction.py b/addons/mail/base_needaction.py index 887b77faa2e..1c7797a9072 100644 --- a/addons/mail/base_needaction.py +++ b/addons/mail/base_needaction.py @@ -25,10 +25,10 @@ import logging from osv import osv, fields from tools.translate import _ -class base_needaction(osv.osv): +class mail_needaction(osv.osv): '''TODO ''' - _name = 'base.needaction' + _name = 'mail.needaction' _description = 'Need action Engine' _columns = { diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 85c297fb07f..fbf284c17f7 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -53,6 +53,7 @@ class mail_thread(osv.osv): ''' _name = 'mail.thread' _description = 'Email Thread' + _inherit = ['mail.needaction'] def _get_message_ids(self, cr, uid, ids, name, arg, context=None): res = {} From 02e927fe6b90cb0ab15e910d49737da3163e56f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 28 Feb 2012 18:13:51 +0100 Subject: [PATCH 3/6] [IMP] mail.thread: removed references to need_action_user_id as it is now delegated to mail.need_action mixin class. Adapted behavior of message_create: have to check object need_action_user_id instead of message need_action_user_id. bzr revid: tde@openerp.com-20120228171351-am5v4m2emypgl332 --- addons/mail/mail_thread.py | 42 +++++++++++++++----------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index fbf284c17f7..2b162c47900 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -89,36 +89,41 @@ class mail_thread(osv.osv): # Generic message api #------------------------------------------------------ - def message_create(self, cr, uid, ids, vals, context=None): + def message_create(self, cr, uid, thread_id, vals, context=None): """OpenSocial: wrapper of mail.message create method - creates the mail.message - automatically subscribe the message writer if not already done - push the message to subscribed users""" + if context is None: + context = {} + subscription_obj = self.pool.get('mail.subscription') notification_obj = self.pool.get('mail.notification') # notifications do not come from any user, but from system if vals.get('type') == 'notification': vals['user_id'] = False - if not 'need_action_user_id' in vals: vals['need_action_user_id'] = False if not 'model' in vals: vals['model'] = False if not 'res_id' in vals: vals['res_id'] = 0 need_action_pushed = False + # create message msg_id = self.pool.get('mail.message').create(cr, uid, vals, context=context) + obj = self.browse(cr, uid, [thread_id], context=context)[0] # automatically subscribe the writer of the message if not subscribed if vals['user_id']: - if not self.message_is_subscriber(cr, uid, ids, context=context): - self.message_subscribe(cr, uid, ids, context=context) + if not self.message_is_subscriber(cr, uid, [thread_id], context=context): + self.message_subscribe(cr, uid, [thread_id], context=context) # push the message to suscribed users - users = self.message_get_subscribers(cr, uid, ids, context=context) + users = self.message_get_subscribers(cr, uid, [thread_id], context=context) for user in users: notification_obj.create(cr, uid, {'user_id': user['id'], 'message_id': msg_id}, context=context) - if vals['need_action_user_id'] == user['id']: need_action_pushed = True + # push to need_action_user_id + if obj.need_action_user_id == user['id']: need_action_pushed = True # push to need_action_user_id if user does not follow the object - if vals['need_action_user_id'] and not need_action_pushed: - notification_obj.create(cr, uid, {'user_id': vals['need_action_user_id'], 'message_id': msg_id}, context=context) + if obj.need_action_user_id and not need_action_pushed: + notification_obj.create(cr, uid, {'user_id': obj.need_action_user_id.id, 'message_id': msg_id}, context=context) return msg_id def message_capable_models(self, cr, uid, context=None): @@ -129,8 +134,7 @@ class mail_thread(osv.osv): ret_dict[model_name] = model._description return ret_dict - def message_append(self, cr, uid, threads, subject, body_text=None, - type='email', need_action_user_id=False, + def message_append(self, cr, uid, threads, subject, body_text=None, type='email', email_to=False, email_from=False, email_cc=None, email_bcc=None, reply_to=None, email_date=None, message_id=False, references=None, attachments=None, body_html=None, subtype=None, headers=None, @@ -216,7 +220,6 @@ class mail_thread(osv.osv): 'attachment_ids': [(6, 0, to_attach)], 'state': 'received', 'type': type, - 'need_action_user_id': need_action_user_id, } if email_from: @@ -248,7 +251,7 @@ class mail_thread(osv.osv): } #mail_message.create(cr, uid, data, context=context) context['mail.thread'] = True - self.message_create(cr, uid, [thread.id], data, context=context) + self.message_create(cr, uid, thread.id, data, context=context) return True def message_append_dict(self, cr, uid, ids, msg_dict, context=None): @@ -273,7 +276,6 @@ class mail_thread(osv.osv): subject = msg_dict.get('subject'), body_text = msg_dict.get('body_text'), type = msg_dict.get('type'), - need_action_user_id = msg_dict.get('need_action_user_id'), email_to = msg_dict.get('to'), email_from = msg_dict.get('from'), email_cc = msg_dict.get('cc'), @@ -571,8 +573,8 @@ class mail_thread(osv.osv): # Note specific #------------------------------------------------------ - def message_append_note(self, cr, uid, ids, subject, body, type='notification', need_action_user_id=False, context=None): - return self.message_append(cr, uid, ids, subject, body_text=body, type=type, need_action_user_id=need_action_user_id, context=context) + def message_append_note(self, cr, uid, ids, subject, body, type='notification', context=None): + return self.message_append(cr, uid, ids, subject, body_text=body, type=type, context=context) # old log overrided method: now calls message_append_note def log(self, cr, uid, id, message, secondary=False, context=None): @@ -587,16 +589,6 @@ class mail_thread(osv.osv): #return True # old behavior print 'Log diabled, but we do not care currently about that. We want you to have our logs !' #return self.message_append_note(cr, uid, [id], 'System notification', message, context=context) - - def message_mark_done(self, cr, uid, ids, context=None): - """ OpenSocial add: mark a need_action message sa done - Find by: res_id (thread id), model (self._name), need_action_user_id != false - """ - msg_obj = self.pool.get('mail.message') - msg_ids = msg_obj.search(cr, uid, - ['&', '&', ('res_id', 'in', ids), ('model', '=', self._name), ('need_action_user_id', '!=', False)], context=context) - msg_obj.write(cr, uid, msg_ids, {'need_action_user_id': False}, context=context) - return True #------------------------------------------------------ # Subscription mechanism From a39bdef62a811ba9fdbab1809ddf15396caa02bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 28 Feb 2012 18:14:37 +0100 Subject: [PATCH 4/6] [IMP] quickly updated js and xml for new behavior of need_action_user_id. Still un progress, but was for testing. bzr revid: tde@openerp.com-20120228171437-0a2lmj2d1kf9rfqu --- addons/mail/static/src/js/mail.js | 9 ++++++++- addons/mail/static/src/xml/mail.xml | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index d49b7a0768c..bdb6f39e69f 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -77,6 +77,11 @@ openerp.mail = function(session) { display_comments: function (records) { var self = this; + + // temporary verification of need_action_user_id (TODO: better display) + if (this.params.need_action_user_id) { + $('
').text('Need action by ' + this.params.need_action_user_id[1]).appendTo(self.$element.find('div.oe_mail_thread_display')); } + /* WIP: map matched regexp -> records to browse with name */ //_(records).each(function (record) { //self.do_check_internal_links(record.body_text); @@ -222,6 +227,7 @@ openerp.mail = function(session) { }, set_value: function() { + console.log(this); var self = this; this._super.apply(this, arguments); /* hide follow/unfollow/see followers buttons */ @@ -237,7 +243,8 @@ openerp.mail = function(session) { this.fetch_subscribers(); /* create ThreadDisplay widget and render it */ this.$element.find('div.oe_mail_thread_left').empty(); - this.thread_display = new mail.ThreadDisplay(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, 'uid': this.session.uid}); + this.thread_display = new mail.ThreadDisplay(this, {'res_model': this.view.model, 'res_id': this.view.datarecord.id, + 'uid': this.session.uid, 'need_action_user_id': this.view.datarecord.need_action_user_id}); this.thread_display.appendTo(this.$element.find('div.oe_mail_thread_left')); }, diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml index b2cc1e8e0c7..5d36df9fd57 100644 --- a/addons/mail/static/src/xml/mail.xml +++ b/addons/mail/static/src/xml/mail.xml @@ -99,9 +99,6 @@ - - - Need action by - wrote on
From c2d045df3d6da725275c48456d35800e924533bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 28 Feb 2012 18:14:50 +0100 Subject: [PATCH 5/6] [IMP] hr_holidays: updated to new need_action_user_id bzr revid: tde@openerp.com-20120228171450-tweynl073wf34z9m --- addons/hr_holidays/hr_holidays.py | 12 ++++++--- addons/hr_holidays/hr_holidays_view.xml | 3 +++ addons/mail/base_needaction.py | 33 +++++++++++++++++++++++++ addons/mail/mail_message.py | 1 - 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index f63dcf9632d..d5331624350 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -358,6 +358,14 @@ class hr_holidays(osv.osv): # OpenChatter and notifications # ----------------------------- + def get_needaction_user_id(self, cr, uid, ids, name, arg, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + result[obj.id] = False + if (obj.state == 'confirm' and obj.employee_id.parent_id): + result[obj.id] = obj.employee_id.parent_id.user_id.id + return result + def message_get_subscribers(self, cr, uid, ids, context=None): sub_ids = self._message_get_subscribers_ids(cr, uid, ids, context=context); # add the employee and its manager if specified to the subscribed users @@ -377,12 +385,10 @@ class hr_holidays(osv.osv): for obj in self.browse(cr, uid, ids): self.message_append_note(cr, uid, [obj.id], _('System notification'), _("The %s request '%s' has been confirmed and is waiting for validation by the manager.") - % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification', - need_action_user_id = obj.employee_id.parent_id.user_id.id if obj.employee_id.parent_id else False) + % ('leave' if obj.type == 'remove' else 'allocation', obj.name,), type='notification') def holidays_validate_notificate(self, cr, uid, ids, context=None): for obj in self.browse(cr, uid, ids): - self.message_mark_done(cr, uid, [obj.id], context=context) if obj.holiday_status_id.double_validation: self.message_append_note(cr, uid, [obj.id], _('System notification'), _("The %s request '%s' has been validated. A second validation is necessary and is now pending.") diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 2096ae2bc61..2501ce50ad3 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -95,6 +95,9 @@