From 2671f43ac437946cf9f8ac0851bac8f37c4f625c Mon Sep 17 00:00:00 2001 From: Fabien Bourgeois Date: Thu, 4 Aug 2016 09:38:32 +0200 Subject: [PATCH] [IMP]GOLEM Activity Session : integer from python function to database constraint --- .../models/golem_activity_session.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/golem_activity_session/models/golem_activity_session.py b/golem_activity_session/models/golem_activity_session.py index 3b87f13..44fadd1 100644 --- a/golem_activity_session/models/golem_activity_session.py +++ b/golem_activity_session/models/golem_activity_session.py @@ -63,6 +63,10 @@ class GolemActivitySession(models.Model): _inherits = {'product.template': 'product_id'} _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, ondelete='cascade') default_code = fields.Char(copy=True) # Copy the default code @@ -204,13 +208,3 @@ class GolemActivitySession(models.Model): if s.places_remain < 0: emsg = _('Sorry, there is no more place !') 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)