Commit 0f62095c by Yvon Kerdoncuff

Merge branch '5021-reset-makeups-to-do-when-changing-from-std-to-non-std-shift'…

Merge branch '5021-reset-makeups-to-do-when-changing-from-std-to-non-std-shift' into 'dev_cooperatic'

extract method, create method to simulate bdm lowering all makeups_to_do and…

See merge request !237
parents 05ed9ebe 84ada4ce
Pipeline #2981 failed with stage
in 1 minute 7 seconds
...@@ -383,6 +383,15 @@ def update_members_makeups(request): ...@@ -383,6 +383,15 @@ def update_members_makeups(request):
members_data = json.loads(request.body.decode()) members_data = json.loads(request.body.decode())
res["res"] = [] res["res"] = []
update_members_makeups_core(members_data, res)
response = JsonResponse(res)
else:
res["message"] = "Unauthorized"
response = JsonResponse(res, status=403)
return response
def update_members_makeups_core(members_data, res):
for member_data in members_data: for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"])) cm = CagetteMember(int(member_data["member_id"]))
...@@ -392,7 +401,7 @@ def update_members_makeups(request): ...@@ -392,7 +401,7 @@ def update_members_makeups(request):
if member_data["member_shift_type"] == "standard": if member_data["member_shift_type"] == "standard":
# Set points to minus the number of makeups to do (limited to -2) # Set points to minus the number of makeups to do (limited to -2)
target_points = - int(member_data["target_makeups_nb"]) target_points = - int(member_data["target_makeups_nb"])
if (target_points < -2) : if (target_points < -2):
target_points = -2 target_points = -2
member_points = cm.get_member_points("standard") member_points = cm.get_member_points("standard")
...@@ -423,11 +432,7 @@ def update_members_makeups(request): ...@@ -423,11 +432,7 @@ def update_members_makeups(request):
# even though it shows 'J'ai 0 rattrapages à effecter' for the delay state change to be eventually triggered) # even though it shows 'J'ai 0 rattrapages à effecter' for the delay state change to be eventually triggered)
api = OdooAPI() api = OdooAPI()
api.execute('res.partner', 'run_process_target_status', []) api.execute('res.partner', 'run_process_target_status', [])
response = JsonResponse(res)
else:
res["message"] = "Unauthorized"
response = JsonResponse(res, status=403)
return response
def regenerate_member_delay(request): def regenerate_member_delay(request):
""" From BDM admin, close existing extension if exists & recreate for 6 months """ """ From BDM admin, close existing extension if exists & recreate for 6 months """
...@@ -603,6 +608,7 @@ def shift_subscription(request): ...@@ -603,6 +608,7 @@ def shift_subscription(request):
shift_template_id = CagetteServices.get_exemptions_shift_id() shift_template_id = CagetteServices.get_exemptions_shift_id()
m = CagetteMember(partner_id) m = CagetteMember(partner_id)
api = OdooAPI()
unsubscribe_first = data["unsubscribe_first"] unsubscribe_first = data["unsubscribe_first"]
if unsubscribe_first is True: if unsubscribe_first is True:
...@@ -619,11 +625,13 @@ def shift_subscription(request): ...@@ -619,11 +625,13 @@ def shift_subscription(request):
) )
res["unsubscribe_member"] = m.unsubscribe_member(changing_shift = True) res["unsubscribe_member"] = m.unsubscribe_member(changing_shift = True)
# https://redmine.coopdev.fr/issues/4715
lower_makeup_count_to_zero_if_moving_from_std_to_ftop(api, partner_id, shift_type, res)
reg_id = m.create_coop_shift_subscription(shift_template_id, shift_type) reg_id = m.create_coop_shift_subscription(shift_template_id, shift_type)
# Return necessary data # Return necessary data
if reg_id is not None: if reg_id is not None:
api = OdooAPI()
c = [['id', '=', shift_template_id]] c = [['id', '=', shift_template_id]]
f = ['id', 'name'] f = ['id', 'name']
res["shift_template"] = api.search_read('shift.template', c, f)[0] res["shift_template"] = api.search_read('shift.template', c, f)[0]
...@@ -640,6 +648,25 @@ def shift_subscription(request): ...@@ -640,6 +648,25 @@ def shift_subscription(request):
return response return response
def lower_makeup_count_to_zero_if_moving_from_std_to_ftop(api, partner_id, shift_type, res):
if shift_type == 2:
c = [['id', '=', partner_id]]
f = ['shift_type']
old_shift_type = api.search_read('res.partner', c, f)[0]['shift_type']
if old_shift_type == 'standard':
members_data = []
members_data.append({
'member_id': partner_id,
'member_shift_type': old_shift_type,
'target_makeups_nb': 0,
'description': 'reset automatique du compteur rattrapages suite changement créneau standard vers non standard'
})
res["res"] = []
update_members_makeups_core(members_data, res)
if res["res"][0]["update"]:
res["makeups_to_do"] = 0
# --- Gestion des binômes # --- Gestion des binômes
def get_member_info(request, id): def get_member_info(request, id):
......
...@@ -92,6 +92,9 @@ function shift_subscrition(shift_type, shift_template_id = null, shift_template_ ...@@ -92,6 +92,9 @@ function shift_subscrition(shift_type, shift_template_id = null, shift_template_
stdata.name stdata.name
]; ];
selected_member.cooperative_state = data.cooperative_state; selected_member.cooperative_state = data.cooperative_state;
if(data.makeups_to_do !== undefined) {
selected_member.makeups_to_do = data.makeups_to_do;
}
display_member_info(); display_member_info();
$("#shifts_calendar_area").hide(); $("#shifts_calendar_area").hide();
......
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