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,51 +383,56 @@ def update_members_makeups(request):
members_data = json.loads(request.body.decode())
res["res"] = []
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
update_members_makeups_core(members_data, res)
response = JsonResponse(res)
else:
res["message"] = "Unauthorized"
response = JsonResponse(res, status=403)
return response
res["res"].append(cm.update_member_makeups(member_data))
# Update member standard points, for standard members only
if member_data["member_shift_type"] == "standard":
# Set points to minus the number of makeups to do (limited to -2)
target_points = - int(member_data["target_makeups_nb"])
if (target_points < -2) :
target_points = -2
def update_members_makeups_core(members_data, res):
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
member_points = cm.get_member_points("standard")
points_diff = abs(member_points - target_points)
res["res"].append(cm.update_member_makeups(member_data))
# Don't update if no change
if points_diff == 0:
continue
# Update member standard points, for standard members only
if member_data["member_shift_type"] == "standard":
# Set points to minus the number of makeups to do (limited to -2)
target_points = - int(member_data["target_makeups_nb"])
if (target_points < -2):
target_points = -2
if member_points > target_points:
points_update = - points_diff
else:
points_update = points_diff
member_points = cm.get_member_points("standard")
points_diff = abs(member_points - target_points)
data = {
'name': "Admin BDM - " + member_data["description"],
'shift_id': False,
'type': member_data["member_shift_type"],
'partner_id': int(member_data["member_id"]),
'point_qty': points_update
}
# Don't update if no change
if points_diff == 0:
continue
if member_points > target_points:
points_update = - points_diff
else:
points_update = points_diff
data = {
'name': "Admin BDM - " + member_data["description"],
'shift_id': False,
'type': member_data["member_shift_type"],
'partner_id': int(member_data["member_id"]),
'point_qty': points_update
}
cm.update_member_points(data)
# Better to call run_process_target_status now, otherwise partner remains
# in alert until routine is called (every 5 minutes). It is a bit weird for users and
# allocation of rattrapages before the routine is executed will not trigger change to delay state !
# (the parner would have to go back to espace membre and click on "j'affecte mes rattrapage"
# even though it shows 'J'ai 0 rattrapages à effecter' for the delay state change to be eventually triggered)
api = OdooAPI()
api.execute('res.partner', 'run_process_target_status', [])
cm.update_member_points(data)
# Better to call run_process_target_status now, otherwise partner remains
# in alert until routine is called (every 5 minutes). It is a bit weird for users and
# allocation of rattrapages before the routine is executed will not trigger change to delay state !
# (the parner would have to go back to espace membre and click on "j'affecte mes rattrapage"
# even though it shows 'J'ai 0 rattrapages à effecter' for the delay state change to be eventually triggered)
api = OdooAPI()
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):
""" From BDM admin, close existing extension if exists & recreate for 6 months """
......@@ -603,6 +608,7 @@ def shift_subscription(request):
shift_template_id = CagetteServices.get_exemptions_shift_id()
m = CagetteMember(partner_id)
api = OdooAPI()
unsubscribe_first = data["unsubscribe_first"]
if unsubscribe_first is True:
......@@ -619,11 +625,13 @@ def shift_subscription(request):
)
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)
# Return necessary data
if reg_id is not None:
api = OdooAPI()
c = [['id', '=', shift_template_id]]
f = ['id', 'name']
res["shift_template"] = api.search_read('shift.template', c, f)[0]
......@@ -640,6 +648,25 @@ def shift_subscription(request):
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
def get_member_info(request, id):
......
......@@ -92,6 +92,9 @@ function shift_subscrition(shift_type, shift_template_id = null, shift_template_
stdata.name
];
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();
$("#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