WIP: Aureplop/kpsul js refactor #501
1 changed files with 75 additions and 40 deletions
|
@ -1397,77 +1397,112 @@ def history_json(request):
|
||||||
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
opegroups = opegroups.filter(on_acc=request.user.profile.account_kfet)
|
||||||
|
|
||||||
# Construction de la réponse
|
# Construction de la réponse
|
||||||
ope_list = []
|
opegroup_list = []
|
||||||
for opegroup in opegroups:
|
for opegroup in opegroups:
|
||||||
opegroup_dict = {
|
opegroup_dict = {
|
||||||
'id': 'ope'+str(opegroup.id),
|
|
||||||
'type': 'opegroup',
|
'type': 'opegroup',
|
||||||
|
'content': {
|
||||||
|
'id': opegroup.id,
|
||||||
'amount': opegroup.amount,
|
'amount': opegroup.amount,
|
||||||
'at': opegroup.at,
|
'at': opegroup.at,
|
||||||
'is_cof': opegroup.is_cof,
|
'is_cof': opegroup.is_cof,
|
||||||
'comment': opegroup.comment,
|
'comment': opegroup.comment,
|
||||||
'trigramme':
|
'trigramme':
|
||||||
opegroup.on_acc and opegroup.on_acc.trigramme or None,
|
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'):
|
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)
|
opegroup.valid_by and opegroup.valid_by.trigramme or None)
|
||||||
|
|
||||||
for ope in opegroup.opes.all():
|
for ope in opegroup.opes.all():
|
||||||
ope_dict = {
|
ope_dict = {
|
||||||
'id': 'ope'+str(ope.id),
|
'content': {
|
||||||
'type': ope.type,
|
'id': ope.id,
|
||||||
'amount': ope.amount,
|
'amount': ope.amount,
|
||||||
'article_nb': ope.article_nb,
|
|
||||||
'is_checkout': ope.is_checkout,
|
|
||||||
'addcost_amount': ope.addcost_amount,
|
|
||||||
'canceled_at': ope.canceled_at,
|
'canceled_at': ope.canceled_at,
|
||||||
'article_name':
|
'is_cof': opegroup.is_cof,
|
||||||
ope.article and ope.article.name or None,
|
'trigramme':
|
||||||
'addcost_for':
|
opegroup.on_acc and opegroup.on_acc.trigramme or None,
|
||||||
ope.addcost_for and ope.addcost_for.trigramme or None,
|
},
|
||||||
'opegroup': opegroup_dict,
|
|
||||||
}
|
}
|
||||||
if request.user.has_perm('kfet.is_team'):
|
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.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:
|
for transfergroup in transfergroups:
|
||||||
if transfergroup.filtered_transfers:
|
if transfergroup.filtered_transfers:
|
||||||
transfergroup_dict = {
|
transfergroup_dict = {
|
||||||
'id': 'tr'+str(transfergroup.id),
|
|
||||||
'type': 'transfergroup',
|
'type': 'transfergroup',
|
||||||
|
'content': {
|
||||||
|
'id': transfergroup.id,
|
||||||
'at': transfergroup.at,
|
'at': transfergroup.at,
|
||||||
'comment': transfergroup.comment,
|
'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'):
|
if request.user.has_perm('kfet.is_team'):
|
||||||
transfergroup_dict['valid_by'] = (
|
transfergroup_dict['content']['valid_by'] = (
|
||||||
transfergroup.valid_by and
|
transfergroup.valid_by and
|
||||||
transfergroup.valid_by.trigramme or
|
transfergroup.valid_by.trigramme or
|
||||||
None)
|
None)
|
||||||
|
|
||||||
for transfer in transfergroup.filtered_transfers:
|
for transfer in transfergroup.filtered_transfers:
|
||||||
transfer_dict = {
|
transfer_dict = {
|
||||||
'id': 'tr'+str(transfer.id),
|
|
||||||
'type': 'transfer',
|
'type': 'transfer',
|
||||||
|
'content': {
|
||||||
|
'id': transfer.id,
|
||||||
'amount': transfer.amount,
|
'amount': transfer.amount,
|
||||||
'canceled_at': transfer.canceled_at,
|
'canceled_at': transfer.canceled_at,
|
||||||
'from_acc': transfer.from_acc.trigramme,
|
'from_acc': transfer.from_acc.trigramme,
|
||||||
'to_acc': transfer.to_acc.trigramme,
|
'to_acc': transfer.to_acc.trigramme,
|
||||||
'opegroup': transfergroup_dict,
|
},
|
||||||
}
|
}
|
||||||
if request.user.has_perm('kfet.is_team'):
|
if request.user.has_perm('kfet.is_team'):
|
||||||
transfer_dict['canceled_by'] = (
|
transfer_dict['content']['canceled_by'] = (
|
||||||
transfer.canceled_by and
|
transfer.canceled_by and
|
||||||
transfer.canceled_by.trigramme or
|
transfer.canceled_by.trigramme or
|
||||||
None)
|
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
|
@teamkfet_required
|
||||||
def kpsul_articles_data(request):
|
def kpsul_articles_data(request):
|
||||||
|
|
Loading…
Reference in a new issue