forked from Yaltik/golem
[IMP]GOLEM Activity Session : integer from python function to database constraint
This commit is contained in:
parent
0e2871cca3
commit
2671f43ac4
@ -63,6 +63,10 @@ class GolemActivitySession(models.Model):
|
|||||||
_inherits = {'product.template': 'product_id'}
|
_inherits = {'product.template': 'product_id'}
|
||||||
_rec_name = 'session_name'
|
_rec_name = 'session_name'
|
||||||
|
|
||||||
|
_sql_constraints = [('golem_activity_session_places_signed',
|
||||||
|
'CHECK (places >= 0)',
|
||||||
|
_('Number of places cannot be negative.'))]
|
||||||
|
|
||||||
product_id = fields.Many2one('product.template', required=True,
|
product_id = fields.Many2one('product.template', required=True,
|
||||||
ondelete='cascade')
|
ondelete='cascade')
|
||||||
default_code = fields.Char(copy=True) # Copy the default code
|
default_code = fields.Char(copy=True) # Copy the default code
|
||||||
@ -204,13 +208,3 @@ class GolemActivitySession(models.Model):
|
|||||||
if s.places_remain < 0:
|
if s.places_remain < 0:
|
||||||
emsg = _('Sorry, there is no more place !')
|
emsg = _('Sorry, there is no more place !')
|
||||||
raise models.ValidationError(emsg)
|
raise models.ValidationError(emsg)
|
||||||
|
|
||||||
@api.constrains('places')
|
|
||||||
def _check_places(self):
|
|
||||||
""" Check integers are signed and overbooked to be superior than
|
|
||||||
normal places """
|
|
||||||
for v in self:
|
|
||||||
for f in ['places']:
|
|
||||||
if v[f] < 0:
|
|
||||||
emsg = _('Number of places cannot be negative.')
|
|
||||||
raise models.ValidationError(emsg)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user