[FIX] base: allow custom model to use SQL (materialized) views instead of table
closes odoo/odoo#41267 X-original-commit: f17d389c4625e95f52c299c13a3f2983127c70bc Signed-off-by: Raphael Collet (rco) <rco@openerp.com> Co-authored-by: Denis Ledoux <dle@odoo.com> Co-authored-by: Raphael Collet <rco@odoo.com>
This commit is contained in:
committed by
Raphael Collet
co-authored by
Denis Ledoux
Raphael Collet
parent
d17e6a6750
commit
17c4f47b0a
@@ -314,7 +314,13 @@ class IrModel(models.Model):
|
||||
cr.execute('SELECT * FROM ir_model WHERE state=%s', ['manual'])
|
||||
for model_data in cr.dictfetchall():
|
||||
model_class = self._instanciate(model_data)
|
||||
model_class._build_model(self.pool, cr)
|
||||
Model = model_class._build_model(self.pool, cr)
|
||||
if tools.table_kind(cr, Model._table) not in ('r', None):
|
||||
# not a regular table, so disable schema upgrades
|
||||
Model._auto = False
|
||||
cr.execute('SELECT * FROM %s LIMIT 0' % Model._table)
|
||||
columns = {desc[0] for desc in cr.description}
|
||||
Model._log_access = set(models.LOG_ACCESS_COLUMNS) <= columns
|
||||
|
||||
|
||||
# retrieve field types defined by the framework only (not extensions)
|
||||
|
||||
+4
-10
@@ -8,13 +8,6 @@ import psycopg2
|
||||
|
||||
_schema = logging.getLogger('odoo.schema')
|
||||
|
||||
_TABLE_KIND = {
|
||||
'BASE TABLE': 'r',
|
||||
'VIEW': 'v',
|
||||
'FOREIGN TABLE': 'f',
|
||||
'LOCAL TEMPORARY': 't',
|
||||
}
|
||||
|
||||
_CONFDELTYPES = {
|
||||
'RESTRICT': 'r',
|
||||
'NO ACTION': 'a',
|
||||
@@ -42,11 +35,12 @@ def table_exists(cr, tablename):
|
||||
|
||||
def table_kind(cr, tablename):
|
||||
""" Return the kind of a table: ``'r'`` (regular table), ``'v'`` (view),
|
||||
``'f'`` (foreign table), ``'t'`` (temporary table), or ``None``.
|
||||
``'f'`` (foreign table), ``'t'`` (temporary table),
|
||||
``'m'`` (materialized view), or ``None``.
|
||||
"""
|
||||
query = "SELECT table_type FROM information_schema.tables WHERE table_name=%s"
|
||||
query = "SELECT relkind FROM pg_class WHERE relname = %s"
|
||||
cr.execute(query, (tablename,))
|
||||
return _TABLE_KIND[cr.fetchone()[0]] if cr.rowcount else None
|
||||
return cr.fetchone()[0] if cr.rowcount else None
|
||||
|
||||
def create_model_table(cr, tablename, comment=None):
|
||||
""" Create the table for a model. """
|
||||
|
||||
Reference in New Issue
Block a user