Commit 850f73f5 by François C.

Fixing makups_to_do bug

parent cc641c14
......@@ -128,6 +128,18 @@ class ShiftCounterEvent(models.Model):
return None
return result
def _update_partner_makeups_to_do(self, vals):
if 'technical_note' in vals and vals['technical_note'] == 'no trigger':
return 0
try:
if 'point_qty' in vals and vals['point_qty'] < 0:
res_partner = self.env['res.partner'].search([('id', '=', vals['partner_id'])])
res_partner[0].update({makeups_to_do: partner[0].makeups_to_do + 1})
return 0
except Exception as e:
_logger.error("_update_partner_makeups_to_do : %s", str(e))
return 1
def _update_partner_target_status(self, vals):
"""actions when points are removed or added"""
partner = None
......@@ -142,7 +154,7 @@ class ShiftCounterEvent(models.Model):
to_consider_vals = vals # TODO : Reimplement this adjustments
if res_partner:
partner = res_partner[0]
_logger.info("partner = : %s", str(partner))
_logger.info("partner = : %s, makeups_to_do : %s", str(partner), str(partner.makeups_to_do))
if to_consider_vals['type'] != partner.shift_type:
_logger.error("Counter shift type is not corresponding to partner shift_type : %s", str(to_consider_vals))
return None
......@@ -171,8 +183,6 @@ class ShiftCounterEvent(models.Model):
target_status = 'delay'
if target_status is not None:
vals_for_update = {'working_state': target_status, 'cooperative_state': target_status}
if vals['point_qty'] < 0:
vals_for_update['makeups_to_do'] = partner.makeups_to_do + 1
partner.update(vals_for_update)
if target_status == 'unsubscribed':
self.unsubscribe_partner(partner, unsubscribe_limit, points_after_computation)
......@@ -189,8 +199,9 @@ class ShiftCounterEvent(models.Model):
@api.model
def write(self, vals):
res = super(ShiftCounterEvent, self).write(vals)
_logger.info("Vals recues = %s", str(vals))
self._update_partner_makeups_to_do(vals)
res = super(ShiftCounterEvent, self).write(vals)
self._update_partner_target_status(vals)
self.affect_associated_people(vals['partner_id'])
return res
......@@ -198,6 +209,7 @@ class ShiftCounterEvent(models.Model):
@api.model
def create(self, vals):
_logger.info("Vals recues creation = %s", str(vals))
self._update_partner_makeups_to_do(vals)
res = super(ShiftCounterEvent, self).create(vals)
self._update_partner_target_status(vals)
self.affect_associated_people(vals['partner_id'])
......
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