Commit d985e9e4 by Yvon Kerdoncuff

#7332 : rework makeups management in binom creation code + some makeups refactoring

parent 97e7bc61
......@@ -1065,20 +1065,11 @@ class CagetteMember(models.Model):
return res
def get_member_selected_makeups(self):
res = {}
c = [["partner_id", "=", self.id], ["is_makeup", "=", True], ["state", "=", "open"]]
f=['id']
res = self.o_api.search_read("shift.registration", c, f)
return res
def get_makeup_registrations_ids_on_shift_template(self, shift_template_id):
""" Get the makeup registrations that are on a shift template """
makeup_reg_ids = []
c = [["partner_id", "=", self.id], ["is_makeup", "=", True], ["state", "=", "open"]]
f = ['id', 'shift_id']
res_shift_ids = self.o_api.search_read("shift.registration", c, f)
res_shift_ids = shifts.fonctions.get_scheduled_makeups(self.api, partner_ids=[self.id])
for shift_reg in res_shift_ids:
c = [["id", "=", int(shift_reg['shift_id'][0])]]
f = ['shift_template_id']
......@@ -1369,6 +1360,7 @@ class CagetteMembers(models.Model):
@staticmethod
def get_makeups_members(ids=[]):
# 0 : fetch members with makeups_to_do > 0
api = OdooAPI()
cond = [['makeups_to_do','>', 0]]
......@@ -1405,8 +1397,7 @@ class CagetteMembers(models.Model):
def add_makeups_to_come_to_member_data(api, res):
if res:
for idx, partner in enumerate(res):
[shift_data, is_ftop] = shifts.fonctions.get_shift_partner(api, int(partner['id']))
res[idx]['makeups_to_come'] = sum(1 for value in shift_data if value['is_makeup'])
res[idx]['makeups_to_come'] = len(shifts.fonctions.get_scheduled_makeups(api, partner_ids=[int(partner['id'])]))
@staticmethod
def get_attached_members():
......
......@@ -9,9 +9,7 @@ def dateIsoUTC(myDate):
def get_partners_with_makeups_to_come(api):
"""Returns a dictionary with : keys = the partners ids having at least one makeup to come ; values = #makeups_to_come"""
fields = ['partner_id']
cond = [['state', '=', 'open'], ['date_begin', '>', datetime.datetime.now().isoformat()], ['is_makeup', '=', True]]
shift_data = api.search_read('shift.registration', cond, fields)
shift_data = get_scheduled_makeups(api)
count_dic = {}
for value in shift_data:
if value['partner_id'][0] in count_dic:
......@@ -47,4 +45,13 @@ 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
return api.search_read('res.partner', cond, fields)
def get_scheduled_makeups(api, partner_ids=None):
c = [["is_makeup", "=", True], ["state", "=", "open"], ['date_begin', '>', datetime.datetime.now().isoformat()]]
if partner_ids:
c.append(["partner_id", "in", partner_ids])
f = ['id', 'shift_id', 'partner_id']
res_shift_ids = api.search_read("shift.registration", c, f)
return res_shift_ids
......@@ -297,7 +297,13 @@ class CagetteShift(models.Model):
def set_shift(self, data):
"""Shift registration.
Decrement makeups_to_do if shift has to be a makeup.
Handle partner already registered on this shift case."""
Handle partner already registered on this shift case.
data should coutain :
- idPartner
- idShift
- shift_type
- is_makeup
"""
st_r_id = False
try:
shift_type = "standard"
......
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