From 533bb81fb9637998fdb784c8ee99df2c0856582f Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Tue, 27 Feb 2018 15:00:55 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20au=20niveau=20de=20plusieur?= =?UTF-8?q?es=20fonction(suppression=20des=20doublon=20et=20interdiction?= =?UTF-8?q?=20d'inscription)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- golem_activity_queue/models/golem_activity.py | 29 ++++++++++++++++++- .../models/golem_activity_queue.py | 15 +++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/golem_activity_queue/models/golem_activity.py b/golem_activity_queue/models/golem_activity.py index ef07b19..3ced4bd 100644 --- a/golem_activity_queue/models/golem_activity.py +++ b/golem_activity_queue/models/golem_activity.py @@ -35,6 +35,30 @@ class GolemActivity(models.Model): queue_activity_number = fields.Integer(compute="_queue_activity_number", store=True, string='Pending registration number') + @api.multi + def write(self, vals): + """ Override method write to delete record from queue if they register in activity""" + super(GolemActivity, self).write(vals) + #recupérer les modification au niveau des registrations + registrations = vals.get('activity_registration_ids') + if registrations: + #parcourir les registrations + for registration in registrations: + #s'il une nouvelle registration est trouvé + if registration[0] == 0: + #recupérer les données de la registration + act_id = registration[2].get('activity_id') + mem_id = registration[2].get('member_id') + domain = [('activity_id', '=', act_id), + ('member_id', '=', mem_id)] + #chercher si le meme nomre est inscrit sur lattente du meme activité + queue = self.env['golem.activity.queue'].search(domain) + if queue: + #supprimer l'inscription sur la queue + self.activity_queue_ids = [(2, queue.id, 0)] + return True + + #mettre à jour le status d'activité remplis sur chaque attente @api.constrains('places_remain') def updateActivityState(self): @@ -149,8 +173,11 @@ class GolemActivity(models.Model): for registration in registrations: #compare le membre sur l'attente au membre sur l'inscription if queue.member_id == registration.member_id: - #si membre trouvé on mentionne enregistré, on passe au registration suivante + #si membre trouvé inscrit sur l'activité on le supprime de la queue + record.activity_queue_ids = [(2, queue.id, 0)] + # on mentionne enregistré, on passe au registration suivante membre_registred = True + #on sort de la boucle de registration et on passe à l'element suivant de l'attente break #à la sortie de la boucle si le membre nest pas sur inscription faire une if not membre_registred: diff --git a/golem_activity_queue/models/golem_activity_queue.py b/golem_activity_queue/models/golem_activity_queue.py index bddf1e0..507ba58 100644 --- a/golem_activity_queue/models/golem_activity_queue.py +++ b/golem_activity_queue/models/golem_activity_queue.py @@ -27,11 +27,14 @@ class GolemActivityQueue(models.Model): _order = "sequence" _description = 'GOLEM Activity Queue' - activity_id = fields.Many2one('golem.activity', required=True, - string='Activity', ondelete='cascade') - season_id = fields.Many2one(related='activity_id.season_id') member_id = fields.Many2one('golem.member', required=True, - string='Member', ondelete='cascade') + string='Member', ondelete='cascade', + index=True) + activity_id = fields.Many2one('golem.activity', required=True, + 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) #nombre de place disponible sur activité liée @@ -41,6 +44,10 @@ class GolemActivityQueue(models.Model): sequence = fields.Integer() + _sql_constraints = [ + ('queue_uniq', 'UNIQUE (member_id, activity_id)', + _('This member has already been registered for the queue.'))] + # decider si l'activity liée est pleine ou non : pour group by sur la liste @api.depends('places_remain')