forked from Yaltik/golem
[REF]GOLEM Activity Queue : huge refactoring around activity methods + fixes
This commit is contained in:
parent
bcfb01e5b0
commit
963bfa7cb1
@ -20,7 +20,7 @@
|
|||||||
'name': 'GOLEM activity queues',
|
'name': 'GOLEM activity queues',
|
||||||
'summary': 'GOLEM activity queues',
|
'summary': 'GOLEM activity queues',
|
||||||
'description': ''' GOLEM activity queue management ''',
|
'description': ''' GOLEM activity queue management ''',
|
||||||
'version': '10.0.1.1.2',
|
'version': '10.0.1.1.3',
|
||||||
'category': 'GOLEM',
|
'category': 'GOLEM',
|
||||||
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
@ -19,239 +19,121 @@
|
|||||||
""" GOLEM Activity adaptations """
|
""" GOLEM Activity adaptations """
|
||||||
|
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
|
||||||
|
|
||||||
class GolemActivity(models.Model):
|
class GolemActivity(models.Model):
|
||||||
""" GOLEM Activity adaptations """
|
""" GOLEM Activity adaptations """
|
||||||
_inherit = 'golem.activity'
|
_inherit = 'golem.activity'
|
||||||
|
|
||||||
#ajout d'un champs O2M vers activity_id de golem.activity.queue
|
|
||||||
activity_queue_ids = fields.One2many('golem.activity.queue',
|
activity_queue_ids = fields.One2many('golem.activity.queue',
|
||||||
'activity_id', 'Pending registration')
|
'activity_id', 'Pending registration')
|
||||||
# un booleen pour determiner si une fille d'attente est autorisé
|
|
||||||
queue_allowed = fields.Boolean(default=True, readonly=True)
|
queue_allowed = fields.Boolean(default=True, readonly=True)
|
||||||
# un booleen pour automatisé l'inscription sur une activité depuis la file d'attente
|
|
||||||
auto_registration_from_queue = fields.Boolean(default=True, readonly=True)
|
auto_registration_from_queue = fields.Boolean(default=True, readonly=True)
|
||||||
#ajout d'un champs pour calculer le nombre d'inscription en file d'attente
|
|
||||||
queue_activity_number = fields.Integer(compute="_compute_queue_activity_number",
|
queue_activity_number = fields.Integer(compute="_compute_queue_activity_number",
|
||||||
store=True, string='Pending registration number')
|
store=True, string='Pending registration number')
|
||||||
#changer le mode de basculement en cas de desinctiption
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def auto_registration_toggle(self):
|
def auto_registration_toggle(self):
|
||||||
""" switch registration from queueu mode """
|
""" switch registration from queue mode """
|
||||||
for activity in self:
|
for activity in self:
|
||||||
activity.auto_registration_from_queue = not activity.auto_registration_from_queue
|
activity.auto_registration_from_queue = not activity.auto_registration_from_queue
|
||||||
|
|
||||||
#supprimer les personnes en attente si une inscription directement est faite
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
""" Override method write to delete record from queue if they register in activity"""
|
""" Override method write to delete record from queue if they register in activity"""
|
||||||
super(GolemActivity, self).write(vals)
|
res = super(GolemActivity, self).write(vals)
|
||||||
#recupérer les modification au niveau des registrations
|
registration_vals = vals.get('activity_registration_ids')
|
||||||
registrations = vals.get('activity_registration_ids')
|
if registration_vals:
|
||||||
if registrations:
|
for rval in registration_vals:
|
||||||
#parcourir les registrations
|
if rval[0] == 0: # creation case
|
||||||
for registration in registrations:
|
act_id = rval[2].get('activity_id')
|
||||||
#s'il une nouvelle registration est trouvé
|
mem_id = rval[2].get('member_id')
|
||||||
if registration[0] == 0:
|
if act_id and mem_id:
|
||||||
#recupérer les données de la registration
|
domain = [('activity_id', '=', act_id),
|
||||||
act_id = registration[2].get('activity_id')
|
('member_id', '=', mem_id)]
|
||||||
mem_id = registration[2].get('member_id')
|
queue = self.env['golem.activity.queue'].search(domain)
|
||||||
domain = [('activity_id', '=', act_id),
|
if queue:
|
||||||
('member_id', '=', mem_id)]
|
# remove registration
|
||||||
#chercher si le meme nomre est inscrit sur lattente du meme activité
|
queue.unlink()
|
||||||
queue = self.env['golem.activity.queue'].search(domain)
|
# self.activity_queue_ids = [(2, queue.id, False)]
|
||||||
if queue:
|
self.automated_register_from_queue()
|
||||||
#supprimer l'inscription sur la queue
|
return res
|
||||||
self.activity_queue_ids = [(2, queue.id, 0)]
|
|
||||||
return True
|
|
||||||
|
|
||||||
#Ajouter/supprimer une file à l'activité et afficher popup pour traitement automatisé
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def queue_allowed_toggle(self):
|
def queue_allowed_toggle(self):
|
||||||
""" Toggle queue_alowed boolean """
|
""" Toggle queue_alowed boolean """
|
||||||
for activity in self:
|
self.ensure_one()
|
||||||
#si l'activité contient une file
|
activity = self[0]
|
||||||
if activity.queue_allowed:
|
if activity.queue_allowed:
|
||||||
# si la queue déja contient des elements à supprimer
|
if len(activity.activity_queue_ids) > 0:
|
||||||
if len(activity.activity_queue_ids) > 0:
|
activity.activity_queue_ids.unlink()
|
||||||
#parcourir et supprimer les element de la queue
|
activity.write({'queue_allowed': False,
|
||||||
for queue in activity.activity_queue_ids:
|
'auto_registration_from_queue': False})
|
||||||
activity.activity_queue_ids = [(2, queue.id, 0)]
|
else:
|
||||||
#changer l'état de queue allowed et automated_registration en false
|
return {
|
||||||
activity.queue_allowed = False
|
'name': _('Choose the activity to register in'),
|
||||||
activity.auto_registration_from_queue = False
|
'type': 'ir.actions.act_window',
|
||||||
|
'res_model': 'golem.activity.automated.queue.activate.wizard',
|
||||||
|
'view_mode': 'form',
|
||||||
|
'context': {'default_activity_id' : activity.id},
|
||||||
|
'target': 'new',
|
||||||
|
}
|
||||||
|
|
||||||
else:
|
|
||||||
#lancer popup pour choisir activité à s'inscrire
|
|
||||||
self.ensure_one()
|
|
||||||
activity_id = self[0]
|
|
||||||
|
|
||||||
return {
|
|
||||||
'name' : _('Choose the activity to register in'),
|
|
||||||
'type' : 'ir.actions.act_window',
|
|
||||||
'res_model' : 'golem.activity.automated.queue.activate.wizard',
|
|
||||||
'view_mode': 'form',
|
|
||||||
'context' : {'default_activity_id' : activity_id.id},
|
|
||||||
'target': 'new',
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#contraint sur nombre d'inscription : une desincription declanche une inscription
|
|
||||||
#depuis attente mode automatique
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.constrains('activity_registration_ids')
|
def register_from_queue(self):
|
||||||
def _auto_registration_from_queue(self):
|
""" Registers from queue """
|
||||||
|
for activity in self:
|
||||||
|
queues = activity.activity_queue_ids
|
||||||
|
if activity.queue_activity_number < activity.places_remain:
|
||||||
|
queues = queues[0:activity.queue_activity_number]
|
||||||
|
else:
|
||||||
|
queues = queues[0:activity.places_remain]
|
||||||
|
for queue in queues:
|
||||||
|
values = {'activity_id' : queue.activity_id.id,
|
||||||
|
'member_id' : queue.member_id.id}
|
||||||
|
self.env['golem.activity.registration'].create(values)
|
||||||
|
queue.unlink()
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def automated_register_from_queue(self):
|
||||||
"""automated registration from queue"""
|
"""automated registration from queue"""
|
||||||
for record in self:
|
for record in self:
|
||||||
# 1 verifier si une place est disponible sur activité
|
if (record.places_remain and record.queue_allowed and
|
||||||
#2 verifier si la file contient des element
|
|
||||||
#3 verifier si la file est activé
|
|
||||||
#4 verifier si linscription automatique depuis la file est activé
|
|
||||||
if (len(record.activity_registration_ids) < record.places and
|
|
||||||
record.queue_activity_number > 0 and
|
record.queue_activity_number > 0 and
|
||||||
record.queue_allowed and
|
|
||||||
record.auto_registration_from_queue):
|
record.auto_registration_from_queue):
|
||||||
#recupérer la liste en file d'attente
|
record.register_from_queue()
|
||||||
queues = record.activity_queue_ids
|
|
||||||
#trier la liste selon l'id : récupérer l'ancien element
|
|
||||||
queues_sorted = sorted(queues, key=lambda k: k['id'])
|
|
||||||
#suppose que le membre est enrigistré
|
|
||||||
membre_registred = True
|
|
||||||
#parcourir les element sur l'attente
|
|
||||||
for queue in queues_sorted:
|
|
||||||
#inverse l'etat du memebre
|
|
||||||
membre_registred = False
|
|
||||||
#recuperer la liste des registration
|
|
||||||
registrations = record.activity_registration_ids
|
|
||||||
#parcourir les registration afin de vérifier si le memebre sur l'attente
|
|
||||||
#déja inscrit
|
|
||||||
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é inscrit sur l'activité on le supprime de la queue
|
|
||||||
record.activity_queue_ids = [(2, queue.id, 0)]
|
|
||||||
#si membre trouvé on mentionne enregistré, on passe au
|
|
||||||
#registration suivante
|
|
||||||
membre_registred = True
|
|
||||||
break
|
|
||||||
#à la sortie de la boucle si le membre nest pas sur inscription faire une
|
|
||||||
if not membre_registred:
|
|
||||||
#valeures pour creer une inscritpion apartir de la file
|
|
||||||
values = {
|
|
||||||
'activity_id' : queue.activity_id,
|
|
||||||
'member_id' : queue.member_id
|
|
||||||
}
|
|
||||||
# creation d'inscription
|
|
||||||
record.activity_registration_ids = [(0, 0, values)]
|
|
||||||
#suppression de l'element de la file d'attente
|
|
||||||
record.activity_queue_ids = [(2, queue.id, 0)]
|
|
||||||
#sortir de la boucle parcourissante la queue puisque inscription faite
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#calculer le nombre d'inscription sur la file d'attente
|
|
||||||
@api.multi
|
|
||||||
@api.depends('activity_queue_ids')
|
@api.depends('activity_queue_ids')
|
||||||
def _compute_queue_activity_number(self):
|
def _compute_queue_activity_number(self):
|
||||||
""" compute number of queue registration for activity"""
|
""" compute number of queue registration for activity"""
|
||||||
for activity in self:
|
for activity in self:
|
||||||
activity.queue_activity_number = len(activity.activity_queue_ids)
|
activity.queue_activity_number = len(activity.activity_queue_ids)
|
||||||
|
|
||||||
#fonction enregistrement du premier element de la liste d'ttente en inscription : mode manuel
|
|
||||||
@api.multi
|
|
||||||
def register_from_queue(self):
|
|
||||||
""" register member from queue"""
|
|
||||||
for record in self:
|
|
||||||
#recupérer la liste en file d'attente
|
|
||||||
queues = record.activity_queue_ids
|
|
||||||
#trier la liste selon l'id : récupérer l'ancien element
|
|
||||||
queues_sorted = sorted(queues, key=lambda k: k['id'])
|
|
||||||
#suppose que le membre est enrigistré
|
|
||||||
membre_registred = True
|
|
||||||
#parcourir les element sur l'attente
|
|
||||||
for queue in queues_sorted:
|
|
||||||
#inverse l'etat du memebre
|
|
||||||
membre_registred = False
|
|
||||||
#recuperer la liste des registration
|
|
||||||
registrations = record.activity_registration_ids
|
|
||||||
#parcourir les registration afin de vérifier si le memebre sur
|
|
||||||
#l'attente déja inscrit
|
|
||||||
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é 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:
|
|
||||||
#valeures pour creer une inscritpion apartir de la file
|
|
||||||
values = {
|
|
||||||
'activity_id' : queue.activity_id,
|
|
||||||
'member_id' : queue.member_id
|
|
||||||
}
|
|
||||||
# creation d'inscription
|
|
||||||
record.activity_registration_ids = [(0, 0, values)]
|
|
||||||
#suppression de l'element de la file d'attente
|
|
||||||
record.activity_queue_ids = [(2, queue.id, 0)]
|
|
||||||
#sortir de la boucle parcourissante la queue puisque inscription faite
|
|
||||||
break
|
|
||||||
#si member_registred est true donc soit membre déja inscrit ou aucun membre sur queue
|
|
||||||
if membre_registred:
|
|
||||||
message = _('there is no member to register for this activity'
|
|
||||||
' from queue.')
|
|
||||||
raise ValidationError(message)
|
|
||||||
# 1 verifie si ajout insctiption donc nombre d'inscription depasse place donc proposer queue
|
|
||||||
#2 verifier si desincription donc place disponible pour queue(automatique ou manuel)
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.onchange('activity_registration_ids')
|
@api.onchange('activity_registration_ids')
|
||||||
def _check_registration_number(self):
|
def _check_registration_number(self):
|
||||||
current_activity = self._origin
|
for activity in self:
|
||||||
for record in self:
|
places_remain = activity.places - activity.places_used
|
||||||
#warning au cas ou le nombre d'inscription depasse le nombre de place
|
if places_remain == 0 and activity.queue_allowed:
|
||||||
if (len(record.activity_registration_ids) > record.places and
|
|
||||||
record.queue_allowed):
|
|
||||||
message = _('No remaining place for the activity : {}, please'
|
message = _('No remaining place for the activity : {}, please'
|
||||||
' discard changes and register in the queue using'
|
' discard changes and register in the queue.')
|
||||||
' the button bellow')
|
|
||||||
return {
|
return {
|
||||||
'warning' : {
|
'warning' : {
|
||||||
'title' : _('Warning'),
|
'title' : _('Warning'),
|
||||||
'message': message.format(record.name),
|
'message': message.format(activity.name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elif (len(record.activity_registration_ids) < len(current_activity.activity_registration_ids) and
|
elif places_remain > 0 and activity.queue_activity_number > 0:
|
||||||
len(current_activity.activity_registration_ids) == record.places and
|
if activity.auto_registration_from_queue:
|
||||||
record.queue_activity_number > 0):
|
|
||||||
#si le mode d'inscription depuis attente est activé
|
|
||||||
if record.auto_registration_from_queue:
|
|
||||||
#lancer un warning informant que l'inscription automatique aura
|
|
||||||
#lieu apres sauvegarde
|
|
||||||
warning_message = _('There is a free place for the activity'
|
warning_message = _('There is a free place for the activity'
|
||||||
' : {}, once you save it will be filled'
|
' : {}, once you save it will be filled'
|
||||||
' by the first membre from queue')
|
' by the first member from queue')
|
||||||
return {
|
|
||||||
'warning' : {
|
|
||||||
'title' : _('Warning'),
|
|
||||||
'message': warning_message.format(record.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#traitement manuel pour le passage de la file d'attente en inscription
|
|
||||||
# : button sur queue
|
|
||||||
else:
|
else:
|
||||||
warning_message = _('There is a free place for the activity'
|
warning_message = _('There is a free place for the activity'
|
||||||
' : {}, you can fill it from the queue'
|
' : {}, you may fill it manually from '
|
||||||
' using the button on queue tab')
|
'the queue')
|
||||||
return {
|
return {
|
||||||
'warning' : {
|
'warning' : {
|
||||||
'title' : _('Warning'),
|
'title' : _('Warning'),
|
||||||
'message': warning_message.format(record.name)
|
'message': warning_message.format(activity.name)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -24,7 +24,7 @@ from odoo.exceptions import ValidationError
|
|||||||
class GolemActivityQueue(models.Model):
|
class GolemActivityQueue(models.Model):
|
||||||
""" GOLEM Activity Queue """
|
""" GOLEM Activity Queue """
|
||||||
_name = 'golem.activity.queue'
|
_name = 'golem.activity.queue'
|
||||||
_order = "sequence"
|
_order = 'sequence asc, id desc'
|
||||||
_description = 'GOLEM Activity Queue'
|
_description = 'GOLEM Activity Queue'
|
||||||
_sql_constraints = [('golem_activity_queue_uniq', 'UNIQUE (member_id, activity_id)',
|
_sql_constraints = [('golem_activity_queue_uniq', 'UNIQUE (member_id, activity_id)',
|
||||||
_('This member has already been registered for the queue.'))]
|
_('This member has already been registered for the queue.'))]
|
||||||
|
Loading…
Reference in New Issue
Block a user