WIP: Aureplop/kpsul js refactor #501

Draft
delobell wants to merge 215 commits from aureplop/kpsul_js_refactor into master
Showing only changes of commit df0ea96b41 - Show all commits

View file

@ -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',
'amount': opegroup.amount, 'content': {
'at': opegroup.at, 'id': opegroup.id,
'is_cof': opegroup.is_cof, 'amount': opegroup.amount,
'comment': opegroup.comment, 'at': opegroup.at,
'trigramme': 'is_cof': opegroup.is_cof,
opegroup.on_acc and opegroup.on_acc.trigramme or None, 'comment': opegroup.comment,
'day': {'id': opegroup.at.strftime('%Y%m%d'), 'trigramme':
'date': opegroup.at}, opegroup.on_acc and opegroup.on_acc.trigramme or None,
},
'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, 'canceled_at': ope.canceled_at,
'is_checkout': ope.is_checkout, 'is_cof': opegroup.is_cof,
'addcost_amount': ope.addcost_amount, 'trigramme':
'canceled_at': ope.canceled_at, opegroup.on_acc and opegroup.on_acc.trigramme or None,
'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,
} }
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',
'at': transfergroup.at, 'content': {
'comment': transfergroup.comment, 'id': transfergroup.id,
'day': {'id': transfergroup.at.strftime('%Y%m%d'), 'at': transfergroup.at,
'date': transfergroup.at}, 'comment': transfergroup.comment,
},
'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',
'amount': transfer.amount, 'content': {
'canceled_at': transfer.canceled_at, 'id': transfer.id,
'from_acc': transfer.from_acc.trigramme, 'amount': transfer.amount,
'to_acc': transfer.to_acc.trigramme, 'canceled_at': transfer.canceled_at,
'opegroup': transfergroup_dict, 'from_acc': transfer.from_acc.trigramme,
'to_acc': transfer.to_acc.trigramme,
},
} }
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):