Commit e02051af by Yvon Kerdoncuff

log / triggers error where there are potentially negative makeups_to_do values that are set

parent 26fb019c
Pipeline #4116 canceled with stage
......@@ -788,6 +788,17 @@ def create_pair(request):
child_makeups = child['makeups_to_do']
parent_makeups = parent['makeups_to_do']
if child_makeups < 0 or parent_makeups < 0:
coop_logger.error(
"Erreur : le suppléant (%s) ou le titulaire (%s) a un compteur de rattrapages négatif.",
child_makeups,
parent_makeups
)
return JsonResponse(
{"message": "Erreur : le suppléant ou le titulaire a un compteur de rattrapages négatif."},
status=409
)
child_scheduled_makeups = shifts.fonctions.get_scheduled_makeups(api, partner_ids=[child_id])
parent_scheduled_makeups_length = len(shifts.fonctions.get_scheduled_makeups(api, partner_ids=[parent_id]))
......
......@@ -1125,6 +1125,11 @@ class CagetteMember(models.Model):
def update_member_makeups(self, member_data):
api = OdooAPI()
makeups_to_do = int(member_data["target_makeups_nb"])
if makeups_to_do < 0:
coop_logger.error(
"Erreur : dans update_member_makeups, target makeups_to_do = %s.",
makeups_to_do
)
f = {'makeups_to_do': makeups_to_do}
res_item = api.update('res.partner', [self.id], f)
res = {
......
......@@ -223,14 +223,20 @@ class CagetteShift(models.Model):
try:
# Ok if makeups_to_do go under 0, until unselect_makeup is called,
# (this is needed when set_shift is called from change_shift)
# This is the only place where we are allowed to set a negative count of makeups_to_do,
# only when we unselect_makeup later.
makeups_to_do_target = self.get_member_makeups_to_do(partner_id) - 1
res_decrement = self.o_api.update(
'res.partner',
[partner_id],
{"makeups_to_do": self.get_member_makeups_to_do(partner_id) - 1}
{"makeups_to_do": makeups_to_do_target}
)
# Usually not needed because another odoo method that automaticaly triggers status recompute is
# often called after a makeup change, manual update IS REQUIRED here.
self.o_api.execute('res.partner', 'recompute_member_states', [partner_id])
if makeups_to_do_target < 0:
coop_logger.debug("Setting a negative makeups_to_do value in set_shift prior to call unselect_makeup.")
else:
# Usually not needed because another odoo method that automaticaly triggers status recompute is
# often called after a makeup change, manual update IS REQUIRED here.
self.o_api.execute('res.partner', 'recompute_member_states', [partner_id])
except Exception as e:
coop_logger.error("Decrement makeups to do and recompute member states : %s, %s", str(e), str(data))
......
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