ajout du fonction qui empeche l'inscritption en queue si une inscription existe

This commit is contained in:
eloyoussef 2018-02-26 13:27:45 +01:00
parent 0d4e819e5d
commit d479a0ca45
5 changed files with 36 additions and 6 deletions

View File

@ -36,6 +36,12 @@ class GolemActivity(models.Model):
store=True, string='Pending registration number')
#Ajouter/supprimer une file à l'activité et afficher popup pour traitement automatisé
@api.multi
def queue_allowed_toggle(self):
for activity in self:
activity.queue_allowed = not activity.queue_allowed
#contraint sur nombre d'inscription : une desincription declanche une inscription depuis attente
@api.multi
@api.constrains('activity_registration_ids')

View File

@ -19,10 +19,12 @@
""" GOLEM activities related models """
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class GolemActivityQueue(models.Model):
""" GOLEM Activity Queue """
_name = 'golem.activity.queue'
_order = "sequence"
_description = 'GOLEM Activity Queue'
activity_id = fields.Many2one('golem.activity', required=True,
@ -48,3 +50,16 @@ class GolemActivityQueue(models.Model):
record.is_activity_full = "Full activity"
else:
record.is_activity_full = "Not full activity"
@api.constrains('member_id')
def _check_member_registration(self):
""" Forbid registration in queue when member is already registred in the
activity """
for queue in self:
domain = [('member_id', '=', queue.member_id.id),
('activity_id', '=', queue.activity_id.id)]
#verifier si un enrigistrement avec le meme membre et activité est déja fait
registrations = self.env['golem.activity.registration'].search(domain)
#si oui lancer un erreur
if len(registrations):
raise ValidationError(_('The member your trying to add to the queue'
' is already registred for this activity'))

View File

@ -34,7 +34,7 @@ class GolemMember(models.Model):
member_id = self[0]
for registration in member_id.activity_registration_ids:
activity = reservation.activity_id
activity = registration.activity_id
if len(activity.activity_registration_ids) > activity.places and activity.queue_allowed:
warning_message = _('This activity : {} is already full, please'
' discard changes and register in'

View File

@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<tree string="Queue Tree" editable="top" colors="grey: places_remain == 0; blue : places_remain &gt;= 1">
<field name="sequence" widget="handle"/>
<field name="member_id"/>
<field name="activity_id" readonly='1'/>
<field name="activity_id"/>
<field name="season_id" readonly='1'/>
<field name="create_date" readonly="1"/>
<field name='places_remain' />

View File

@ -40,7 +40,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</xpath>
<!--Ajout onglet queue sur activity form-->
<page name="invoicing" position="before">
<xpath expr="//page[@name='invoicing']" position="before">
<page name="queue" string="Queue">
<group>
<field name="queue_activity_number" readonly='1'/>
@ -61,7 +61,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
string="Register from Queue" type="object"/>
</group>
</page>
</page>
</xpath>
<!--Ajout du bouton "ajouter une file"-->
<xpath expr="//header" position="inside">
<button class="oe_highlight" name="queue_allowed_toggle"
string="Add Queue" type="object"
attrs="{'invisible': [('queue_allowed', '=', True)]}"/>
<button class="oe_highlight" name="queue_allowed_toggle"
string="Remove Queue" type="object"
attrs="{'invisible': [('queue_allowed', '=', False)]}"/>
</xpath>
</field>
</record>