diff --git a/trytond/ir/action.py b/trytond/ir/action.py index 66e47ede54..dbca24a278 100644 --- a/trytond/ir/action.py +++ b/trytond/ir/action.py @@ -171,10 +171,13 @@ class ActionReport(OSV): fnct_inv='report_content_inv', type='binary', string='Content') action = fields.Many2One('ir.action', 'Action', required=True) - _sql_constraints = [ - ('report_name_uniq', 'unique (report_name)', - 'The internal name must be unique!'), - ] + + def __init__(self): + super(ActionReport, self).__init__() + self._sql_constraints += [ + ('report_name_uniq', 'unique (report_name)', + 'The internal name must be unique!'), + ] def default_type(self, cursor, user, context=None): return 'ir.action.report' diff --git a/trytond/ir/attachment.py b/trytond/ir/attachment.py index dc50b7fcdc..0f926da038 100644 --- a/trytond/ir/attachment.py +++ b/trytond/ir/attachment.py @@ -22,11 +22,14 @@ class Attachment(OSV): collision = fields.Integer('Collision') datas_size = fields.Function('datas', type='integer', string='Datas size') - _sql_constraints = [ - ('res_model_res_id_name', - 'UNIQUE (res_model, res_id, name)', - 'Error! You can not create attachment with the same name!'), - ] + + def __init__(self): + super(Attachment, self).__init__() + self._sql_constraints += [ + ('res_model_res_id_name', + 'UNIQUE (res_model, res_id, name)', + 'Error! You can not create attachment with the same name!'), + ] def default_collision(self, cursor, user, context=None): return 0 diff --git a/trytond/ir/model.py b/trytond/ir/model.py index 2bfb3c58fd..391c9c306e 100644 --- a/trytond/ir/model.py +++ b/trytond/ir/model.py @@ -66,10 +66,13 @@ class ModelAccess(OSV): perm_create = fields.Boolean('Create Access') perm_unlink = fields.Boolean('Delete Permission') description = fields.Text('Description') - _sql_constraints = [ - ('model_group_uniq', 'UNIQUE("model", "group")', - 'Only on record by model and group is allowed!'), - ] + + def __init__(self): + super(ModelAccess, self).__init__() + self._sql_constraints += [ + ('model_group_uniq', 'UNIQUE("model", "group")', + 'Only on record by model and group is allowed!'), + ] def check(self, cursor, user, model_name, mode='read', raise_exception=True): @@ -158,19 +161,16 @@ class ModelData(OSV): date_update = fields.DateTime('Update Date') date_init = fields.DateTime('Init Date') values = fields.Text('Values') - _sql_constraints = [ - ('fs_id_module_uniq', 'UNIQUE("fs_id", "module")', - 'The couple (fs_id, module) must be unique!'), - ] - - def default_date_init(self, cursor, user, context=None): - return time.strftime('%Y-%m-%d %H:%M:%S') def __init__(self): super(ModelData, self).__init__() - self.fs2db = None - self.fs2values = None + self._sql_constraints = [ + ('fs_id_module_uniq', 'UNIQUE("fs_id", "module")', + 'The couple (fs_id, module) must be unique!'), + ] + def default_date_init(self, cursor, user, context=None): + return time.strftime('%Y-%m-%d %H:%M:%S') def get_id(self, cursor, user, module, fs_id): """ diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index caa1d3ec51..687b7279f9 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -149,10 +149,13 @@ class Module(OSV): ('Other proprietary', 'Other proprietary')], string='License', readonly=True) _order = 'name' - _sql_constraints = [ - ('name_uniq', 'unique (name)', - 'The name of the module must be unique!'), - ] + + def __init__(self): + super(Module, self).__init__() + self._sql_constraints = [ + ('name_uniq', 'unique (name)', + 'The name of the module must be unique!'), + ] def default_state(self, cursor, user, context=None): return 'uninstalled' diff --git a/trytond/ir/translation.py b/trytond/ir/translation.py index f111d1e5f0..9dd82a6b23 100644 --- a/trytond/ir/translation.py +++ b/trytond/ir/translation.py @@ -40,15 +40,18 @@ class Translation(OSV, Cacheable): fuzzy = fields.Boolean('Fuzzy') model = fields.Function('get_model', fnct_search='model_search', type='char', string='Model') - _sql_constraints = [ - ('translation_uniq', 'UNIQUE (name, res_id, lang, type, src)', - 'Translation must be unique'), - ] _sql = """ CREATE INDEX ir_translation_ltn ON ir_translation (lang, type, name); CREATE INDEX ir_translation_res_id ON ir_translation (res_id); """ + def __init__(self): + super(Translation, self).__init__() + self._sql_constraints += [ + ('translation_uniq', 'UNIQUE (name, res_id, lang, type, src)', + 'Translation must be unique'), + ] + def default_fuzzy(self, cursor, user, context=None): return 0 diff --git a/trytond/ir/ui/view.py b/trytond/ir/ui/view.py index 640c568c12..6813c930f9 100644 --- a/trytond/ir/ui/view.py +++ b/trytond/ir/ui/view.py @@ -21,9 +21,12 @@ class View(OSV): field_childs = fields.Char('Childs Field',size=64) module = fields.Char('Module', size=128, readonly=True) _order = "priority" - _constraints = [ - ('check_xml', 'Invalid XML for View Architecture!', ['arch']) - ] + + def __init__(self): + super(View, self).__init__() + self._constraints += [ + ('check_xml', 'Invalid XML for View Architecture!', ['arch']) + ] def default_arch(self, cursor, user, context=None): return '\n' \ diff --git a/trytond/osv/orm.py b/trytond/osv/orm.py index c896658de2..865f0e9d36 100644 --- a/trytond/osv/orm.py +++ b/trytond/osv/orm.py @@ -235,8 +235,6 @@ class ORM(object): - relations (one2many, many2one, many2many) - functions """ - _sql_constraints = [] - _constraints = [] _log_access = True _table = None _name = None @@ -244,13 +242,12 @@ class ORM(object): _parent_name = 'parent' _date_name = 'date' _order = 'id' - _inherits = {} + _inherits = {} #XXX remove from class instance _sequence = None _description = '' _auto = True _obj = None _sql = '' - _inherit_fields = [] pool = None __columns = None __defaults = None @@ -769,10 +766,13 @@ class ORM(object): 'import_data', 'search_count', ] - - # reinit the cachel on _columns and _defaults + self._sql_constraints = [] + self._constraints = [] + self._inherit_fields = [] + # reinit the cache on _columns and _defaults self.__columns = None self.__defaults = None + if not self._table: self._table = self._name.replace('.', '_') if not self._description: diff --git a/trytond/res/group.py b/trytond/res/group.py index 7453738299..ed9919ba4a 100644 --- a/trytond/res/group.py +++ b/trytond/res/group.py @@ -14,9 +14,12 @@ class Group(OSV): domain="[('global', '<>', True)]") menu_access = fields.Many2Many('ir.ui.menu', 'ir_ui_menu_group_rel', 'gid', 'menu_id', 'Access Menu') - _sql_constraints = [ - ('name_uniq', 'unique (name)', 'The name of the group must be unique!') - ] + + def __init__(self): + super(Group, self).__init__() + self._sql_constraints += [ + ('name_uniq', 'unique (name)', 'The name of the group must be unique!') + ] def write(self, cursor, user, ids, vals, context=None): res = super(Group, self).write(cursor, user, ids, vals, diff --git a/trytond/res/user.py b/trytond/res/user.py index bc1e526eba..88581cc838 100644 --- a/trytond/res/user.py +++ b/trytond/res/user.py @@ -27,22 +27,30 @@ class User(OSV): domain="[('global', '<>', True)]") language = fields.Selection('languages', 'Language') timezone = fields.Selection('timezones', 'Timezone') - _sql_constraints = [ - ('login_key', 'UNIQUE (login)', - 'You can not have two users with the same login!') - ] - _preferences_fields = [ - 'name', - 'password', - 'signature', - 'menu', - 'action', - ] - _context_fields = [ - 'language', - 'timezone', - 'groups', - ] + + def __init__(self): + super(User, self).__init__() + self._rpc_allowed += [ + 'get_preferences', + 'set_preferences', + 'get_preferences_fields_view', + ] + self._sql_constraints = [ + ('login_key', 'UNIQUE (login)', + 'You can not have two users with the same login!') + ] + self._preferences_fields = [ + 'name', + 'password', + 'signature', + 'menu', + 'action', + ] + self._context_fields = [ + 'language', + 'timezone', + 'groups', + ] def default_password(self, cursor, user, context=None): return '' @@ -68,14 +76,6 @@ class User(OSV): def default_action(self, cursor, user, context=None): return self.default_menu(cursor, user, context=context) - def __init__(self): - super(User, self).__init__() - self._rpc_allowed += [ - 'get_preferences', - 'set_preferences', - 'get_preferences_fields_view', - ] - def _convert_vals(self, cursor, user, vals, context=None): vals = vals.copy() action_obj = self.pool.get('ir.action') diff --git a/trytond/webdav/webdav.py b/trytond/webdav/webdav.py index 92b2c7dc52..a71c152323 100644 --- a/trytond/webdav/webdav.py +++ b/trytond/webdav/webdav.py @@ -16,22 +16,25 @@ class Directory(OSV): childs = fields.One2Many('webdav.directory', 'parent', 'Childs') model = fields.Many2One('ir.model', 'Model') domain = fields.Char('Domain', size=250) - _sql_constraints = [ - ('name_parent_uniq', 'UNIQUE (name, parent)', - 'The directory name must be unique inside a directory!'), - ] _parent_name = 'parent' - _constraints = [ - ('check_recursion', - 'Error! You can not create recursive directories.', ['parent']), - ('check_attachment', - 'Error! You can not create a directory \n' \ - 'with the same name of an existing file \n' \ - 'inside the same directory.', ['name']), - ] - ext2mime = { - '.png': 'image/png', - } + + def __init__(self): + super(Directory, self).__init__() + self._sql_constraints += [ + ('name_parent_uniq', 'UNIQUE (name, parent)', + 'The directory name must be unique inside a directory!'), + ] + self._constraints += [ + ('check_recursion', + 'Error! You can not create recursive directories.', ['parent']), + ('check_attachment', + 'Error! You can not create a directory \n' \ + 'with the same name of an existing file \n' \ + 'inside the same directory.', ['name']), + ] + self.ext2mime = { + '.png': 'image/png', + } def default_domain(self, cursor, user, context=None): return '[]' @@ -299,7 +302,7 @@ class Attachment(OSV): def __init__(self): super(Attachment, self).__init__() - self._constraints = self._constraints + [ + self._constraints += [ ('check_directory', 'Error! You can not create a attachment \n' \ 'on a directory that have the same name \n' \