ajouter fonction pour passer les elements de la liste d'attente en liste d'inscription

This commit is contained in:
eloyoussef 2018-02-22 22:59:10 +01:00
parent b9eeb3a170
commit 3cc4ec92f0
6 changed files with 95 additions and 36 deletions

View File

@ -26,18 +26,23 @@ class GolemActivity(models.Model):
#ajout d'un champs O2M vers activity_id de golem.activity.queue
activity_queue_ids = fields.One2many('golem.activity.queue',
'activity_id','Pending registration')
# un boolen pour determiner si une fille d'attente est autorisé
# un booleen pour determiner si une fille d'attente est autorisé
queue_allowed = fields.Boolean(default=True)
# un booleen pour automatisé l'inscription sur une activité depuis la file d'attente
automated_registration_from_queue = fields.Boolean(default=True)
#ajout d'un champs pour calculer le nombre d'inscription en file d'attente
queue_activity_number = fields.Integer(compute="_queue_activity_number",
store=True , string='Pending registration number')
#calculer le nombre d'inscription sur la file d'attente
@api.multi
@api.depends('activity_queue_ids')
def _queue_activity_number(self):
for activity in self:
activity.queue_activity_number = len(activity.activity_queue_ids)
#lancer une fenetre pour inscritpion en file d'attente
@api.multi
def queue_register(self):
self.ensure_one()
@ -55,39 +60,77 @@ class GolemActivity(models.Model):
@api.multi
def register_from_queue(self):
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'])
#valeures pour creer une inscritpion apartir de la file
values = {
'activity_id' : queues_sorted[0].activity_id,
'member_id' : queues_sorted[0].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, queues_sorted[0].id, 0)]
@api.multi
@api.onchange('activity_registration_ids')
def _checkRemain(self):
if len(self.activity_registration_ids) > self.places and self.queue_allowed:
return {
'warning' : {
'title' : _('Warning'),
'message': _('No remaining place, please register in the queue'),
for record in self:
if len(record.activity_registration_ids) > record.places and record.queue_allowed:
message = _('No remaining place for the activity : {}, please'
' discard changes and register in the queue using'
' the button bellow')
return {
'warning' : {
'title' : _('Warning'),
'message': message.format(record.name),
}
}
}
elif len(record.activity_registration_ids) < record.places and record.queue_allowed and record.queue_activity_number > 0:
"""
@api.multi
@api.constrains('places_remain')
def _check_remaining_places(self):
#Forbid inscription when there is no more place
for activity in self:
if activity.places_remain < 5:
if self.queue_allowed:
print "__________________________ test ______________________"
return {
'name' : _('Do you want to add your registration to the queue?'),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.activity.queue',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
# passage de l'element depuis la file d'attente automatiquement
if record.automated_registration_from_queue:
#traitement qui bloque avec message d'erreur can't adapt activitiy_id to newId
"""
#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'])
#valeures pour creer une inscritpion apartir de la file
values = {
'activity_id' : queues_sorted[0].activity_id,
'member_id' : queues_sorted[0].member_id
}
print "________________________________test 2 __________________"
raise models.ValidationError("erreur")
# creation d'inscription
record.activity_registration_ids = [(0, 0,values)]
#suppression de l'element de la file d'attente
record.activity_queue_ids = [(2, queues_sorted[0].id, 0)]
"""
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)
}
}
else:
emsg = _('Sorry, there is no more place man !')
raise models.ValidationError(emsg)
"""
#traitement manuel pour le passage de la file d'attente en inscription : button sur queue
else :
warningMessage = _('There is a free place for the activity'
' : {}, you can fill it from the queue'
' using the button on queue tab')
return {
'warning' : {
'title' : _('Warning'),
'message': warningMessage.format(record.name)
}
}

View File

@ -25,9 +25,9 @@ class GolemActivityQueue(models.Model):
_name = 'golem.activity.queue'
_description = 'GOLEM Activity Queue'
activity_id = fields.Many2one('golem.activity', required=True)
activity_id = fields.Many2one('golem.activity', required=True, ondelete='cascade')
season_id = fields.Many2one(related='activity_id.season_id')
member_id = fields.Many2one('golem.member', required=True)
member_id = fields.Many2one('golem.member', required=True, ondelete='cascade')
is_current = fields.Boolean('Current season?',
related='activity_id.is_current', store=True)

View File

@ -26,9 +26,13 @@ class GolemMember(models.Model):
activity_queue_ids = fields.One2many('golem.activity.queue',
'member_id','Pending registration')
@api.multi
@api.onchange('activity_registration_ids')
def _checkRemain(self):
for reservation in self.activity_registration_ids:
self.ensure_one()
member_id = self[0]
for reservation in member_id.activity_registration_ids:
activity = reservation.activity_id
if len(activity.activity_registration_ids) > activity.places and activity.queue_allowed:
warning_message = _('This activity : {} is already full, please'
@ -43,6 +47,8 @@ class GolemMember(models.Model):
@api.multi
def queue_register(self):
print "_________________________________________________"
print self
self.ensure_one()
member_id = self[0]
return {

View File

@ -61,7 +61,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="model">golem.activity.queue</field>
<field name="arch" type="xml">
<tree string="Queue Tree" editable="bottom">
<field name="member_id" readonly="1"/>
<field name="member_id"/>
<field name="activity_id" readonly='1'/>
<field name="season_id" readonly='1'/>
<field name="create_date" readonly="1"/>

View File

@ -25,15 +25,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.golem_activity_form" />
<field name="arch" type="xml">
<!--Ajout du case file sur activity form-->
<!--Ajout du case file d'attente et inscription automatisé sur activity form-->
<xpath expr="//field[@name='is_overbooked']" position="after">
<field name="queue_allowed"/>
<field name="automated_registration_from_queue"/>
</xpath>
<!--Ajout du bouton inscription en file d'attente sur activity form-->
<xpath expr="//field[@name='activity_registration_ids']" position="after">
<button class="oe_highlight" name="queue_register"
string="Register in the queue" type="object"
attrs="{'invisible':[('places_remain','>', 0)]}"/>
<button class="oe_highlight" name="register_from_queue"
string="Register from Queue" type="object"/>
</xpath>
<!--Ajout onglet queue sur activity form-->
<page name="invoicing" position="before">
@ -48,8 +52,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="activity_id" readonly="1" />
<field name="season_id" readonly="1" />
</tree>
</field>
</group>
<group>
<button class="oe_highlight" name="register_from_queue"
string="Register from Queue" type="object"/>
</group>
</page>
</page>
</field>

View File

@ -24,7 +24,8 @@ class GolemActivityQueueChooseWizard(models.TransientModel):
"""GOLEM Resource wizard : rchoose activity queue to register in """
_name = "golem.activity.queue.choose.wizard"
activity_id = fields.Many2one("golem.activity")
activity_id = fields.Many2one("golem.activity",
domain=[('places_remain','<',1)])
member_id = fields.Many2one("golem.member")