Commit 1c919eba by François C.

Modifications pour recalcul statut suite choix rattrapage dans espace membre

parent 8634d413
...@@ -52,7 +52,7 @@ class ResPartner(models.Model): ...@@ -52,7 +52,7 @@ class ResPartner(models.Model):
makeups_to_add = fields.Integer( makeups_to_add = fields.Integer(
"Number of make-ups to add (set by shift_registration)", "Number of make-ups to add (set by shift_registration)",
default= 0) default= 0)
# To be removed # To be removed
target_status = fields.Selection( target_status = fields.Selection(
selection=TARGET_STATUS_SELECTION, default='') selection=TARGET_STATUS_SELECTION, default='')
...@@ -74,6 +74,18 @@ class ResPartner(models.Model): ...@@ -74,6 +74,18 @@ class ResPartner(models.Model):
"Number of shift done with both of the associate", "Number of shift done with both of the associate",
default= 0) 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 @api.multi
def _compute_lacagette_working_state(self): def _compute_lacagette_working_state(self):
...@@ -121,16 +133,13 @@ class ResPartner(models.Model): ...@@ -121,16 +133,13 @@ class ResPartner(models.Model):
state = 'unsubscribed' state = 'unsubscribed'
self.env['shift.counter.event'].unsubscribe_partner(partner, unsubscribe_limit, points) self.env['shift.counter.event'].unsubscribe_partner(partner, unsubscribe_limit, points)
else: else:
if partner.date_alert_stop: if partner.makeups_to_do == 0 and partner._is_in_delay():
if partner.makeups_to_do == 0 and partner.date_delay_stop and partner.date_delay_stop > current_datetime: state = 'delay'
state = 'delay'
else:
state = 'suspended'
else: else:
state = 'suspended' state = 'suspended'
else: else:
state = 'unsubscribed' state = 'unsubscribed'
partner.working_state = state partner.working_state = state
# Overriding by calling our own method (which is mentionned in field declaration) # Overriding by calling our own method (which is mentionned in field declaration)
@api.depends('is_blocked', 'final_standard_point', 'final_ftop_point', 'shift_type', 'date_alert_stop', 'date_delay_stop', 'leave_ids.state') @api.depends('is_blocked', 'final_standard_point', 'final_ftop_point', 'shift_type', 'date_alert_stop', 'date_delay_stop', 'leave_ids.state')
...@@ -178,10 +187,14 @@ class ResPartner(models.Model): ...@@ -178,10 +187,14 @@ class ResPartner(models.Model):
@api.multi @api.multi
def recompute_member_states(self): def recompute_member_states(self, params=''):
for record in self: for record in self:
record._compute_lacagette_working_state() record._compute_lacagette_working_state()
record._compute_cooperative_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 @api.model
def run_process_target_status(self): def run_process_target_status(self):
......
...@@ -43,3 +43,13 @@ class ShiftRegistration(models.Model): ...@@ -43,3 +43,13 @@ class ShiftRegistration(models.Model):
to_add += 1 to_add += 1
s.partner_id.update({'makeups_to_add': to_add}) s.partner_id.update({'makeups_to_add': to_add})
return super(ShiftRegistration, self).write(vals) 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