diff options
| author | Nicolas Vannieuwerburgh <nvn@odoo.com> | 2019-11-22 08:40:03 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2019-12-03 07:45:25 +0000 |
| commit | 17c4f47b0ae7a0eec78b5555d52eeb0bb5e3cc5a (patch) | |
| tree | 0d984e392ec43fccfad299f8ab84553fb4daa8ad /odoo/tools | |
| parent | d17e6a6750f93a0d90a92e5c4d321de5437f07f1 (diff) | |
[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>
Diffstat (limited to 'odoo/tools')
| -rw-r--r-- | odoo/tools/sql.py | 14 |
1 files changed, 4 insertions, 10 deletions
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. """ |
