From b094dcee19fa235c3e32c8b6a18e101ee5c30558 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Tue, 6 Mar 2018 09:53:58 +0100 Subject: [PATCH] [REF]GOLEM Activity Queue : SQL constrains is sufficient, no need to double check with Pytho constraint here --- golem_activity_queue/__manifest__.py | 2 +- .../models/golem_activity_queue.py | 27 ++++--------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/golem_activity_queue/__manifest__.py b/golem_activity_queue/__manifest__.py index 2264ab2..400fae7 100644 --- a/golem_activity_queue/__manifest__.py +++ b/golem_activity_queue/__manifest__.py @@ -20,7 +20,7 @@ 'name': 'GOLEM activity queues', 'summary': 'GOLEM activity queues', 'description': ''' GOLEM activity queue management ''', - 'version': '10.0.1.1.0', + 'version': '10.0.1.1.1', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', diff --git a/golem_activity_queue/models/golem_activity_queue.py b/golem_activity_queue/models/golem_activity_queue.py index 0b452e0..aab5427 100644 --- a/golem_activity_queue/models/golem_activity_queue.py +++ b/golem_activity_queue/models/golem_activity_queue.py @@ -18,14 +18,16 @@ """ GOLEM Activity Queue """ -from odoo import models, fields, api, _ -from odoo.exceptions import ValidationError +from odoo import models, fields, _ class GolemActivityQueue(models.Model): """ GOLEM Activity Queue """ _name = 'golem.activity.queue' _order = "sequence" _description = 'GOLEM Activity Queue' + _sql_constraints = [('golem_activity_queue_uniq', 'UNIQUE (member_id, activity_id)', + _('This member has already been registered for the queue.'))] + member_id = fields.Many2one('golem.member', required=True, string='Member', ondelete='cascade', @@ -34,27 +36,8 @@ class GolemActivityQueue(models.Model): string='Activity', ondelete='cascade', index=True) season_id = fields.Many2one(related='activity_id.season_id') - is_current = fields.Boolean('Current season?', related='activity_id.is_current', store=True) + places_remain = fields.Integer(related='activity_id.places_remain') - sequence = fields.Integer() - - _sql_constraints = [ - ('queue_uniq', 'UNIQUE (member_id, activity_id)', - _('This member has already been registered for the queue.'))] - - @api.constrains('member_id', 'activity_id') - def _check_member_registration(self): - """ Forbid registration in queue when member is already registred in the - activity """ - for queue in self: - domain = [('member_id', '=', queue.member_id.id), - ('activity_id', '=', queue.activity_id.id)] - #verifier si un enrigistrement avec le meme membre et activité est déja fait - registrations = self.env['golem.activity.registration'].search(domain) - #si oui lancer un erreur - if len(registrations): - raise ValidationError(_('The member your trying to add to the queue' - ' is already registred for this activity'))