Commit 3277594d by Yvon Kerdoncuff

#7320 : trigger error when trying to add makeup to an unsubscribed person

parent b067f004
Pipeline #4051 failed with stage
...@@ -412,7 +412,6 @@ def update_members_makeups(request): ...@@ -412,7 +412,6 @@ def update_members_makeups(request):
makeup_change_count = target_makeups_nb - cs.get_member_makeups_to_do(cm.id) makeup_change_count = target_makeups_nb - cs.get_member_makeups_to_do(cm.id)
points_target = cm.get_member_points("standard") - makeup_change_count points_target = cm.get_member_points("standard") - makeup_change_count
if points_target <= unsubscription_limit: if points_target <= unsubscription_limit:
error = []
error["error"]\ error["error"]\
= "L'ajout de rattrapage a été annulé car il provoquerait la désinscription d'un membre." = "L'ajout de rattrapage a été annulé car il provoquerait la désinscription d'un membre."
return JsonResponse(error, status=400) return JsonResponse(error, status=400)
...@@ -420,6 +419,10 @@ def update_members_makeups(request): ...@@ -420,6 +419,10 @@ def update_members_makeups(request):
if res_exempted: if res_exempted:
error["error"] = "L'opération de rattrapage a été annulée car le membre ciblé est exempté." error["error"] = "L'opération de rattrapage a été annulée car le membre ciblé est exempté."
return JsonResponse(error, status=400) return JsonResponse(error, status=400)
if cm.has_state_unsubscribed_gone_or_associated():
error["error"] = ("L'opération de rattrapage a été annulée car le membre ciblé est désinscrit, parti ou"
"associé.")
return JsonResponse(error, status=400)
# Save computed data in member_data. It will be useful to update makeups and points. # Save computed data in member_data. It will be useful to update makeups and points.
members_data[member_data["member_id"]]["points_diff"] = - makeup_change_count members_data[member_data["member_id"]]["points_diff"] = - makeup_change_count
......
...@@ -1158,6 +1158,12 @@ class CagetteMember(models.Model): ...@@ -1158,6 +1158,12 @@ class CagetteMember(models.Model):
else: else:
return False return False
def has_state_unsubscribed_gone_or_associated(self):
c = [['id', '=', self.id]]
f = ['cooperative_state']
state = self.o_api.search_read("res.partner", c, f)[0]["cooperative_state"]
return state in ("unsubscribed", "gone", "associated")
class CagetteMembers(models.Model): class CagetteMembers(models.Model):
"""Class to manage operations on all members or part of them.""" """Class to manage operations on all members or part of them."""
......
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