[MERGE] Merged with branch modifying the need_action_user_id mechanism. need_action is now a server-side mechanism. Addons only have to inherit from res.needaction to have the possibility to use this mechanism. Overwriting the get_action_user_id method is the way to define when a user_id is requested to perform an action.

bzr revid: tde@openerp.com-20120307092119-o56qgyd1h22gktvw
This commit is contained in:
Thibault Delavallée 2012-03-07 10:21:19 +01:00
commit 89eec3624c
6 changed files with 38 additions and 33 deletions

View File

@ -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.")

View File

@ -95,6 +95,9 @@
<button string="Approved" name="second_validate" states="validate1" type="workflow" icon="gtk-apply" groups="base.group_hr_user"/>
<button string="Set to Draft" name="set_to_draft" states="refuse,validate" type="object" icon="gtk-convert" groups="base.group_hr_user"/>
</group>
<separator string="Temporary Need Action" colspan="4"/>
<field name="need_action_user_id"/>
<newline/>
<field name="message_ids_social" colspan="4" widget="ThreadView" nolabel="1"/>
</page>
</notebook>

View File

@ -184,7 +184,6 @@ class mail_message(osv.osv):
('comment', 'Comment'),
('notification', 'System notification'),
], 'Type', help="Message type: e-mail for e-mail message, notification for system message, comment for other messages such as user replies"),
'need_action_user_id': fields.many2one('res.users', 'Action by user', help="User requested to perform an action"),
}
_defaults = {

View File

@ -53,6 +53,7 @@ class mail_thread(osv.osv):
'''
_name = 'mail.thread'
_description = 'Email Thread'
_inherit = ['res.needaction']
def _get_message_ids(self, cr, uid, ids, name, arg, context=None):
res = {}
@ -88,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):
@ -128,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,
@ -215,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:
@ -247,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):
@ -272,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'),
@ -570,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):
@ -586,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

View File

@ -98,6 +98,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) {
$('<div class="oe_mail_thread_msg"/>').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);
@ -238,6 +243,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 */
@ -253,7 +259,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'));
},

View File

@ -95,9 +95,6 @@
<a href="#" data-res-model='res.users' t-attf-data-res-id='{record.user_id[0]}'><t t-raw="record.user_id[1]"/></a>
</span>
</t>
<t t-if="record.need_action_user_id != false">
- <span class="oe_mail_msg_need_action">Need action by <a href="#"><t t-raw="record.need_action_user_id[1]"/></a></span>
</t>
wrote on <span class="oe_mail_msg_date"><t t-raw="record.date"/></span>
<br />
<span class="oe_mail_msg_body"><t t-raw="record.body_text"/></span>