organisation du code + ajout de commentaires + suppression des blocs dispensable

This commit is contained in:
eloyoussef 2018-02-23 18:51:23 +01:00
parent 9d0ef62c0e
commit 399e55875f
6 changed files with 32 additions and 90 deletions

View File

@ -41,10 +41,14 @@ class GolemActivity(models.Model):
@api.constrains('activity_registration_ids') @api.constrains('activity_registration_ids')
def _automatedRegistrationFromQueue(self): def _automatedRegistrationFromQueue(self):
for record in self: for record in self:
print "________________________stitot_________________" # 1 verifier si une place est disponible sur activité
#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 if (len(record.activity_registration_ids) < record.places and
record.queue_activity_number > 0): record.queue_activity_number > 0 and
print("________________________testuiiautomated____________________________________") record.queue_allowed and
record.automated_registration_from_queue):
#recupérer la liste en file d'attente #recupérer la liste en file d'attente
queues = record.activity_queue_ids queues = record.activity_queue_ids
#trier la liste selon l'id : récupérer l'ancien element #trier la liste selon l'id : récupérer l'ancien element
@ -53,7 +57,6 @@ class GolemActivity(models.Model):
membre_registred = True membre_registred = True
#parcourir les element sur l'attente #parcourir les element sur l'attente
for queue in queues_sorted: for queue in queues_sorted:
print "_______queueu frome queues"
#inverse l'etat du memebre #inverse l'etat du memebre
membre_registred = False membre_registred = False
#recuperer la liste des registration #recuperer la liste des registration
@ -68,7 +71,6 @@ class GolemActivity(models.Model):
#à la sortie de la boucle si le membre nest pas sur inscription faire une #à la sortie de la boucle si le membre nest pas sur inscription faire une
if not membre_registred: if not membre_registred:
#valeures pour creer une inscritpion apartir de la file #valeures pour creer une inscritpion apartir de la file
print "____________________passage en cours"
values = { values = {
'activity_id' : queue.activity_id, 'activity_id' : queue.activity_id,
'member_id' : queue.member_id 'member_id' : queue.member_id
@ -89,14 +91,9 @@ class GolemActivity(models.Model):
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)
#lancer une fenetre pour inscritpion en file d'attente #lancer une fenetre pour inscritpion en file d'attente à partir du boutton
#@api.multi @api.multi
def queue_register(self): def queue_register(self):
print "______________________________________chmat-----------------"
self.ensure_one() self.ensure_one()
activity_id = self[0] activity_id = self[0]
return { return {
@ -110,13 +107,10 @@ class GolemActivity(models.Model):
'target': 'new', 'target': 'new',
} }
#fonction enregistrement du premier element de la liste d'ttente en inscription : mode manuel
#fonction enregistrement du premier element de la liste d'ttente en inscription
@api.multi @api.multi
def register_from_queue(self): def register_from_queue(self):
for record in self: for record in self:
print("________________________testuii____________________________________")
#recupérer la liste en file d'attente #recupérer la liste en file d'attente
queues = record.activity_queue_ids queues = record.activity_queue_ids
#trier la liste selon l'id : récupérer l'ancien element #trier la liste selon l'id : récupérer l'ancien element
@ -149,27 +143,21 @@ class GolemActivity(models.Model):
record.activity_queue_ids = [(2, queue.id, 0)] record.activity_queue_ids = [(2, queue.id, 0)]
#sortir de la boucle parcourissante la queue puisque inscription faite #sortir de la boucle parcourissante la queue puisque inscription faite
break break
#si member_registred est true donc soit membre déja inscrit ou aucun membre sur queue
if membre_registred: if membre_registred:
print "diknokemekrklekrlekr"
message = _('there is no member to register for this activity' message = _('there is no member to register for this activity'
' from queue.') ' from queue.')
raise ValidationError(message) 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 _checkRemain(self): def _checkRegistrationNumber(self):
current_activity = self._origin current_activity = self._origin
for record in self: for record in self:
#warning au cas ou le nombre d'inscription depasse le nombre de place #warning au cas ou le nombre d'inscription depasse le nombre de place
if len(record.activity_registration_ids) > record.places and record.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 using'
' the button bellow') ' the button bellow')
@ -182,69 +170,20 @@ class GolemActivity(models.Model):
elif (len(record.activity_registration_ids) < len(current_activity.activity_registration_ids) and elif (len(record.activity_registration_ids) < len(current_activity.activity_registration_ids) and
len(current_activity.activity_registration_ids) == record.places and len(current_activity.activity_registration_ids) == record.places and
record.queue_activity_number > 0 ): record.queue_activity_number > 0 ):
#si le mode d'inscription depuis attente est activé
if record.automated_registration_from_queue: if record.automated_registration_from_queue:
#inscription automatique du 1er element de la file d'attente #lancer un warning informant que l'inscription automatique aura lieu apres sauvegarde
print("________________________testuii____________________________________") print("________________________testuii____________________________________")
warningMessage = _('There is a free place for the activity' warningMessage = _('There is a free place for the activity'
' : {}, you can fill it from the queue' ' : {}, once you save it will be filled'
' using the button bellow') ' by the first membre from queue')
return { return {
'warning' : { 'warning' : {
'title' : _('Warning'), 'title' : _('Warning'),
'message': warningMessage.format(record.name) 'message': warningMessage.format(record.name)
} }
} }
"""
#recupérer la liste en file d'attente
queues = current_activity.activity_queue_ids
print "______________________test1"
#trier la liste selon l'id : récupérer l'ancien element
queues_sorted = sorted(queues, key=lambda k: k['id'])
print "______________________test1"
membre_registred = True
for queue in queues_sorted:
print "______________________1"
membre_registred = False
registrations = record.activity_registration_ids
for registration in registrations:
print "______________________2"
if queue.member_id == registration.member_id:
membre_registred = True
break
if not membre_registred:
#valeures pour creer une inscritpion apartir de la file
print '_____________________creation'
values = {
'activity_id' : queue.activity_id.id,
'member_id' : queue.member_id.id
}
# creation d'inscription
record.places =100
#current_activity.places_remain = 2
##current_activity.places_remain+
#reservation = self.env['golem.activity.registration'].create(values)
#record.activity_registration_ids = [(4, reservation.id,0)]
#suppression de l'element de la file d'attente
#record.activity_queue_ids = [(2, queue.id, 0)]
break
if membre_registred:
message = _('there is no member to register for this activity'
' from queue.')
raise ValidationError(message)
"""
"""
warningMessage = _('There is a free place for the activity'
' : {}, you can fill it from the queue'
' using the button bellow')
return {
'warning' : {
'title' : _('Warning'),
'message': warningMessage.format(record.name)
}
}
"""
#traitement manuel pour le passage de la file d'attente en inscription : button sur queue #traitement manuel pour le passage de la file d'attente en inscription : button sur queue
else : else :
warningMessage = _('There is a free place for the activity' warningMessage = _('There is a free place for the activity'

View File

@ -37,7 +37,7 @@ class GolemActivityQueue(models.Model):
#activité liée est plein ou non #activité liée est plein ou non
is_activity_full = fields.Char(compute="_isActivityFull") is_activity_full = fields.Char(compute="_isActivityFull")
# decider si l'activity liée est pleine ou non # decider si l'activity liée est pleine ou non : pour group by sur la liste
@api.multi @api.multi
@api.depends('places_remain') @api.depends('places_remain')
def _isActivityFull(self): def _isActivityFull(self):

View File

@ -26,17 +26,18 @@ class GolemMember(models.Model):
activity_queue_ids = fields.One2many('golem.activity.queue', activity_queue_ids = fields.One2many('golem.activity.queue',
'member_id','Pending registration') 'member_id','Pending registration')
#verifier si nombre d'inscription sur activité est supérieur au place disponible
@api.multi @api.multi
@api.onchange('activity_registration_ids') @api.onchange('activity_registration_ids')
def _checkRemain(self): def _checkRegistrationNumber(self):
self.ensure_one() self.ensure_one()
member_id = self[0] member_id = self[0]
for reservation in member_id.activity_registration_ids: for registration in member_id.activity_registration_ids:
activity = reservation.activity_id activity = reservation.activity_id
if len(activity.activity_registration_ids) > activity.places and activity.queue_allowed: if len(activity.activity_registration_ids) > activity.places and activity.queue_allowed:
warning_message = _('This activity : {} is already full, please' warning_message = _('This activity : {} is already full, please'
' remove your registration and register in' ' discard changes and register in'
' the queue using the bellow button') ' the queue using the bellow button')
return { return {
'warning' : { 'warning' : {
@ -45,8 +46,9 @@ class GolemMember(models.Model):
} }
} }
#lancer popup pour choisir activité à s'inscrire
@api.multi @api.multi
def queue_register(self): def choose_queue_to_register(self):
print "_________________________________________________" print "_________________________________________________"
print self print self
self.ensure_one() self.ensure_one()

View File

@ -29,7 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!--Ajout bouton d'inscription en file d'attente sur member form--> <!--Ajout bouton d'inscription en file d'attente sur member form-->
<xpath expr="//field[@name='activity_registration_ids']" position="after"> <xpath expr="//field[@name='activity_registration_ids']" position="after">
<group> <group>
<button class="oe_highlight" name="queue_register" string="Register in the queue" type="object"/> <button class="oe_highlight" name="choose_queue_to_register" string="Register in the queue" type="object"/>
</group> </group>
</xpath> </xpath>
<!--Ajout onglet queue sur member form--> <!--Ajout onglet queue sur member form-->

View File

@ -30,7 +30,8 @@ class GolemActivityQueueChooseWizard(models.TransientModel):
def ChooseActivity(self): # lancer liste editable d'inscription sur attente
def register_in_queue(self):
self.ensure_one() self.ensure_one()
activityQueue = self[0] activityQueue = self[0]
return { return {
@ -41,7 +42,7 @@ class GolemActivityQueueChooseWizard(models.TransientModel):
'context' :{'default_activity_id' : activityQueue.activity_id.id, 'context' :{'default_activity_id' : activityQueue.activity_id.id,
'default_member_id' : activityQueue.member_id.id 'default_member_id' : activityQueue.member_id.id
}, },
'domain' : [('activity_id', '=',activityQueue.activity_id.id )],# activity_id.name)],#"('activity_id', '=', True)" 'domain' : [('activity_id', '=',activityQueue.activity_id.id )],
'flags': {'action_buttons': True}, 'flags': {'action_buttons': True},
'target': 'new', 'target': 'new',
} }

View File

@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="activity_id" options="{'no_create': True}" /> <field name="activity_id" options="{'no_create': True}" />
</group> </group>
<footer> <footer>
<button name="ChooseActivity" string="Validate" type="object" <button name="register_in_queue" string="Validate" type="object"
class="oe_highlight" /> class="oe_highlight" />
<button string="Cancel" class="oe_link" special="cancel" /> <button string="Cancel" class="oe_link" special="cancel" />
</footer> </footer>