From 17c4f47b0ae7a0eec78b5555d52eeb0bb5e3cc5a Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwerburgh Date: Fri, 22 Nov 2019 08:40:03 +0000 Subject: [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) Co-authored-by: Denis Ledoux Co-authored-by: Raphael Collet --- odoo/tools/sql.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'odoo/tools/sql.py') diff --git a/odoo/tools/sql.py b/odoo/tools/sql.py index e1e4256dc7f..28cbe3ab25f 100644 --- a/odoo/tools/sql.py +++ b/odoo/tools/sql.py @@ -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. """ -- cgit v1.2.3