diff --git a/addons/note/models/note.py b/addons/note/models/note.py index e5e8b471a10..dd89b29c693 100644 --- a/addons/note/models/note.py +++ b/addons/note/models/note.py @@ -92,15 +92,20 @@ class Note(models.Model): def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): if groupby and groupby[0] == "stage_id" and (len(groupby) == 1 or lazy): stages = self.env['note.stage'].search([('user_id', '=', self.env.uid)]) - if stages: # if the user has some stages - result = [{ # notes by stage for stages user - '__context': {'group_by': groupby[1:]}, - '__domain': domain + [('stage_ids.id', '=', stage.id)], - 'stage_id': (stage.id, stage.name), - 'stage_id_count': self.search_count(domain + [('stage_ids', '=', stage.id)]), - '__fold': stage.fold, - } for stage in stages] - + if stages: + # if the user has some stages + result = [] + for stage in stages: + # notes by stage for stages user + nb_stage_counts = self.search_count(domain + [('stage_ids', '=', stage.id)]) + result.append({ + '__context': {'group_by': groupby[1:]}, + '__domain': domain + [('stage_ids.id', '=', stage.id)], + 'stage_id': (stage.id, stage.name), + 'stage_id_count': nb_stage_counts, + '__count': nb_stage_counts, + '__fold': stage.fold, + }) # note without user's stage nb_notes_ws = self.search_count(domain + [('stage_ids', 'not in', stages.ids)]) if nb_notes_ws: @@ -110,6 +115,7 @@ class Note(models.Model): dom_in = result[0]['__domain'].pop() result[0]['__domain'] = domain + ['|', dom_in, dom_not_in] result[0]['stage_id_count'] += nb_notes_ws + result[0]['__count'] += nb_notes_ws else: # add the first stage column result = [{ @@ -117,6 +123,7 @@ class Note(models.Model): '__domain': domain + [dom_not_in], 'stage_id': (stages[0].id, stages[0].name), 'stage_id_count': nb_notes_ws, + '__count': nb_notes_ws, '__fold': stages[0].name, }] + result else: # if stage_ids is empty, get note without user's stage @@ -126,7 +133,8 @@ class Note(models.Model): '__context': {'group_by': groupby[1:]}, '__domain': domain, 'stage_id': False, - 'stage_id_count': nb_notes_ws + 'stage_id_count': nb_notes_ws, + '__count': nb_notes_ws }] else: result = []