Skip to content

Instantly share code, notes, and snippets.

@gurneyalex
Created April 11, 2016 15:43
Show Gist options
  • Save gurneyalex/b571449b4e698b3635d13aba674ca392 to your computer and use it in GitHub Desktop.
Save gurneyalex/b571449b4e698b3635d13aba674ca392 to your computer and use it in GitHub Desktop.
class A(Model):
def _compute_B_count(self):
query = 'select a.id, count(b.id) from a right outer join b on (a.id=b.a_id) where a.id = ANY(%s)'
self.env.cr.execute(query, self.ids)
counts = dict(self.env.cr.fetchall())
for rec in self:
rec.count = counts[rec.id]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment