From bb27960228ed69ee2c5028c98e65f0cf79f14de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 17 Dec 2016 00:38:21 +0100 Subject: [PATCH] Remove order constraint on register ModelSQL We create the foreign table if needed before adding the foreign key constraint, thus it is no more needed to order the registration of the ModelSQL. issue5682 review32841002 --- CHANGELOG | 1 + trytond/model/modelsql.py | 6 +++++- trytond/res/__init__.py | 1 - trytond/res/group.py | 13 +++---------- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 050135ff10..cc00f17975 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Remove order constraint on register ModelSQL * Add relate from report to translations Version 4.2.0 - 2016-11-28 diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 3d5d16496a..9b7e3b7352 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -188,7 +188,11 @@ class ModelSQL(ModelStorage): if field.model_name in ('res.user', 'res.group'): ref = field.model_name.replace('.', '_') else: - ref = pool.get(field.model_name)._table + ref_model = pool.get(field.model_name) + ref = ref_model._table + # Create foreign key table if missing + if not TableHandler.table_exist(ref): + TableHandler(ref_model) if field_name in ['create_uid', 'write_uid']: # migration from 3.6 table.drop_fk(field_name) diff --git a/trytond/res/__init__.py b/trytond/res/__init__.py index d80ac99b99..582d34c17d 100644 --- a/trytond/res/__init__.py +++ b/trytond/res/__init__.py @@ -15,7 +15,6 @@ def register(): Group, User, LoginAttempt, - Group2, UserAction, UserGroup, Warning_, diff --git a/trytond/res/group.py b/trytond/res/group.py index 528e5fcc27..b87a712091 100644 --- a/trytond/res/group.py +++ b/trytond/res/group.py @@ -3,12 +3,10 @@ "Group" from itertools import chain from ..model import ModelView, ModelSQL, fields, Unique -from ..pool import Pool, PoolMeta +from ..pool import Pool from ..tools import grouped_slice -__all__ = [ - 'Group', 'Group2', - ] +__all__ = ['Group'] class MenuMany2Many(fields.Many2Many): @@ -33,6 +31,7 @@ class Group(ModelSQL, ModelView): "Group" __name__ = "res.group" name = fields.Char('Name', required=True, select=True, translate=True) + users = fields.Many2Many('res.user-res.group', 'group', 'user', 'Users') model_access = fields.One2Many('ir.model.access', 'group', 'Access Model') field_access = fields.One2Many('ir.model.field.access', 'group', @@ -115,9 +114,3 @@ class Group(ModelSQL, ModelView): pool.get('ir.model.access')._get_access_cache.clear() pool.get('ir.model.field.access')._get_access_cache.clear() ModelView._fields_view_get_cache.clear() - - -class Group2: - __metaclass__ = PoolMeta - __name__ = "res.group" - users = fields.Many2Many('res.user-res.group', 'group', 'user', 'Users')