From e61d6bae165444015ef37f71ae1e3c13f42ec253 Mon Sep 17 00:00:00 2001 From: Paramjit Singh Sahota Date: Fri, 5 Apr 2013 19:14:25 +0530 Subject: [PATCH] [IMP] Improved code and passed user_id=None as optional field. bzr revid: psa@tinyerp.com-20130405134425-3xfbbv3vapq1un68 --- addons/mail/mail_thread.py | 10 ++++----- addons/mail/static/src/js/mail_followers.js | 24 +++++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 2527b4cf035..aa929083374 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -112,7 +112,7 @@ class mail_thread(osv.AbstractModel): res[id]['message_summary'] = "9 %d %s" % (title, res[id].pop('message_unread_count'), _("New")) return res - def _get_subscription_data(self, cr, uid, ids, user_id, name, args, context=None): + def _get_subscription_data(self, cr, uid, ids, name, args, user_id=None, context=None): """ Computes: - message_subtype_data: data about document subtypes: which are available, which are followed if any """ @@ -1105,17 +1105,17 @@ class mail_thread(osv.AbstractModel): def message_get_subscription_data(self, cr, uid, ids, user_id=None, context=None): """ Wrapper to get subtypes data. """ - return self._get_subscription_data(cr, uid, ids, user_id, None, None, context=context) + return self._get_subscription_data(cr, uid, ids, None, None, user_id=user_id, context=context) - def message_subscribe_users(self, cr, uid, ids, user_ids=None, partner_id=None, subtype_ids=None, context=None): + def message_subscribe_users(self, cr, uid, ids, user_ids=None, subtype_ids=None, user_id=None, context=None): """ Wrapper on message_subscribe, using users. If user_ids is not provided, subscribe uid instead. """ if user_ids is None: user_ids = [uid] partner_ids = [user.partner_id.id for user in self.pool.get('res.users').browse(cr, uid, user_ids, context=context)] - return self.message_subscribe(cr, uid, ids, partner_ids, partner_id, subtype_ids=subtype_ids, context=context) + return self.message_subscribe(cr, uid, ids, partner_ids, subtype_ids=subtype_ids, user_id=user_id, context=context) - def message_subscribe(self, cr, uid, ids, partner_ids, user_id, subtype_ids=None, context=None): + def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, user_id=None, context=None): """ Add partners to the records followers. """ user_pid = self.pool.get('res.users').read(cr, uid, uid, ['partner_id'], context=context)['partner_id'][0] if user_id: diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index 02cf01d9889..83b46f9f951 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -264,7 +264,7 @@ openerp_mail_followers = function(session, mail) { do_follow: function () { var context = new session.web.CompoundContext(this.build_context(), {}); - this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, context]) + this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], [this.session.uid], undefined, undefined, context]) .then(this.proxy('read_value')); _.each(this.$('.oe_subtype_list input'), function (record) { @@ -288,19 +288,15 @@ openerp_mail_followers = function(session, mail) { var self = this; var checklist = new Array(); - if (partner_id) { - _($('.oe_edit_actions input[type="checkbox"]')).each(function (record) { - if ($(record).is(':checked')) { - checklist.push(parseInt($(record).data('id'))); - } - }); - } else { - _(this.$('.oe_actions input[type="checkbox"]')).each(function (record) { - if ($(record).is(':checked')) { - checklist.push(parseInt($(record).data('id'))); - } - }); - } + var subtype_checkbox = _(this.$('.oe_actions input[type="checkbox"]')) + if (partner_id) { + subtype_checkbox = _($('.oe_edit_actions input[type="checkbox"]')) + } + subtype_checkbox.each(function (record) { + if ($(record).is(':checked')) { + checklist.push(parseInt($(record).data('id'))); + } + }); if (!checklist.length) { if (!this.do_unfollow()) { $(event.target).attr("checked", "checked");