Commit f2da7d5a by Yvon Kerdoncuff

#7319 : prevent adding makeup to an exempted person

parent 47d81479
......@@ -10,6 +10,7 @@ from shifts.models import CagetteShift
from members_space.models import CagetteMembersSpace
from outils.common import MConfig
from datetime import datetime, date
import shifts.fonctions
default_msettings = {'msg_accueil': {'title': 'Message borne accueil',
'type': 'textarea',
......@@ -397,6 +398,7 @@ def update_members_makeups(request):
# Perform checks and compute some data in a loop on members.
cs = CagetteShift()
unsubscription_limit = api.get_system_param('lacagette_membership.points_limit_to_get_unsubscribed')
error = []
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
target_makeups_nb = int(member_data["target_makeups_nb"])
......@@ -404,7 +406,6 @@ def update_members_makeups(request):
# Prevent setting a negative number of makeups_to_do https://redmine.coopdev.fr/issues/6090
# This could happen when bdm has two screens open and clicks on minus btn on a coop line
# with exactly 1 makeup_to_do on both screens
error = []
error["error"] = "L'opération de rattrapage a été annulée car le nombre de rattrapage cible est négatif."
return JsonResponse(error, status=400)
makeup_change_count = target_makeups_nb - cs.get_member_makeups_to_do(cm.id)
......@@ -414,6 +415,10 @@ def update_members_makeups(request):
error["error"]\
= "L'ajout de rattrapage a été annulé car il provoquerait la désinscription d'un membre."
return JsonResponse(error, status=400)
res_exempted = shifts.fonctions.get_exempted_ids_from(api, [member_data["member_id"]])
if res_exempted:
error["error"] = "L'opération de rattrapage a été annulée car le membre ciblé est exempté."
return JsonResponse(error, status=400)
# 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
......
......@@ -41,3 +41,10 @@ def get_shift_partner(api, id, start_date=None, end_date=None):
else:
is_ftop = True
return [shifts, is_ftop]
def get_exempted_ids_from(api, partner_ids):
cond = [['id', 'in', partner_ids],
['cooperative_state', 'in', ['exempted']]]
fields = ['id']
return api.search_read('res.partner', cond, fields)
\ No newline at end of file
......@@ -836,10 +836,7 @@ class CagetteServices(models.Model):
ids = []
excluded_partner = []
canceled_reg_ids = [] # for exempted people
cond = [['id', 'in', partner_ids],
['cooperative_state', 'in', ['exempted']]]
fields = ['id']
res_exempted = api.search_read('res.partner', cond, fields)
res_exempted = shifts.fonctions.get_exempted_ids_from(api, partner_ids)
for r in res_exempted:
excluded_partner.append(int(r['id']))
for r in 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