[REF]GOLEM Activity Queue : usage of qualified contraint instead of overloading write (more efficient)
This commit is contained in:
parent
2f5b1a776b
commit
22fbbe4d11
@ -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.2.0',
|
'version': '10.0.1.2.1',
|
||||||
'category': 'GOLEM',
|
'category': 'GOLEM',
|
||||||
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
'author': 'Youssef El Ouahby, Fabien Bourgeois',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
@ -37,25 +37,6 @@ class GolemActivity(models.Model):
|
|||||||
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
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def write(self, vals):
|
|
||||||
""" Override method write to delete record from queue if they register
|
|
||||||
in activity (only for manual queue processing) """
|
|
||||||
res = super(GolemActivity, self).write(vals)
|
|
||||||
registration_vals = vals.get('activity_registration_ids')
|
|
||||||
if registration_vals:
|
|
||||||
for rval in registration_vals:
|
|
||||||
if rval[0] == 0: # creation case
|
|
||||||
act_id = rval[2].get('activity_id')
|
|
||||||
mem_id = rval[2].get('member_id')
|
|
||||||
if act_id and mem_id:
|
|
||||||
domain = [('activity_id', '=', act_id),
|
|
||||||
('member_id', '=', mem_id)]
|
|
||||||
queue = self.env['golem.activity.queue'].search(domain)
|
|
||||||
if queue:
|
|
||||||
queue.unlink()
|
|
||||||
return res
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def queue_allowed_toggle(self):
|
def queue_allowed_toggle(self):
|
||||||
""" Toggle queue_alowed boolean """
|
""" Toggle queue_alowed boolean """
|
||||||
@ -91,6 +72,16 @@ class GolemActivity(models.Model):
|
|||||||
self.env['golem.activity.registration'].create(values)
|
self.env['golem.activity.registration'].create(values)
|
||||||
queue.unlink()
|
queue.unlink()
|
||||||
|
|
||||||
|
@api.constrains('activity_registration_ids')
|
||||||
|
def handle_queue_at_register(self):
|
||||||
|
""" Remove member from queue if he has been registered directly in
|
||||||
|
activity (only for manual queue processing) """
|
||||||
|
for activity in self:
|
||||||
|
member_ids = activity.activity_registration_ids.mapped('member_id.id')
|
||||||
|
queues_to_remove = activity.activity_queue_ids.filtered(
|
||||||
|
lambda q: q.member_id.id in member_ids)
|
||||||
|
queues_to_remove.unlink()
|
||||||
|
|
||||||
@api.constrains('activity_queue_ids', 'activity_registration_ids',
|
@api.constrains('activity_queue_ids', 'activity_registration_ids',
|
||||||
'places_remain', 'queue_allowed', 'queue_activity_number',
|
'places_remain', 'queue_allowed', 'queue_activity_number',
|
||||||
'auto_registration_from_queue')
|
'auto_registration_from_queue')
|
||||||
|
@ -29,7 +29,6 @@ class GolemActivityQueue(models.Model):
|
|||||||
_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.'))]
|
||||||
|
|
||||||
|
|
||||||
member_id = fields.Many2one('golem.member', required=True,
|
member_id = fields.Many2one('golem.member', required=True,
|
||||||
string='Member', ondelete='cascade',
|
string='Member', ondelete='cascade',
|
||||||
index=True)
|
index=True)
|
||||||
@ -51,4 +50,4 @@ class GolemActivityQueue(models.Model):
|
|||||||
if queue.activity_id in \
|
if queue.activity_id in \
|
||||||
queue.member_id.activity_registration_all_ids.mapped('activity_id'):
|
queue.member_id.activity_registration_all_ids.mapped('activity_id'):
|
||||||
raise ValidationError(_('The member your trying to add to the queue'
|
raise ValidationError(_('The member your trying to add to the queue'
|
||||||
' is already registred for this activity'))
|
' is already registered for this activity'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user