fetch transfers as well

This commit is contained in:
Ludovic Stephan 2016-12-02 00:16:40 -02:00
parent 971848cb1b
commit 5a354c61a0

View file

@ -1331,10 +1331,10 @@ def history_json(request):
opegroups_list = []
for opegroup in opegroups:
opegroup_dict = {
'type' : 'opegroup',
'id' : opegroup.id,
'amount' : opegroup.amount,
'at' : opegroup.at,
'checkout_id': opegroup.checkout_id,
'is_cof' : opegroup.is_cof,
'comment' : opegroup.comment,
'opes' : [],
@ -1363,7 +1363,41 @@ def history_json(request):
ope.canceled_by and ope.canceled_by.trigramme or None)
opegroup_dict['opes'].append(ope_dict)
opegroups_list.append(opegroup_dict)
return JsonResponse({ 'opegroups': opegroups_list })
for transfergroup in transfergroups:
if transfergroup.filtered_transfers:
transfergroup_dict = {
'type': 'transfergroup',
'id': transfergroup.id,
'at': transfergroup.at,
'comment': transfergroup.comment,
'opes': [],
}
if request.user.has_perm('kfet.is_team'):
transfergroup_dict['valid_by__trigramme'] = (
transfergroup.valid_by
and transfergroup.valid_by.trigramme
or None)
for transfer in transfergroup.filtered_transfers:
transfer_dict = {
'id': transfer.id,
'amount': transfer.amount,
'canceled_at': transfer.canceled_at,
'from_acc': transfer.from_acc.trigramme,
'to_acc': transfer.to_acc.trigramme,
}
if request.user.has_perm('kfet.is_team'):
transfer_dict['canceled_by__trigramme'] = (
transfer.canceled_by
and transfer.canceled_by.trigramme
or None)
transfergroup_dict['opes'].append(transfer_dict)
opegroups_list.append(transfergroup_dict)
opegroups_list.sort(key=lambda group: group['at'])
return JsonResponse({'opegroups': opegroups_list})
@teamkfet_required
def kpsul_articles_data(request):