Skip to content

Instantly share code, notes, and snippets.

@litnimax
Created May 26, 2018 13:54
Show Gist options
  • Save litnimax/bcc34097456bfec787d8a5af8d3c8335 to your computer and use it in GitHub Desktop.
Save litnimax/bcc34097456bfec787d8a5af8d3c8335 to your computer and use it in GitHub Desktop.
Odoo many2many groupby example
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
if not '_context_' in groupby:
return super(Task, self).read_group(domain, fields, groupby,
offset, limit, orderby, lazy)
else:
# Get the list of contexts
res = []
for c in self.env['nibbana.context'].search(
[('create_uid','=', self.env.user.id)]):
count = self.env['nibbana.task'].search_count([('context','in',c.id)])
res.append({
'_context_': c.name,
'_context__count': count,
'__domain': expression.AND([domain, [('context','in', c.id)]])
})
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment