Adapt history_json return value to ModelForest standards

This commit is contained in:
Ludovic Stephan 2017-03-17 15:59:21 -03:00
parent 53f89f53e0
commit df0ea96b41

View file

@ -1397,77 +1397,112 @@ def history_json(request):
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
# Construction de la réponse
ope_list = []
opegroup_list = []
for opegroup in opegroups:
opegroup_dict = {
'id': 'ope'+str(opegroup.id),
'type': 'opegroup',
'content': {
'id': opegroup.id,
'amount': opegroup.amount,
'at': opegroup.at,
'is_cof': opegroup.is_cof,
'comment': opegroup.comment,
'trigramme':
opegroup.on_acc and opegroup.on_acc.trigramme or None,
'day': {'id': opegroup.at.strftime('%Y%m%d'),
'date': opegroup.at},
},
'parent': {
'type': 'day',
'content': {
'id': opegroup.at.strftime('%Y%m%d'),
'date': opegroup.at
},
'child_sort': 'opegroup',
},
'children': [],
}
if request.user.has_perm('kfet.is_team'):
opegroup_dict['valid_by'] = (
opegroup_dict['content']['valid_by'] = (
opegroup.valid_by and opegroup.valid_by.trigramme or None)
for ope in opegroup.opes.all():
ope_dict = {
'id': 'ope'+str(ope.id),
'type': ope.type,
'content': {
'id': ope.id,
'amount': ope.amount,
'article_nb': ope.article_nb,
'is_checkout': ope.is_checkout,
'addcost_amount': ope.addcost_amount,
'canceled_at': ope.canceled_at,
'article_name':
ope.article and ope.article.name or None,
'addcost_for':
ope.addcost_for and ope.addcost_for.trigramme or None,
'opegroup': opegroup_dict,
'is_cof': opegroup.is_cof,
'trigramme':
opegroup.on_acc and opegroup.on_acc.trigramme or None,
},
}
if request.user.has_perm('kfet.is_team'):
ope_dict['canceled_by'] = (
ope_dict['content']['canceled_by'] = (
ope.canceled_by and ope.canceled_by.trigramme or None)
ope_list.append(ope_dict)
if ope.type == Operation.PURCHASE:
ope_dict['type'] = 'purchase'
ope_dict['content'].update({
'article_name': ope.article.name,
'article_nb': ope.article_nb,
'addcost_amount': ope.addcost_amount,
'addcost_for':
ope.addcost_for and ope.addcost_for.trigramme or None,
})
else:
ope_dict['type'] = 'specialope'
ope_dict['content'].update({
'type': ope.type,
'is_checkout': ope.is_checkout,
})
opegroup_dict['children'].append(ope_dict)
opegroup_list.append(opegroup_dict)
for transfergroup in transfergroups:
if transfergroup.filtered_transfers:
transfergroup_dict = {
'id': 'tr'+str(transfergroup.id),
'type': 'transfergroup',
'content': {
'id': transfergroup.id,
'at': transfergroup.at,
'comment': transfergroup.comment,
'day': {'id': transfergroup.at.strftime('%Y%m%d'),
'date': transfergroup.at},
},
'parent': {
'type': 'day',
'content': {
'id': transfergroup.at.strftime('%Y%m%d'),
'date': transfergroup.at
},
},
'children': [],
}
if request.user.has_perm('kfet.is_team'):
transfergroup_dict['valid_by'] = (
transfergroup_dict['content']['valid_by'] = (
transfergroup.valid_by and
transfergroup.valid_by.trigramme or
None)
for transfer in transfergroup.filtered_transfers:
transfer_dict = {
'id': 'tr'+str(transfer.id),
'type': 'transfer',
'content': {
'id': transfer.id,
'amount': transfer.amount,
'canceled_at': transfer.canceled_at,
'from_acc': transfer.from_acc.trigramme,
'to_acc': transfer.to_acc.trigramme,
'opegroup': transfergroup_dict,
},
}
if request.user.has_perm('kfet.is_team'):
transfer_dict['canceled_by'] = (
transfer_dict['content']['canceled_by'] = (
transfer.canceled_by and
transfer.canceled_by.trigramme or
None)
ope_list.append(transfer_dict)
transfergroup_dict['children'].append(transfer_dict)
opegroup_list.append(transfergroup_dict)
return JsonResponse(ope_list, safe=False)
return JsonResponse(opegroup_list, safe=False)
@teamkfet_required
def kpsul_articles_data(request):