summaryrefslogtreecommitdiff
path: root/odoo/models.py
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2020-08-12 15:29:15 +0000
committerRaphael Collet <rco@odoo.com>2020-08-20 07:45:18 +0000
commitf2ceef0e2f0efb2e47b5f595a80009184305a2c4 (patch)
treefc890511b910167a2ecec0881ddd7169007cbe10 /odoo/models.py
parent9ad16bf84a0a1e33426105ec20670042e00f19b9 (diff)
[IMP] core: add models defined by a query instead of a table/view
By adding a parameter `_table_query` on the Model, we can now have views that depend on the context. The query is used instead of the table name in ORM operations. This allows to pre-compute some values to improve performance, instead of storing context values in the database. Co-authored-by: william-andre <wan@odoo.com> Co-authored-by: rco-odoo <rco@odoo.com>
Diffstat (limited to 'odoo/models.py')
-rw-r--r--odoo/models.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/odoo/models.py b/odoo/models.py
index f7e54cd4750..d82806b6862 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -316,6 +316,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
correspond to the last one (in the inherits list order).
"""
_table = None #: SQL table name used by model if :attr:`_auto`
+ _table_query = None #: SQL expression of the table's content (optional)
_sequence = None #: SQL sequence to use for ID field
_sql_constraints = [] #: SQL constraints [(name, sql_def, message)]
@@ -3058,7 +3059,7 @@ Fields:
cr, user, context, su = env.args
# make a query object for selecting ids, and apply security rules to it
- query = Query(self.env.cr, self._table)
+ query = Query(self.env.cr, self._table, self._table_query)
self._apply_ir_rules(query, 'read')
# the query may involve several tables: we need fully-qualified names
@@ -3321,7 +3322,7 @@ Fields:
if not self._ids:
return self
- query = Query(self._cr, self._table)
+ query = Query(self.env.cr, self._table, self._table_query)
self._apply_ir_rules(query, operation)
if not query.where_clause:
return self
@@ -4153,7 +4154,7 @@ Fields:
if domain:
return expression.expression(domain, self).query
else:
- return Query(self.env.cr, self._table)
+ return Query(self.env.cr, self._table, self._table_query)
def _check_qorder(self, word):
if not regex_order.match(word):