Commit 02ee410b by Yvon Kerdoncuff

#7425 : never increment makeups from third-party as this is handled by odoo

parent 813db0c0
......@@ -394,6 +394,22 @@ def update_members_makeups(request):
if is_connected_user is True:
members_data = json.loads(request.body.decode())
# Make sure update would not unsubscribe member
cs = CagetteShift()
unsubscription_limit = api.get_system_param('lacagette_membership.points_limit_to_get_unsubscribed')
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
target_makeups_nb = int(member_data["target_makeups_nb"])
if target_makeups_nb < 0:
# 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)
members_data[member_data["member_id"]]["points_diff"] = - makeup_change_count
res["res"] = []
update_members_makeups_core(members_data, res)
response = JsonResponse(res)
......@@ -407,50 +423,21 @@ def update_members_makeups_core(members_data, res):
for member_data in members_data:
cm = CagetteMember(int(member_data["member_id"]))
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 + the makeups to come (limited to -2)
cs = CagetteShift()
[shift_data, is_ftop] = cs.get_shift_partner(int(member_data["member_id"]))
target_points = - int(member_data["target_makeups_nb"]) - sum(1 for value in shift_data if value['is_makeup'])
if (target_points < -2):
target_points = -2
member_points = cm.get_member_points("standard")
points_diff = abs(member_points - target_points)
# Don't update if no change
if points_diff == 0:
res["res"][-1]['standard_points'] = member_points
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
}
# If points are added, we need to manage makeups count change here,
# otherwise this is handled automatically by odoo when points are changed
if member_data["points_diff"] > 0:
res["res"].append(cm.update_member_makeups(member_data))
cm.update_member_points(data)
#There are some odoo process happening here that could change the actual number of points
#so we want to fetch it again to send it back
res["res"][-1]['standard_points'] = cm.get_member_points("standard")
# 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', [])
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': member_data['points_diff']
}
cm.update_member_points(data)
res["res"][-1]['standard_points'] = cm.get_member_points("standard")
def regenerate_member_delay(request):
""" From BDM admin, close existing extension if exists & recreate for 6 months """
......@@ -554,23 +541,15 @@ def delete_shift_template_registration(request):
try:
data = json.loads(request.body.decode())
partner_id = int(data["partner_id"])
shift_template_id = int(data["shift_template_id"])
makeups_to_do = int(data["makeups_to_do"])
permanent_unsuscribe = data["permanent_unsuscribe"]
cm = CagetteMember(partner_id)
# Get partner nb of future makeup shifts
partner_makeups = cm.get_member_selected_makeups()
target_makeup = makeups_to_do + len(partner_makeups)
if target_makeup > 2:
target_makeup = 2
# Update partner makeups to do
res["update_makeups"] = cm.update_member_makeups({'target_makeups_nb': target_makeup})
# Knowing that the total number of makeups will always be 2 or less,
# old code here would only increment the number of makeups...
# which is not needed as makeup increment is now handled
# by odoo.
# Delete all shift registrations & shift template registration
cm = CagetteMember(partner_id)
res["unsubscribe_member"] = cm.unsubscribe_member()
if permanent_unsuscribe is True:
......@@ -676,12 +655,15 @@ def shift_subscription(request):
def lower_makeup_count_to_zero_if_moving_from_std_to_ftop(partner_id, res):
cs = CagetteShift()
cm = CagetteMember(partner_id)
members_data = []
members_data.append({
'member_id': partner_id,
'member_shift_type': 'standard',
'target_makeups_nb': 0,
'description': 'reset automatique du compteur rattrapages suite changement créneau standard vers non standard'
'description': 'reset automatique du compteur rattrapages suite changement créneau standard vers non standard',
'points_diff': cs.get_member_makeups_to_do(cm.id)
})
res["res"] = []
update_members_makeups_core(members_data, res)
......
......@@ -1054,14 +1054,8 @@ class CagetteMember(models.Model):
def update_member_makeups(self, member_data):
api = OdooAPI()
res = {}
# 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
makeups_to_do = max(0,int(member_data["target_makeups_nb"]))
f = { 'makeups_to_do': makeups_to_do }
makeups_to_do = int(member_data["target_makeups_nb"])
f = {'makeups_to_do': makeups_to_do}
res_item = api.update('res.partner', [self.id], f)
res = {
'mid': self.id,
......
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