From ca9c79727541fbf87f316906887e920e79b9550c Mon Sep 17 00:00:00 2001 From: Amit Parik Date: Wed, 5 Sep 2012 17:03:13 +0530 Subject: [PATCH 1/8] [FIX]:project_timesheet impossible to edit task work bzr revid: pja@tinyerp.com-20120905113313-c2cbi37xqr6mnvrc --- addons/project_timesheet/project_timesheet.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 1e50848201c..12d1eedbeb2 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -166,10 +166,7 @@ class project_work(osv.osv): vals_line['name'] = '%s: %s' % (tools.ustr(task.task_id.name), tools.ustr(vals['name']) or '/') if 'user_id' in vals: vals_line['user_id'] = vals['user_id'] - result = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) - for fld in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): - if result.get(fld, False): - vals_line[fld] = result[fld] + if 'date' in vals: vals_line['date'] = vals['date'][:10] @@ -177,7 +174,10 @@ class project_work(osv.osv): default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id vals_line['unit_amount'] = vals['hours'] prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set - + result = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) + for fld in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): + if result.get(fld, False): + vals_line[fld] = result[fld] if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom): vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id']) From c0cc5b01d7727cc643df5ab6dbcfb28cd8bf5490 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 14:16:39 +0200 Subject: [PATCH 2/8] [IMP] code style bzr revid: abo@openerp.com-20121003121639-uv0x4n8j9vyinbrc --- addons/project_timesheet/project_timesheet.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 37dd5eb0707..bfb931ea61d 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -28,6 +28,7 @@ from tools.translate import _ class project_project(osv.osv): _inherit = 'project.project' + def onchange_partner_id(self, cr, uid, ids, part=False, context=None): res = super(project_project, self).onchange_partner_id(cr, uid, ids, part, context) if part and res and ('value' in res): @@ -68,6 +69,7 @@ class project_project(osv.osv): 'nodestroy': True, 'help': help } + project_project() class project_work(osv.osv): @@ -118,7 +120,7 @@ class project_work(osv.osv): vals_line['product_id'] = result['product_id'] vals_line['date'] = vals['date'][:10] - #calculate quantity based on employee's product's uom + # Calculate quantity based on employee's product's uom vals_line['unit_amount'] = vals['hours'] default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id @@ -165,23 +167,24 @@ class project_work(osv.osv): # if a record is deleted from timesheet, the line_id will become # null because of the foreign key on-delete=set null continue + vals_line = {} if 'name' in vals: vals_line['name'] = '%s: %s' % (tools.ustr(task.task_id.name), tools.ustr(vals['name']) or '/') if 'user_id' in vals: vals_line['user_id'] = vals['user_id'] - - if 'date' in vals: vals_line['date'] = vals['date'][:10] if 'hours' in vals: default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id vals_line['unit_amount'] = vals['hours'] prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set + result = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) - for fld in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): - if result.get(fld, False): - vals_line[fld] = result[fld] + for field in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): + if result.get(field, False): + vals_line[field] = result[field] + if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom): vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id']) @@ -203,7 +206,7 @@ class project_work(osv.osv): for task in self.browse(cr, uid, ids): if task.hr_analytic_timesheet_id: hat_ids.append(task.hr_analytic_timesheet_id.id) -# delete entry from timesheet too while deleting entry to task. + # Delete entry from timesheet too while deleting entry to task. if hat_ids: hat_obj.unlink(cr, uid, hat_ids, *args, **kwargs) return super(project_work,self).unlink(cr, uid, ids, *args, **kwargs) @@ -253,6 +256,7 @@ task() class res_partner(osv.osv): _inherit = 'res.partner' + def unlink(self, cursor, user, ids, context=None): parnter_id=self.pool.get('project.project').search(cursor, user, [('partner_id', 'in', ids)]) if parnter_id: @@ -263,6 +267,7 @@ res_partner() class account_analytic_line(osv.osv): _inherit = "account.analytic.line" + def on_change_account_id(self, cr, uid, ids, account_id): res = {} if not account_id: @@ -274,5 +279,7 @@ class account_analytic_line(osv.osv): if acc.state == 'close' or acc.state == 'cancelled': raise osv.except_osv(_('Invalid Analytic Account !'), _('You cannot select a Analytic Account which is in Close or Cancelled state.')) return res + account_analytic_line() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From e9571326e2934680a53f85d0caf41970a9d6fdd2 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 15:01:55 +0200 Subject: [PATCH 3/8] [IMP] variable name bzr revid: abo@openerp.com-20121003130155-s5xw33xcix8pthgc --- addons/project_timesheet/project_timesheet.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index bfb931ea61d..64c81563312 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -105,7 +105,7 @@ class project_work(osv.osv): return res def create(self, cr, uid, vals, *args, **kwargs): - obj_timesheet = self.pool.get('hr.analytic.timesheet') + timesheet_obj = self.pool.get('hr.analytic.timesheet') project_obj = self.pool.get('project.project') task_obj = self.pool.get('project.task') uom_obj = self.pool.get('product.uom') @@ -129,7 +129,7 @@ class project_work(osv.osv): acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False if acc_id: vals_line['account_id'] = acc_id - res = obj_timesheet.on_change_account_id(cr, uid, False, acc_id) + res = timesheet_obj.on_change_account_id(cr, uid, False, acc_id) if res.get('value'): vals_line.update(res['value']) vals_line['general_account_id'] = result['general_account_id'] @@ -139,14 +139,14 @@ class project_work(osv.osv): amount = vals_line['unit_amount'] prod_id = vals_line['product_id'] unit = False - timeline_id = obj_timesheet.create(cr, uid, vals=vals_line, context=context) + timeline_id = timesheet_obj.create(cr, uid, vals=vals_line, context=context) # Compute based on pricetype - amount_unit = obj_timesheet.on_change_unit_amount(cr, uid, timeline_id, + amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, timeline_id, prod_id, amount, False, unit, vals_line['journal_id'], context=context) if amount_unit and 'amount' in amount_unit.get('value',{}): updv = { 'amount': amount_unit['value']['amount'] } - obj_timesheet.write(cr, uid, [timeline_id], updv, context=context) + timesheet_obj.write(cr, uid, [timeline_id], updv, context=context) vals['hr_analytic_timesheet_id'] = timeline_id return super(project_work,self).create(cr, uid, vals, *args, **kwargs) @@ -263,6 +263,7 @@ class res_partner(osv.osv): raise osv.except_osv(_('Invalid Action!'), _('You cannot delete a partner which is assigned to project, but you can uncheck the active box.')) return super(res_partner,self).unlink(cursor, user, ids, context=context) + res_partner() class account_analytic_line(osv.osv): From 1de8b63e9d7708151fb7714a2450e6771c205cea Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 15:08:40 +0200 Subject: [PATCH 4/8] [IMP] variable name, remove unused variables bzr revid: abo@openerp.com-20121003130840-33cf4seornv3jxq6 --- addons/project_timesheet/project_timesheet.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 64c81563312..30c8b380415 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -83,7 +83,7 @@ class project_work(osv.osv): user_name = self.pool.get('res.users').read(cr, uid, [user_id], ['name'])[0]['name'] raise osv.except_osv(_('Bad Configuration !'), _('Please define employee for user "%s". You must create one.')% (user_name,)) - emp = self.pool.get('hr.employee').browse(cr, uid, emp_id[0]) + emp = emp_obj.browse(cr, uid, emp_id[0]) if not emp.product_id: raise osv.except_osv(_('Bad Configuration !'), _('Please define product on the related employee.\nFill in the timesheet tab of the employee form.')) @@ -92,21 +92,20 @@ class project_work(osv.osv): raise osv.except_osv(_('Bad Configuration !'), _('Please define journal on the related employee.\nFill in the timesheet tab of the employee form.')) - a = emp.product_id.product_tmpl_id.property_account_expense.id - if not a: - a = emp.product_id.categ_id.property_account_expense_categ.id - if not a: + acc_id = emp.product_id.product_tmpl_id.property_account_expense.id + if not acc_id: + acc_id = emp.product_id.categ_id.property_account_expense_categ.id + if not acc_id: raise osv.except_osv(_('Bad Configuration !'), _('Please define product and product category property account on the related employee.\nFill in the timesheet tab of the employee form.')) res['product_id'] = emp.product_id.id res['journal_id'] = emp.journal_id.id - res['general_account_id'] = a + res['general_account_id'] = acc_id res['product_uom_id'] = emp.product_id.uom_id.id return res def create(self, cr, uid, vals, *args, **kwargs): timesheet_obj = self.pool.get('hr.analytic.timesheet') - project_obj = self.pool.get('project.project') task_obj = self.pool.get('project.task') uom_obj = self.pool.get('product.uom') @@ -154,7 +153,6 @@ class project_work(osv.osv): if context is None: context = {} timesheet_obj = self.pool.get('hr.analytic.timesheet') - project_obj = self.pool.get('project.project') uom_obj = self.pool.get('product.uom') result = {} From 77b29a2493acbdf9f55ae043cc7866bb4b7defa6 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 15:36:39 +0200 Subject: [PATCH 5/8] [IMP] variable name and code style lp bug: https://launchpad.net/bugs/953006 fixed bzr revid: abo@openerp.com-20121003133639-pd1dhlbdwg5fltya --- addons/project_timesheet/project_timesheet.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 30c8b380415..30630780106 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -112,9 +112,9 @@ class project_work(osv.osv): vals_line = {} context = kwargs.get('context', {}) if not context.get('no_analytic_entry',False): - obj_task = task_obj.browse(cr, uid, vals['task_id']) + task_obj = task_obj.browse(cr, uid, vals['task_id']) result = self.get_user_related_details(cr, uid, vals.get('user_id', uid)) - vals_line['name'] = '%s: %s' % (tools.ustr(obj_task.name), tools.ustr(vals['name']) or '/') + vals_line['name'] = '%s: %s' % (tools.ustr(task_obj.name), tools.ustr(vals['name']) or '/') vals_line['user_id'] = vals['user_id'] vals_line['product_id'] = result['product_id'] vals_line['date'] = vals['date'][:10] @@ -125,7 +125,7 @@ class project_work(osv.osv): default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id if result['product_uom_id'] != default_uom: vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id']) - acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False + acc_id = task_obj.project_id and task_obj.project_id.analytic_account_id.id or False if acc_id: vals_line['account_id'] = acc_id res = timesheet_obj.on_change_account_id(cr, uid, False, acc_id) @@ -232,12 +232,11 @@ class task(osv.osv): if vals.get('project_id',False) or vals.get('name',False): vals_line = {} hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet') - task_obj_l = self.browse(cr, uid, ids, context=context) if vals.get('project_id',False): project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context) acc_id = project_obj.analytic_account_id.id - for task_obj in task_obj_l: + for task_obj in self.browse(cr, uid, ids, context=context): if len(task_obj.work_ids): for task_work in task_obj.work_ids: if not task_work.hr_analytic_timesheet_id: From 19a70c9d2ceb06de56c18613a43aadb125aa8a43 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 16:28:59 +0200 Subject: [PATCH 6/8] [IMP] code style bzr revid: abo@openerp.com-20121003142859-tdskhyqzfwthy9sl --- addons/project_timesheet/project_timesheet.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 30630780106..6711ee613cf 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -98,6 +98,7 @@ class project_work(osv.osv): if not acc_id: raise osv.except_osv(_('Bad Configuration !'), _('Please define product and product category property account on the related employee.\nFill in the timesheet tab of the employee form.')) + res['product_id'] = emp.product_id.id res['journal_id'] = emp.journal_id.id res['general_account_id'] = acc_id @@ -157,7 +158,7 @@ class project_work(osv.osv): result = {} if isinstance(ids, (long, int)): - ids = [ids,] + ids = [ids] for task in self.browse(cr, uid, ids, context=context): line_id = task.hr_analytic_timesheet_id @@ -174,17 +175,18 @@ class project_work(osv.osv): if 'date' in vals: vals_line['date'] = vals['date'][:10] if 'hours' in vals: - default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id vals_line['unit_amount'] = vals['hours'] prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set - result = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) + details = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) for field in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): - if result.get(field, False): - vals_line[field] = result[field] + if details.get(field, False): + vals_line[field] = details[field] - if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom): - vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id']) + # Check if user's default UOM differs from product's UOM + user_default_uom_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id + if details.get('product_uom_id', False) and details['product_uom_id'] != user_default_uom_id: + vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, user_default_uom_id, vals['hours'], details['product_uom_id']) # Compute based on pricetype amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id, From 1786beefa0bc1fd3cd7804060c83fdad9bfbd5e0 Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Wed, 3 Oct 2012 16:38:09 +0200 Subject: [PATCH 7/8] [IMP] add a few comments bzr revid: abo@openerp.com-20121003143809-621gfqzcc2099ph2 --- addons/project_timesheet/project_timesheet.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/project_timesheet/project_timesheet.py b/addons/project_timesheet/project_timesheet.py index 6711ee613cf..12fac7802c6 100644 --- a/addons/project_timesheet/project_timesheet.py +++ b/addons/project_timesheet/project_timesheet.py @@ -151,6 +151,9 @@ class project_work(osv.osv): return super(project_work,self).create(cr, uid, vals, *args, **kwargs) def write(self, cr, uid, ids, vals, context=None): + """ + When a project task work gets updated, handle its hr analytic timesheet. + """ if context is None: context = {} timesheet_obj = self.pool.get('hr.analytic.timesheet') @@ -178,6 +181,7 @@ class project_work(osv.osv): vals_line['unit_amount'] = vals['hours'] prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set + # Put user related details in analytic timesheet values details = self.get_user_related_details(cr, uid, vals.get('user_id', task.user_id.id)) for field in ('product_id', 'general_account_id', 'journal_id', 'product_uom_id'): if details.get(field, False): From 3744f5c402b05edf50bd4562d0daedbc7cbc08e1 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 3 Oct 2012 17:33:06 +0200 Subject: [PATCH 8/8] [REV] Revert last commit, breaks tests bzr revid: odo@openerp.com-20121003153306-e2ugphdyijvq8x6l --- addons/mail/mail_message.py | 184 ++++++++++++-------- addons/mail/mail_message_view.xml | 11 +- addons/mail/mail_thread.py | 8 +- addons/mail/mail_thread_view.xml | 10 +- addons/mail/static/src/css/mail.css | 2 +- addons/mail/static/src/js/mail.js | 37 ++-- addons/mail/static/src/js/mail_followers.js | 5 +- addons/mail/static/src/xml/mail.xml | 9 +- addons/mail/tests/test_mail.py | 42 +++++ addons/mail/wizard/mail_compose_message.py | 1 + 10 files changed, 195 insertions(+), 114 deletions(-) diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index eeefd730f22..bbf68509277 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -134,7 +134,6 @@ class mail_message(osv.Model): 'subtype_id': fields.many2one('mail.message.subtype', 'Subtype'), 'vote_user_ids': fields.many2many('res.users', 'mail_vote', 'message_id', 'user_id', string='Votes', help='Users that voted for this message'), - 'is_private': fields.boolean('Private message'), } def _needaction_domain_get(self, cr, uid, context=None): @@ -222,67 +221,70 @@ class mail_message(osv.Model): 'unread': msg.unread and msg.unread['unread'] or False } - def _message_read_expandable(self, cr, uid, tree, result, message_loaded, domain, context, parent_id, limit): - """ - create the expandable message for all parent message read - this function is used by message_read + def message_read_tree_get_expandable(self, cr, uid, parent_message, last_message, domain=[], current_level=0, level=0, context=None): + """ . """ + base_domain = [('id', '<', last_message['id'])] + if parent_message and current_level < level: + base_domain += [('parent_id', '=', parent_message['id'])] + elif parent_message: + base_domain += [('id', 'child_of', parent_message['id']), ('id', '!=', parent_message['id'])] + if domain: + base_domain += domain + extension = { 'type': 'expandable', + 'domain': base_domain, + 'thread_level': current_level, + 'context': context, + 'id': -1, + } + return extension + + def message_read_tree_flatten(self, cr, uid, parent_message, messages, domain=[], level=0, current_level=0, context=None, limit=None, add_expandable=True): + """ Given a tree with several roots of following structure : + [ {'id': 1, 'child_ids': [ + {'id': 11, 'child_ids': [...] },], + {...} ] + Flatten it to have a maximum number of levels, 0 being flat and + sort messages in a level according to a key of the messages. + Perform the flattening at leafs if above the maximum depth, then get + back in the tree. + :param context: ``sort_key``: key for sorting (id by default) + :param context: ``sort_reverse``: reverser order for sorting (True by default) """ + def _flatten(msg_dict): + """ from {'id': x, 'child_ids': [{child1}, {child2}]} + get [{'id': x, 'child_ids': []}, {child1}, {child2}] + """ + child_ids = msg_dict.pop('child_ids', []) + msg_dict['child_ids'] = [] + return [msg_dict] + child_ids - tree_not = [] - # expandable for not show message - for id_msg in tree: - # get all childs - not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=1000) - # group childs not read - id_min=None - id_max=None - nb=0 - for not_loaded_id in not_loaded_ids: - if not_loaded_id not in tree: - nb+=1 - if id_min==None or id_min>not_loaded_id: - id_min=not_loaded_id - if id_max==None or id_max0: - result.append({ - 'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',id_msg]], - 'nb_messages': nb, - 'type': 'expandable', - 'parent_id': id_msg, - 'id': id_min - }) - id_min=None - id_max=None - nb=0 - if nb>0: - result.append({ - 'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',id_msg]], - 'nb_messages': nb, - 'type': 'expandable', - 'parent_id': id_msg, - 'id': id_min - }) + context = context or {} + limit = limit or self._message_read_limit + # Depth-first flattening + for message in messages: + if message.get('type') == 'expandable': + continue + message['child_ids'] = self.message_read_tree_flatten(cr, uid, message, message['child_ids'], domain, level, current_level + 1, context=context, limit=limit) + for child in message['child_ids']: + if child.get('type') == 'expandable': + continue + message['child_nbr'] += child['child_nbr'] + # Flatten if above maximum depth + if current_level < level: + return_list = messages + else: + return_list = [flat_message for message in messages for flat_message in _flatten(message)] - # expandable for limit max - ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded+tree+tree_not]], context=context, limit=1) - if len(ids) > 0: - result.append( - { - 'domain': domain, - 'nb_messages': 0, - 'type': 'expandable', - 'parent_id': parent_id, - 'id': -1 - }); - - - result = sorted(result, key=lambda k: k['id']) - - return result + # Add expandable + return_list = sorted(return_list, key=itemgetter(context.get('sort_key', 'id')), reverse=context.get('sort_reverse', True)) + if return_list and current_level == 0 and add_expandable: + expandable = self.message_read_tree_get_expandable(cr, uid, parent_message, return_list and return_list[-1] or parent_message, domain, current_level, level, context=context) + return_list.append(expandable) + elif return_list and current_level <= level and add_expandable: + expandable = self.message_read_tree_get_expandable(cr, uid, parent_message, return_list and return_list[-1] or parent_message, domain, current_level, level, context=context) + return_list.append(expandable) + return return_list def message_read(self, cr, uid, ids=False, domain=[], level=0, context=None, parent_id=False, limit=None): """ Read messages from mail.message, and get back a structured tree @@ -298,6 +300,7 @@ class mail_message(osv.Model): further parents :return list: list of trees of messages """ + message_loaded = context and context.get('message_loaded') or [0] # don't read the message display by .js, in context message_loaded list @@ -338,7 +341,58 @@ class mail_message(osv.Model): result = sorted(result, key=lambda k: k['id']) - result = self._message_read_expandable(cr, uid, tree, result, message_loaded, domain, context, parent_id, limit) + + tree_not = [] + # expandable for not show message + for id_msg in tree: + # get all childs + not_loaded_ids = self.search(cr, SUPERUSER_ID, [['parent_id','=',id_msg],['id','not in',message_loaded]], None, limit=1000) + # group childs not read + id_min=None + id_max=None + nb=0 + for not_loaded_id in not_loaded_ids: + if not_loaded_id not in tree: + nb+=1 + if id_min==None or id_min>not_loaded_id: + id_min=not_loaded_id + if id_max==None or id_max0: + result.append({ + 'domain': [['id','>=',id_min],['id','<=',id_max],['parent_id','=',id_msg]], + 'nb_messages': nb, + 'type': 'expandable', + 'parent_id': id_msg, + 'id': id_min + }) + nb=0 + if nb>0: + result.append({ + 'domain': [['id','>=',id_min],['parent_id','=',id_msg]], + 'nb_messages': nb, + 'type': 'expandable', + 'parent_id': id_msg, + 'id': id_min + }) + + + # expandable for limit max + ids = self.search(cr, SUPERUSER_ID, domain+[['id','not in',message_loaded+tree+tree_not]], context=context, limit=1) + if len(ids) > 0: + result.append( + { + 'domain': domain, + 'nb_messages': 0, + 'type': 'expandable', + 'parent_id': parent_id, + 'id': -1 + }); + + + result = sorted(result, key=lambda k: k['id']) return result @@ -472,9 +526,11 @@ class mail_message(osv.Model): self.pool.get('ir.attachment').unlink(cr, uid, attachments_to_delete, context=context) return super(mail_message, self).unlink(cr, uid, ids, context=context) - def _notify_followers(self, cr, uid, newid, message, context=None): + def _notify(self, cr, uid, newid, context=None): """ Add the related record followers to the destination partner_ids. + Call mail_notification.notify to manage the email sending """ + message = self.browse(cr, uid, newid, context=context) partners_to_notify = set([]) # message has no subtype_id: pure log message -> no partners, no one notified if not message.subtype_id: @@ -502,14 +558,6 @@ class mail_message(osv.Model): else: self.write(cr, SUPERUSER_ID, [newid], {'partner_ids': [(3, message.author_id.id)]}, context=context) - def _notify(self, cr, uid, newid, context=None): - """ Add the related record followers to the destination partner_ids if is not a private message. - Call mail_notification.notify to manage the email sending - """ - message = self.browse(cr, uid, newid, context=context) - if message and (message.is_private!=False and message.is_private!=None): - self._notify_followers(cr, uid, newid, message, context=context) - self.pool.get('mail.notification')._notify(cr, uid, newid, context=context) def copy(self, cr, uid, id, default=None, context=None): diff --git a/addons/mail/mail_message_view.xml b/addons/mail/mail_message_view.xml index 6d854d4d701..cc0419352af 100644 --- a/addons/mail/mail_message_view.xml +++ b/addons/mail/mail_message_view.xml @@ -87,15 +87,8 @@ Inbox mail.wall - - - - - Wall - mail.wall - + diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 42b66a53fe5..9f53b4c08b1 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -627,6 +627,7 @@ class mail_thread(osv.AbstractModel): ``(name,content)``, where content is NOT base64 encoded :return: ID of newly created mail.message """ + context = context or {} attachments = attachments or [] assert (not thread_id) or isinstance(thread_id, (int, long)) or \ @@ -678,13 +679,6 @@ class mail_thread(osv.AbstractModel): 'attachment_ids': attachment_ids, 'subtype_id': subtype_id, }) - - # if the parent is private, the message must be private - if parent_id: - msg = messages.browse(cr, uid, parent_id, context=context) - if msg.is_private: - values["is_private"] = msg.is_private - # Avoid warnings about non-existing fields for x in ('from', 'to', 'cc'): values.pop(x, None) diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml index 4b6709dd2d8..3507e7c449f 100644 --- a/addons/mail/mail_thread_view.xml +++ b/addons/mail/mail_thread_view.xml @@ -18,21 +18,15 @@ - - Wall - - - - Archives - + Sent - + diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css index 4ffb9013496..364ac7e3165 100644 --- a/addons/mail/static/src/css/mail.css +++ b/addons/mail/static/src/css/mail.css @@ -370,7 +370,7 @@ bottom: 0px; top: auto; left: auto; - right: 0; + right: 28px; height: 26px; width: 26px; min-width: 22px; diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 8915f1387e1..e0c9ac9b7fc 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -148,8 +148,8 @@ openerp.mail = function(session) { // handle attachment button this.fileupload_id = _.uniqueId('oe_fileupload'); var button_attach = this.$('button.oe_mail_compose_message_attachment'); - var rendered = $( session.web.qweb.render('mail.compose_message.add_attachment', {'widget': this}) ); - rendered.insertBefore(button_attach); + var rendered = session.web.qweb.render('mail.compose_message.add_attachment', {'widget': this}); + $(rendered).insertBefore(button_attach); // move the button inside div.oe_hidden_input_file var input_node = this.$('input[name=ufile]'); button_attach.detach().insertAfter(input_node); @@ -256,10 +256,10 @@ openerp.mail = function(session) { default_res_id: 0, default_parent_id: false }, options.context || {}); - this.id = options.parameters.id || -1; + this.id = -1; this.parent_id= options.parameters.parent_id || false; this.nb_messages = options.parameters.nb_messages || 0; - this.type = 'expandable'; + this.type = options.parameters.type || false; // record options and data this.parent_thread= parent.messages!= undefined ? parent : options.options.thread._parents[0] ; @@ -501,6 +501,9 @@ openerp.mail = function(session) { } else { self.destroy(); } + for(var i in this.thread.messages){ + this.thread.messages[i].animated_destroy({fadeTime:0}); + } }, on_message_delete: function (event) { @@ -595,8 +598,8 @@ openerp.mail = function(session) { display_vote: function () { var self = this; var vote_element = session.web.qweb.render('mail.thread.message.vote', {'widget': self}); - self.$(".placeholder-mail-vote:first").empty(); - self.$(".placeholder-mail-vote:first").html(vote_element); + self.$(".placeholder-mail-vote").empty(); + self.$(".placeholder-mail-vote").html(vote_element); }, }); @@ -876,7 +879,7 @@ openerp.mail = function(session) { fetch_domain = replace_domain ? replace_domain : this.domain; fetch_context = replace_context ? replace_context : this.context; fetch_context.message_loaded= [this.id||0].concat( self.options.thread._parents[0].get_child_ids() ); - + return this.ds_message.call('message_read', [ids, fetch_domain, (this.options.thread.thread_level+1), fetch_context, this.context.default_parent_id || undefined] ).then(this.proxy('switch_new_message')); }, @@ -942,11 +945,11 @@ openerp.mail = function(session) { } } - if(parent_older) - message.insertBefore(parent_older.$el); - else if(parent_newer) + if(parent_newer) message.insertAfter(parent_newer.$el); - else + else if(parent_older) + message.insertBefore(parent_older.$el); + else message.prependTo(thread.list_ul); return message @@ -1095,7 +1098,6 @@ openerp.mail = function(session) { this._super.apply(this, arguments); var searchview_ready = this.load_searchview({}, false); var thread_displayed = this.message_render(); - this.options.domain = this.options.domain.concat(this.search_results['domain']); return (searchview_ready && thread_displayed); }, @@ -1135,14 +1137,19 @@ openerp.mail = function(session) { /** Clean and display the threads */ message_render: function (search) { + var domain = this.options.domain.concat(this.search_results['domain']); + + var domain = _.extend(this.options.domain, search&&search.domain? search.domain : {}); + var context = _.extend(this.options.context, search&&search.context ? search.context : {}); + this.thread = new mail.Thread(this, { - 'domain' : this.options.domain.concat(this.search_results['domain']), - 'context' : _.extend(this.options.context, search&&search.search_results['context'] ? search.search_results['context'] : {}), + 'domain' : domain, + 'context' : context, 'options': { 'thread' :{ 'thread_level': this.options.thread_level, 'use_composer': true, - 'show_header_compose': 1, + 'show_header_compose': 1, }, 'message': { 'show_reply': this.options.thread_level > 0, diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js index ab6a63ea6fa..953b8cd9fc8 100644 --- a/addons/mail/static/src/js/mail_followers.js +++ b/addons/mail/static/src/js/mail_followers.js @@ -149,6 +149,7 @@ openerp_mail_followers = function(session, mail) { var self = this; var node_user_list = this.$('ul.oe_mail_followers_display').empty(); this.$('div.oe_mail_recthread_followers h4').html(this.options.title + (records.length>=5 ? ' (' + records.length + ')' : '') ); + console.log(records); for(var i=0; i -
  • +
  • @@ -170,7 +171,7 @@
  • -
  • +
  • Load more messages ( messages not display)... diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index 1485c40570b..7ec37d952bc 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -550,6 +550,48 @@ class test_mail(TestMailMockups): # _compare_structures(struct1[x]['child_ids'], struct2[x]['child_ids'], n + 1) # # print '%send compare' % ('\t' * n) + # # ---------------------------------------- + # # CASE1: Flattening test + # # ---------------------------------------- + + # # Create dummy message structure + # import copy + # tree = [{'id': 2, 'child_nbr': 1, 'child_ids': [ + # {'id': 6, 'child_nbr': 1, 'child_ids': [ + # {'id': 8, 'child_nbr': 0, 'child_ids': []}, + # ]}, + # ]}, + # {'id': 1, 'child_nbr': 3, 'child_ids':[ + # {'id': 7, 'child_nbr': 1, 'child_ids': [ + # {'id': 9, 'child_nbr': 0, 'child_ids': []}, + # ]}, + # {'id': 4, 'child_nbr': 2, 'child_ids': [ + # {'id': 10, 'child_nbr': 0, 'child_ids': []}, + # {'id': 5, 'child_nbr': 0, 'child_ids': []}, + # ]}, + # {'id': 3, 'child_nbr': 0, 'child_ids': []}, + # ]}, + # ] + # # Test: completely flat + # new_tree = self.mail_message.message_read_tree_flatten(cr, uid, None, copy.deepcopy(tree), [('type', 'in', 'borderlands')], 0, limit=15, add_expandable=False) + # _compare_structures(new_tree, new_tree) + # self.assertEqual(len(new_tree), 10, 'message_read_tree_flatten wrong in flat') + # # Test: 1 thread level + # tree_test = [{'id': 2, 'child_ids': [ + # {'id': 8, 'child_ids': []}, {'id': 6, 'child_ids': []}, + # ]}, + # {'id': 1, 'child_ids': [ + # {'id': 10, 'child_ids': []}, {'id': 9, 'child_ids': []}, + # {'id': 7, 'child_ids': []}, {'id': 5, 'child_ids': []}, + # {'id': 4, 'child_ids': []}, {'id': 3, 'child_ids': []}, + # ]}, + # ] + # new_tree = self.mail_message.message_read_tree_flatten(cr, uid, None, copy.deepcopy(tree), [('type', 'in', 'borderlands')], 1, limit=15, add_expandable=False) + # _compare_structures(new_tree, tree_test) + # # Test: 2 thread levels + # new_tree = self.mail_message.message_read_tree_flatten(cr, uid, None, copy.deepcopy(tree), [('type', 'in', 'borderlands')], 2, limit=15, add_expandable=False) + # _compare_structures(new_tree, tree) + # # ---------------------------------------- # # CASE2: message_read test # # ---------------------------------------- diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index b7c51a20125..fbadf76f2fb 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -219,6 +219,7 @@ class mail_compose_message(osv.TransientModel): email(s), rendering any template patterns on the fly if needed. """ if context is None: context = {} + print '**', context active_ids = context.get('active_ids') for wizard in self.browse(cr, uid, ids, context=context):