Commit b564b158 by Yvon

efficiently fetch makeups to come data in order to (1) display members with only…

efficiently fetch makeups to come data in order to (1) display members with only makeups to come and no makeups to do and (2) speed up display of makeups admin
parent 55ca2075
Pipeline #3186 failed with stage
in 1 minute 5 seconds
......@@ -1284,7 +1284,29 @@ class CagetteMembers(models.Model):
fields = ['id', 'name', 'display_std_points', 'display_ftop_points', 'shift_type', 'makeups_to_do', 'date_delay_stop']
res = api.search_read('res.partner', cond, fields)
CagetteMembers.add_makeups_to_come_to_member_data(res)
# There are two things we need to do now :
# 1 : fetching members with no makeups to do but with some makeups to come
# 2 : providing makeups to come to all members
cs = CagetteShift()
makeups_to_come_per_partner = cs.get_count_of_makeups_to_come_per_partner()
# 1 : fetching members with no makeups to do but with some makeups to come
cond = [['makeups_to_do', '=', 0], ['id', 'in', list(makeups_to_come_per_partner.keys())]]
if len(ids) > 0:
cond.append(['id','in', ids])
res = res + api.search_read('res.partner', cond, fields)
# 2 : providing makeups to come to all members
for idx, partner in enumerate(res):
if partner['id'] in makeups_to_come_per_partner:
res[idx]['makeups_to_come'] = makeups_to_come_per_partner[partner['id']]
else:
res[idx]['makeups_to_come'] = 0
return res
@staticmethod
......
......@@ -41,10 +41,10 @@ function display_makeups_members() {
$('#makeups_members_table').empty();
}
// Remove members with 0 makeups to do
// Remove members with 0 makeups to do and 0 makeups to come
ids_to_remove = [];
for (let member_item of makeups_members) {
if (member_item.makeups_to_do === 0) {
if (member_item.makeups_to_do === 0 && member_item.makeups_to_come === 0) {
ids_to_remove.push(member_item.id);
}
}
......
......@@ -185,6 +185,18 @@ class CagetteShift(models.Model):
shiftData = self.o_api.search_read('shift.registration', cond, fields, order ="date_begin ASC")
return shiftData
def get_count_of_makeups_to_come_per_partner(self):
fields = ['partner_id']
cond = [['state', '=', 'open'], ['date_begin', '>', datetime.datetime.now().isoformat()], ['is_makeup', '=', True]]
shift_data = self.o_api.search_read('shift.registration', cond, fields)
count_dic = {}
for value in shift_data:
if value['partner_id'][0] in count_dic:
count_dic[value['partner_id'][0]] = count_dic[value['partner_id'][0]] + 1
else:
count_dic[value['partner_id'][0]] = 1
return count_dic
def shift_is_makeup(self, id):
"""vérifie si une shift est un rattrapage"""
fields = ["is_makeup", "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