Nimesh Contractor(Open ERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-chatter_imp-nco into lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
Requested reviews: Atul Patel(OpenERP) (atp-openerp) For more details, see: https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-chatter_imp-nco/+merge/114346 Hello sir, I have add method for count the votes and check items for the kanban. Add description for method and object. Optimize some coding. Thanks, NCO. -- https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp-chatter_imp-nco/+merge/114346 Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-open-chatter-part-4-atp.
=== modified file 'mail_extra/mail_checklist.py' --- mail_extra/mail_checklist.py 2012-07-05 07:25:17 +0000 +++ mail_extra/mail_checklist.py 2012-07-11 07:35:28 +0000 @@ -2,8 +2,8 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>) -# +# Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>). + # 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 @@ -20,60 +20,94 @@ ############################################################################## from osv import osv, fields -import logging -class mail_checklist_item(osv.osv): +class mail_checklist_item(osv.Model): _name = 'mail.checklist.item' _description = 'Mail Checklist Item' + ''' + Mail Checklist Item add new feature checklist in messages. + It add number of checklist Items with comments. + It allows to strike and unstrike Item with progress Bar in particular messages. + msg_id : Message id on which the Items will be added. + name : Item name + done : True If Item checked otherwise False. + ''' _columns = { 'msg_id': fields.many2one('mail.message', 'Message'), - 'name': fields.char('Name', size=128, help='Checklist Item Name.'), + 'name': fields.char('Item Name', size=128, required=True, help='Checklist Item Name.'), 'done': fields.boolean('Done', help="When Item is done then check it."), 'user_id': fields.many2one('res.users', 'Related user', readonly=1), } def action_done(self, cr, uid, check_item_id, check_value, context=None): - if context == None: - context = {} - self.write(cr, uid, check_item_id , {'done': check_value}) - msg_id = self.browse(cr, uid, check_item_id, context=context).msg_id.id - return self.pool.get("mail.message").get_checklist_items(cr, uid, msg_id, context=context) - + """ + Write done checklist Item. + Return Checklist Item Details.(name, id, done) + """ + self.write(cr, uid, check_item_id[0] , {'done': check_value[0]}) + msg_id = self.browse(cr, uid, check_item_id[0], context=context).msg_id.id + return self.pool.get("mail.message").read_checklist_items(cr, uid, [msg_id], context=context) + mail_checklist_item() -class mail_message(osv.osv): - _logger = logging.getLogger(__name__) - - def get_checklist_items(self, cr, uid, message_id, context=None): +class mail_message(osv.Model): + def read_checklist_items(self, cr, uid, ids, context=None): + """ + Find Checklist Item of particular Message Id. + Return Checklist Item Details.(name, id, done) + """ checklist = self.pool.get("mail.checklist.item") - checklist_ids = checklist.search(cr, uid, [("msg_id","=",message_id)]) - return checklist.read(cr, uid, checklist_ids, ['id','name','done']) - + for id in ids: + checklist_ids = checklist.search(cr, uid, [("msg_id","=",id)]) + return checklist.read(cr, uid, checklist_ids, ['id','name','done']) _inherit = 'mail.message' _columns= { 'checklist_item_ids': fields.one2many('mail.checklist.item', 'msg_id', 'CheckItems'), } - - def add_checklist_item(self, cr, uid, msg_id, item_name, context=None): - mail_item = self.pool.get('mail.checklist.item') - return mail_item.create(cr, uid, {'msg_id':msg_id, 'user_id':uid, 'name' : item_name}, context=context) - mail_message() -class mail_thread(osv.osv): +class mail_thread(osv.Model): _inherit = 'mail.thread' - + def message_append_note_checklist(self, cr, uid, ids, subject=None, body=None, parent_id=False, type='notification', subtype='html', items=[], context=None): + '''for creating check items, will work for any model at the creation of thread.''' new_msg_ids = self.message_append_note(cr, uid, ids, subject=subject, body=body, parent_id=parent_id, type=type, subtype=subtype, context=context) check_items = [] mail_message = self.pool.get('mail.message') - for msg in mail_message.browse(cr, uid, new_msg_ids, context): - mail_item = self.pool.get('mail.checklist.item') - for item in items: - item_id = mail_item.create(cr, uid, {'msg_id':msg.id, 'user_id':uid, 'name' : item}, context=context) - check_items.append(item_id) - mail_message.write(cr, uid, msg.id, {'checklist_item_ids': [(6,0,check_items)]}, context) - return True - -class res_users(osv.osv): + mail_item = self.pool.get('mail.checklist.item') + for item in items: + item_id = mail_item.create(cr, uid, {'msg_id':new_msg_ids[0], 'user_id':uid, 'name' : item}, context=context) + check_items.append(item_id) + return mail_message.write(cr, uid, new_msg_ids[0], {'checklist_item_ids': [(6,0,check_items)]}, context) + + def _get_message_ids(self, cr, uid, ids, name, args, context=None): + res = super(mail_thread, self)._get_message_ids(cr, uid, ids, name, args, context=context) + msg_obj = self.pool.get('mail.message') + for key in res.keys(): + vote_list = [] + total_items = 0 + total_done_items = 0 + for msg in res[key]['message_ids']: + msg_id = msg_obj.browse(cr, uid, msg) + # for count the number of done checklist items. + if msg_id.checklist_item_ids: + for item in filter(lambda x:x.done == True , msg_id.checklist_item_ids): + total_done_items += 1 + total_items += len(msg_id.checklist_item_ids) + # Count the number of votes. + if msg_id.vote_ids: + vote_list.append(msg_id.vote_ids) + img_vote = "<img height='12px' width='16px' src='/mail_extra/static/src/img/vote.gif'/>" + img_checklist = "<img height='12px' width='16px' src='/mail_extra/static/src/img/checklist.png'/>" + res[key]['message_summary'] += " <span> %s %d Votes</span> . <span> %s %d/%d</span>"% (img_vote,len(vote_list),img_checklist,total_done_items,total_items) + return res + _columns = { + 'message_summary': fields.function(_get_message_ids, method=True, + type='text', string='Summary', multi="_get_message_ids", + help="Holds the Chatter summary (number of messages, items, votes...). "\ + "This summary is directly in html format in order to "\ + "be inserted in kanban views."), + } + +class res_users(osv.Model): _name = 'res.users' _inherit = ['res.users', 'mail.thread'] === modified file 'mail_extra/mail_vote.py' --- mail_extra/mail_vote.py 2012-06-12 10:19:02 +0000 +++ mail_extra/mail_vote.py 2012-07-11 07:35:28 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>) +# Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -22,44 +22,56 @@ from osv import osv, fields from tools.translate import _ -class mail_vote(osv.osv): +class mail_vote(osv.Model): + ''' + Mail vote feature allow users to like and unlike particular message comment. + It counts the number of votes per document. + ''' _name = 'mail.vote' _description = 'Mail Vote' - _columns = { 'msg_id': fields.many2one('mail.message', 'Message', required=True), 'user_id': fields.many2one('res.users', 'User', required=True), } -class mail_message(osv.osv): +class mail_message(osv.Model): _inherit = 'mail.message' _columns= { 'vote_ids': fields.one2many('mail.vote', 'msg_id', 'Votes'), } - def get_votes(self, cr, uid, message_id, context=None): - message = self.browse(cr, uid, message_id, context) - is_vote_liked = False - vote_count = len(message.vote_ids) - for vote in message.vote_ids: - if vote.user_id.id == uid: - is_vote_liked = True - break - res = { - 'msg_id': message_id, - 'vote_count': vote_count, - 'is_vote_liked': is_vote_liked - } + def get_vote_summary(self, cr, uid, ids, context=None): + ''' + returns the dictionary of msg_id, number of votes and like or unlike the comment. + ''' + for id in ids: + message = self.browse(cr, uid, id, context) + is_vote_liked = False + vote_count = len(message.vote_ids) + for vote in message.vote_ids: + if vote.user_id.id == uid: + is_vote_liked = True + break + res = { + 'msg_id': ids, + 'vote_count': vote_count, + 'is_vote_liked': is_vote_liked + } return res - def vote_subscribe(self, cr, uid, message_id, context=None): + def vote_toggle(self, cr, uid, ids, context=None): + ''' + Toggles when comment is liked or unlike + return the number of votes of particular message. + ''' vote_pool = self.pool.get('mail.vote') vote_count = 0 - message = self.browse(cr, uid, message_id, context) - voters_id = vote_pool.search(cr, uid, [('msg_id', '=', message_id), ('user_id', '=', uid)], context=context) - if not voters_id: - new_vote_id = vote_pool.create(cr, uid, {'msg_id': message_id, 'user_id': uid}, context=context) - else: - vote_pool.unlink(cr, uid, voters_id, context=context) - if message.vote_ids: - vote_count = len(message.vote_ids) + for id in ids: + message = self.browse(cr, uid, id, context) + voters_id = vote_pool.search(cr, uid, [('msg_id', '=', id), ('user_id', '=', uid)], context=context) + if not voters_id: + new_vote_id = vote_pool.create(cr, uid, {'msg_id': id, 'user_id': uid}, context=context) + else: + vote_pool.unlink(cr, uid, voters_id, context=context) + if message.vote_ids: + vote_count = len(message.vote_ids) return vote_count === modified file 'mail_extra/static/src/css/mail_extra.css' --- mail_extra/static/src/css/mail_extra.css 2012-07-05 04:15:00 +0000 +++ mail_extra/static/src/css/mail_extra.css 2012-07-11 07:35:28 +0000 @@ -22,11 +22,6 @@ margin-top: 2px; } -.openerp .oe_checklist{ - padding: 5px; - cursor:pointer; -} - .openerp .oe_checklist_icon{ height: 15px; width: 20px; === modified file 'mail_extra/static/src/js/mail_extra.js' --- mail_extra/static/src/js/mail_extra.js 2012-07-04 09:46:44 +0000 +++ mail_extra/static/src/js/mail_extra.js 2012-07-11 07:35:28 +0000 @@ -122,7 +122,7 @@ render_vote: function(message_id){ var self = this; this.mail_message = new session.web.DataSet(this, 'mail.message'); - this.mail_message.call('get_votes',[parseInt(message_id)]).then(function(result){ + this.mail_message.call('get_vote_summary',[[parseInt(message_id)]]).then(function(result){ if (result){ parent_element = self.find_parent_element(".oe_mail_msg_vote", message_id); vote_element = QWeb.render('VoteDisplay', result); @@ -135,11 +135,11 @@ subscribe_vote: function(message_id){ var self = this; this.mail_message = new session.web.DataSet(this, 'mail.message'); - return this.mail_message.call('vote_subscribe', [parseInt(message_id)]).then(function(result){ + return this.mail_message.call('vote_toggle', [[parseInt(message_id)]]).then(function(result){ self.render_vote(message_id); }); }, - + display_comments: function(records){ res = this._super(records); var self = this; @@ -151,7 +151,7 @@ self.render_checklist_items(record.id); }); }, - + do_comment: function () { var comment_node = this.$element.find('textarea'); var body_text = comment_node.val(); @@ -168,14 +168,14 @@ return this.ds.call('message_append_note_checklist', [[this.params.res_id], 'Reply', body_text, this.params.parent_id, 'comment', 'html', check_items]).then( this.proxy('init_comments')); }, - + do_display_checklist: function (message_id) { var self=this; parent_element = self.find_parent_element(".oe_mail_msg_checklist", message_id); var new_item = $(QWeb.render("AddChecklist", {})); $(parent_element).after(new_item); }, - + find_parent_element: function(name, message_id){ parent_element = false; _.each($(name), function(element){ @@ -185,7 +185,7 @@ }); return parent_element; }, - + calculate_checklist_progress: function(items){ if (items.length == 0) return 0; total_checklist_items = items.length; @@ -198,11 +198,11 @@ checklist_progress = Math.round((done_checklist_items *100)/total_checklist_items); return checklist_progress; }, - + render_checklist_items: function(message_id){ var self = this; this.mail_message = new session.web.DataSet(this, 'mail.message'); - this.mail_message.call('get_checklist_items',[parseInt(message_id)]).then(function(result){ + this.mail_message.call('read_checklist_items',[[parseInt(message_id)]]).then(function(result){ if (result.length){ checklist_progress = self.calculate_checklist_progress(result); parent_element = self.find_parent_element(".oe_mail_msg_checklist", message_id); @@ -214,7 +214,7 @@ } }); }, - + // Strike and unstrike the checklist item. do_strike_checkbox_item: function(message_id, item){ check_item_id = item.attr("data-id"); @@ -222,8 +222,8 @@ checked = item.attr("checked"); self = this; mail_checklist_item = new session.web.DataSet(this, 'mail.checklist.item'); - mail_checklist_item.call('action_done', [parseInt(check_item_id), checked]).then(function (result) { - checklist_progress = self.calculate_checklist_progress(result); + mail_checklist_item.call('action_done', [[parseInt(check_item_id)], [checked]]).then(function (result) { + checklist_progress = self.calculate_checklist_progress(result); progresselement = $(self.find_parent_element(".oe_mail_msg_checklist_progress", message_id)); progresselement.find('.oe_mail_msg_checklist_progress_value').html(checklist_progress + "%"); progresselement.find('.oe_progressbar').attr("value", checklist_progress);
_______________________________________________ Mailing list: https://launchpad.net/~openerp-dev-gtk Post to : [email protected] Unsubscribe : https://launchpad.net/~openerp-dev-gtk More help : https://help.launchpad.net/ListHelp

