Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Base

Entity: ir.model

Compute Method: _compute_count

View 17.0 View 19.0
Inputs Method Outputs
  • model
- cr = self.env.cr
self.count = 0
for model in self:
-             records = self.env[model.model]
-             if not records._abstract and records._auto:
-                 cr.execute(sql.SQL('SELECT COUNT(*) FROM {}').format(sql.Identifier(records._table)))
-                 model.count = cr.fetchone()[0]
+             records = self.env.get(model.model)
+             if records is not None and not records._abstract and records._auto:
+                 [[count]] = self.env.execute_query(SQL("SELECT COUNT(*) FROM %s", SQL.identifier(records._table)))
+                 model.count = count
  • count

Back to entity