Commit 27ac19fc by François C.

Correctifs suite remontées Antonin

parent df15e861
...@@ -58,7 +58,6 @@ class ResPartner(models.Model): ...@@ -58,7 +58,6 @@ class ResPartner(models.Model):
compute='_compute_lacagette_cooperative_state' compute='_compute_lacagette_cooperative_state'
) )
working_state = fields.Selection( working_state = fields.Selection(
selection=WORKING_STATE_SELECTION, string='Working State', store=True, selection=WORKING_STATE_SELECTION, string='Working State', store=True,
compute='_compute_lacagette_working_state', help="This state depends on the" compute='_compute_lacagette_working_state', help="This state depends on the"
...@@ -71,9 +70,12 @@ class ResPartner(models.Model): ...@@ -71,9 +70,12 @@ class ResPartner(models.Model):
default= 0) default= 0)
@api.multi @api.multi
def _compute_lacagette_working_state(self): def _compute_lacagette_working_state(self):
_logger.debug("Dans _compute_lacagette_working_state") _logger.debug("Dans _compute_lacagette_working_state")
conf = self.env['ir.config_parameter']
unsubscribe_limit = int(conf.get_param("lacagette_membership.points_limit_to_get_unsubscribed"))
current_datetime = fields.Datetime.now() current_datetime = fields.Datetime.now()
for partner in self: for partner in self:
_logger.debug("partner_id = %s, cooperative_state = %s", str(partner.id), str(partner.cooperative_state)) _logger.debug("partner_id = %s, cooperative_state = %s", str(partner.id), str(partner.cooperative_state))
...@@ -82,16 +84,10 @@ class ResPartner(models.Model): ...@@ -82,16 +84,10 @@ class ResPartner(models.Model):
is_exempted = partner.leave_ids.filtered( is_exempted = partner.leave_ids.filtered(
lambda l: l.state == 'done' and l.start_date <= current_datetime and l.stop_date >= lambda l: l.state == 'done' and l.start_date <= current_datetime and l.stop_date >=
current_datetime and l.partner_state == 'exempted') current_datetime and l.partner_state == 'exempted')
_logger.debug("is_exempted = %s", str(is_exempted)) # _logger.debug("is_exempted = %s", str(is_exempted))
if is_exempted: if is_exempted:
_logger.debug("On met le statut exempté") _logger.debug("On met le statut exempté")
state = 'exempted' state = 'exempted'
#for l in list(partner.leave_ids):
# if l.stop_date > current_datetime and l.partner_state == 'exempted':
# state = 'exempted'
# fulldata = l.read()
# _logger.debug("for l in partner.leave_ids")
# _logger.debug(str(fulldata))
if state != 'exempted': if state != 'exempted':
if partner.is_associated_people is True: if partner.is_associated_people is True:
state = partner.parent_id.cooperative_state state = partner.parent_id.cooperative_state
...@@ -110,6 +106,10 @@ class ResPartner(models.Model): ...@@ -110,6 +106,10 @@ class ResPartner(models.Model):
else: else:
points = partner.final_ftop_point points = partner.final_ftop_point
if points < 0: if points < 0:
if points <= unsubscribe_limit:
state = 'unsubscribed'
self.env['shift.counter.event'].unsubscribe_partner(partner, unsubscribe_limit, points)
else:
if partner.date_alert_stop: if partner.date_alert_stop:
if partner.date_delay_stop > current_datetime: if partner.date_delay_stop > current_datetime:
state = 'delay' state = 'delay'
...@@ -134,7 +134,7 @@ class ResPartner(models.Model): ...@@ -134,7 +134,7 @@ class ResPartner(models.Model):
# _logger.debug("Partner = %s", str(partner.read())) # _logger.debug("Partner = %s", str(partner.read()))
_logger.debug("partner_id = %s, working_state = %s", str(partner.id), str(partner.working_state)) _logger.debug("partner_id = %s, working_state = %s", str(partner.id), str(partner.working_state))
state = 'up_to_date' state = 'up_to_date'
if partner.is_member is False and partner.is_associated_people is False and partner.is_worker_member is False: if partner.is_member is False and partner.is_associated_people is False:
state= 'not_concerned' state= 'not_concerned'
else: else:
if partner.is_associated_people: if partner.is_associated_people:
...@@ -327,6 +327,9 @@ class ResPartner(models.Model): ...@@ -327,6 +327,9 @@ class ResPartner(models.Model):
_logger.info("valeurs recues pour write partner = %s", str(vals)) _logger.info("valeurs recues pour write partner = %s", str(vals))
if 'cooperative_state' in vals: if 'cooperative_state' in vals:
self._write_state_change(vals['cooperative_state']) self._write_state_change(vals['cooperative_state'])
if 'barcode_base' in vals:
vals['cooperative_state'] = 'unsubscribed'
vals['working_state'] = 'unsubscribed'
return super(ResPartner, self).write(vals) return super(ResPartner, self).write(vals)
......
...@@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__) ...@@ -9,6 +9,8 @@ _logger = logging.getLogger(__name__)
class ShiftCounterEvent(models.Model): class ShiftCounterEvent(models.Model):
_inherit = 'shift.counter.event' _inherit = 'shift.counter.event'
technical_note = fields.Char(string="Technical note such as 'no trigger'", required=True)
def _alter_point_event_depending_on_makeups_total_count(self, res_partner, vals, suspension_limit): def _alter_point_event_depending_on_makeups_total_count(self, res_partner, vals, suspension_limit):
""" """
This code helps keeping the consistency between std_counter and makeup total count. This code helps keeping the consistency between std_counter and makeup total count.
...@@ -88,7 +90,7 @@ class ShiftCounterEvent(models.Model): ...@@ -88,7 +90,7 @@ class ShiftCounterEvent(models.Model):
'type': partner.shift_type, 'type': partner.shift_type,
'partner_id': partner.id, 'partner_id': partner.id,
'point_qty': points_update, 'point_qty': points_update,
'note': 'no trigger' 'technical_note': 'no trigger'
} }
self.env['shift.counter.event'].create(data) self.env['shift.counter.event'].create(data)
...@@ -116,8 +118,10 @@ class ShiftCounterEvent(models.Model): ...@@ -116,8 +118,10 @@ class ShiftCounterEvent(models.Model):
mail_template = self.env.ref('coop_membership.unsubscribe_email') mail_template = self.env.ref('coop_membership.unsubscribe_email')
if mail_template: if mail_template:
mail_template.send_mail(partner.id) mail_template.send_mail(partner.id)
else:
_logger.error("run_unsubscribe_process - mail_template not found")
except Exception as e: except Exception as e:
_logger.error("run_unsubscribe_process - send mail : %s - Process not interrupted", str(e)) _logger.error("run_unsubscribe_process - send mail : %s - Process interrupted", str(e))
partner.update(new_values) partner.update(new_values)
except Exception as e: except Exception as e:
_logger.error("run_unsubscribe_process : %s", str(e)) _logger.error("run_unsubscribe_process : %s", str(e))
...@@ -143,7 +147,7 @@ class ShiftCounterEvent(models.Model): ...@@ -143,7 +147,7 @@ class ShiftCounterEvent(models.Model):
_logger.error("Counter shift type is not corresponding to partner shift_type : %s", str(to_consider_vals)) _logger.error("Counter shift type is not corresponding to partner shift_type : %s", str(to_consider_vals))
return None return None
# Do not continue if method has been triggered by a 'no trigger' created shift_counter_event (while executing unsubscribe_partner) # Do not continue if method has been triggered by a 'no trigger' created shift_counter_event (while executing unsubscribe_partner)
if 'note' in to_consider_vals and to_consider_vals == 'no trigger': if 'technical_note' in to_consider_vals and to_consider_vals['technical_note'] == 'no trigger':
return None return None
points_after_computation = partner.final_ftop_point if partner.shift_type == "ftop" else partner.final_standard_point points_after_computation = partner.final_ftop_point if partner.shift_type == "ftop" else partner.final_standard_point
target_status = None target_status = None
...@@ -176,12 +180,19 @@ class ShiftCounterEvent(models.Model): ...@@ -176,12 +180,19 @@ class ShiftCounterEvent(models.Model):
# don't block process if an error occurs here # don't block process if an error occurs here
_logger.error("Error during _update_partner_target_status : %s", str(e)) _logger.error("Error during _update_partner_target_status : %s", str(e))
@api.model
def affect_associated_people(self, parent_id):
associated = self.env['res.partner'].search([('parent_id', '=', parent_id)])
if associated:
for a in associated:
a.recompute_member_states()
@api.model @api.model
def write(self, vals): def write(self, vals):
res = super(ShiftCounterEvent, self).write(vals) res = super(ShiftCounterEvent, self).write(vals)
_logger.info("Vals recues = %s", str(vals)) _logger.info("Vals recues = %s", str(vals))
self._update_partner_target_status(vals) self._update_partner_target_status(vals)
self.affect_associated_people(vals['partner_id'])
return res return res
@api.model @api.model
...@@ -189,5 +200,6 @@ class ShiftCounterEvent(models.Model): ...@@ -189,5 +200,6 @@ class ShiftCounterEvent(models.Model):
_logger.info("Vals recues creation = %s", str(vals)) _logger.info("Vals recues creation = %s", str(vals))
res = super(ShiftCounterEvent, self).create(vals) res = super(ShiftCounterEvent, self).create(vals)
self._update_partner_target_status(vals) self._update_partner_target_status(vals)
self.affect_associated_people(vals['partner_id'])
return res return res
...@@ -33,4 +33,6 @@ class ShiftTemplateRegistrationLine(models.Model): ...@@ -33,4 +33,6 @@ class ShiftTemplateRegistrationLine(models.Model):
coop_state = 'unsubscribed' coop_state = 'unsubscribed'
member.update({'cooperative_state': coop_state}) member.update({'cooperative_state': coop_state})
_logger.info("new cooperative_state = %s for %s", coop_state, str(member.id)) _logger.info("new cooperative_state = %s for %s", coop_state, str(member.id))
_logger.info("On va recalculer le statut du membre = %s", str(member.id))
member.recompute_member_states()
return super_res return super_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