Commit 1c919eba by François C.

Modifications pour recalcul statut suite choix rattrapage dans espace membre

parent 8634d413
......@@ -74,6 +74,18 @@ class ResPartner(models.Model):
"Number of shift done with both of the associate",
default= 0)
def _is_in_delay(self):
"""Necessary because date_delay_stop may not have been computed yet"""
answer = False
max_date = False
for extension in self.sudo().extension_ids:
if extension.date_start <= fields.Datetime.now() and\
extension.date_stop > fields.Datetime.now():
max_date = max(max_date, extension.date_stop)
if max_date and max_date > fields.Datetime.now():
answer = True
_logger.debug("%s est en délai ? Réponse = %s", str(self.id), str(answer))
return answer
@api.multi
def _compute_lacagette_working_state(self):
......@@ -121,14 +133,11 @@ class ResPartner(models.Model):
state = 'unsubscribed'
self.env['shift.counter.event'].unsubscribe_partner(partner, unsubscribe_limit, points)
else:
if partner.date_alert_stop:
if partner.makeups_to_do == 0 and partner.date_delay_stop and partner.date_delay_stop > current_datetime:
if partner.makeups_to_do == 0 and partner._is_in_delay():
state = 'delay'
else:
state = 'suspended'
else:
state = 'suspended'
else:
state = 'unsubscribed'
partner.working_state = state
......@@ -178,10 +187,14 @@ class ResPartner(models.Model):
@api.multi
def recompute_member_states(self):
def recompute_member_states(self, params=''):
for record in self:
record._compute_lacagette_working_state()
record._compute_cooperative_state()
associated_binome = self.env['res.partner'].search([('parent_id','=',record.id), ('is_associated_people', '=', True)])
if associated_binome:
for assoc_people in associated_binome:
assoc_people.recompute_member_states()
@api.model
def run_process_target_status(self):
......
......@@ -43,3 +43,13 @@ class ShiftRegistration(models.Model):
to_add += 1
s.partner_id.update({'makeups_to_add': to_add})
return super(ShiftRegistration, self).write(vals)
@api.model
def create(self, vals):
_logger.debug("Create shift_registration Vals recues creation = %s", str(vals))
res = super(ShiftRegistration, self).create(vals)
if 'is_makeup' in vals and vals['is_makeup'] is True:
member = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
member.write({'makeups_to_do': member.makeups_to_do - 1})
member.recompute_member_states()
return res
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment