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 #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 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) 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 #ajout d'un champs pour calculer le nombre d'inscription en file d'attente
queue_activity_number = fields.Integer(compute="_queue_activity_number", queue_activity_number = fields.Integer(compute="_queue_activity_number",
store=True , string='Pending registration number') store=True , string='Pending registration number')
#calculer le nombre d'inscription sur la file d'attente
@api.multi @api.multi
@api.depends('activity_queue_ids')
def _queue_activity_number(self): def _queue_activity_number(self):
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
@api.multi @api.multi
def queue_register(self): def queue_register(self):
self.ensure_one() 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') @api.onchange('activity_registration_ids')
def _checkRemain(self): def _checkRemain(self):
if len(self.activity_registration_ids) > self.places and self.queue_allowed: for record in self:
return { if len(record.activity_registration_ids) > record.places and record.queue_allowed:
'warning' : { message = _('No remaining place for the activity : {}, please'
'title' : _('Warning'), ' discard changes and register in the queue using'
'message': _('No remaining place, please register in the queue'), ' 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:
""" # passage de l'element depuis la file d'attente automatiquement
@api.multi if record.automated_registration_from_queue:
@api.constrains('places_remain') #traitement qui bloque avec message d'erreur can't adapt activitiy_id to newId
def _check_remaining_places(self): """
#Forbid inscription when there is no more place #recupérer la liste en file d'attente
for activity in self: queues = record.activity_queue_ids
if activity.places_remain < 5: #trier la liste selon l'id : récupérer l'ancien element
queues_sorted = sorted(queues, key=lambda k: k['id'])
if self.queue_allowed: #valeures pour creer une inscritpion apartir de la file
print "__________________________ test ______________________" values = {
return { 'activity_id' : queues_sorted[0].activity_id,
'name' : _('Do you want to add your registration to the queue?'), 'member_id' : queues_sorted[0].member_id
'type' : 'ir.actions.act_window',
'res_model' : 'golem.activity.queue',
'view_mode': 'form',
'view_type': 'form',
'target': 'new',
} }
print "________________________________test 2 __________________" # creation d'inscription
raise models.ValidationError("erreur") 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: #traitement manuel pour le passage de la file d'attente en inscription : button sur queue
emsg = _('Sorry, there is no more place man !') else :
raise models.ValidationError(emsg) 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' _name = 'golem.activity.queue'
_description = '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') 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?', is_current = fields.Boolean('Current season?',
related='activity_id.is_current', store=True) 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', activity_queue_ids = fields.One2many('golem.activity.queue',
'member_id','Pending registration') 'member_id','Pending registration')
@api.multi
@api.onchange('activity_registration_ids') @api.onchange('activity_registration_ids')
def _checkRemain(self): 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 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'
@ -43,6 +47,8 @@ class GolemMember(models.Model):
@api.multi @api.multi
def queue_register(self): def queue_register(self):
print "_________________________________________________"
print self
self.ensure_one() self.ensure_one()
member_id = self[0] member_id = self[0]
return { 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="model">golem.activity.queue</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Queue Tree" editable="bottom"> <tree string="Queue Tree" editable="bottom">
<field name="member_id" readonly="1"/> <field name="member_id"/>
<field name="activity_id" readonly='1'/> <field name="activity_id" readonly='1'/>
<field name="season_id" readonly='1'/> <field name="season_id" readonly='1'/>
<field name="create_date" 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="model">golem.activity</field>
<field name="inherit_id" ref="golem_activity.golem_activity_form" /> <field name="inherit_id" ref="golem_activity.golem_activity_form" />
<field name="arch" type="xml"> <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"> <xpath expr="//field[@name='is_overbooked']" position="after">
<field name="queue_allowed"/> <field name="queue_allowed"/>
<field name="automated_registration_from_queue"/>
</xpath> </xpath>
<!--Ajout du bouton inscription en file d'attente sur activity form--> <!--Ajout du bouton inscription en file d'attente sur activity form-->
<xpath expr="//field[@name='activity_registration_ids']" position="after"> <xpath expr="//field[@name='activity_registration_ids']" position="after">
<button class="oe_highlight" name="queue_register" <button class="oe_highlight" name="queue_register"
string="Register in the queue" type="object" string="Register in the queue" type="object"
attrs="{'invisible':[('places_remain','>', 0)]}"/> attrs="{'invisible':[('places_remain','>', 0)]}"/>
<button class="oe_highlight" name="register_from_queue"
string="Register from Queue" type="object"/>
</xpath> </xpath>
<!--Ajout onglet queue sur activity form--> <!--Ajout onglet queue sur activity form-->
<page name="invoicing" position="before"> <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="activity_id" readonly="1" />
<field name="season_id" readonly="1" /> <field name="season_id" readonly="1" />
</tree> </tree>
</field> </field>
</group> </group>
<group>
<button class="oe_highlight" name="register_from_queue"
string="Register from Queue" type="object"/>
</group>
</page> </page>
</page> </page>
</field> </field>

View File

@ -24,7 +24,8 @@ class GolemActivityQueueChooseWizard(models.TransientModel):
"""GOLEM Resource wizard : rchoose activity queue to register in """ """GOLEM Resource wizard : rchoose activity queue to register in """
_name = "golem.activity.queue.choose.wizard" _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") member_id = fields.Many2one("golem.member")