[IMP]GOLEM Activity Session Registration : use SQL constraint when possible, forbids duplicates

This commit is contained in:
Fabien Bourgeois 2016-09-22 13:53:33 +02:00
parent 7ea95dbac8
commit a36c88a113

View File

@ -77,11 +77,9 @@ class GolemActivitySessionRegistration(models.Model):
is_current = fields.Boolean('Current season?', is_current = fields.Boolean('Current season?',
related='session_id.is_current') related='session_id.is_current')
# TODO : translate / change error ?? _sql_constraints = [
_sql_constraints = [('golem_activity_session_registration_uniq', ('registration_uniq', 'UNIQUE (member_id, session_id)',
'UNIQUE (member_id, session_id)', _('This member has already been registered for this session.'))]
'This memebr has already been registered for this '
'session.')]
@api.constrains('member_id', 'session_id') @api.constrains('member_id', 'session_id')
def _check_season_reliability(self): def _check_season_reliability(self):
@ -92,8 +90,3 @@ class GolemActivitySessionRegistration(models.Model):
emsg = _('Subscription can not be executed : the targeted ' emsg = _('Subscription can not be executed : the targeted '
'member is not on the same season as the session.') 'member is not on the same season as the session.')
raise models.ValidationError(emsg) raise models.ValidationError(emsg)
# domain = ['&', ('session_id', '=', r.session_id.id),
# ('member_id', '=', r.member_id.id)]
# if len(self.search(domain)) > 1:
# raise models.ValidationError(_('This member has already been '
# 'registered for this session.'))