forked from DGNum/gestioCOF
PEP8 for perform_operation
This commit is contained in:
parent
a107fa0309
commit
de724a2c0d
1 changed files with 54 additions and 39 deletions
|
@ -927,7 +927,8 @@ def kpsul_update_addcost(request):
|
|||
if not request.user.has_perms(required_perms):
|
||||
data = {
|
||||
'errors': {
|
||||
'missing_perms': get_missing_perms(required_perms, request.user)
|
||||
'missing_perms': get_missing_perms(required_perms,
|
||||
request.user)
|
||||
}
|
||||
}
|
||||
return JsonResponse(data, status=403)
|
||||
|
@ -935,7 +936,8 @@ def kpsul_update_addcost(request):
|
|||
trigramme = addcost_form.cleaned_data['trigramme']
|
||||
account = trigramme and Account.objects.get(trigramme=trigramme) or None
|
||||
Settings.objects.filter(name='ADDCOST_FOR').update(value_account=account)
|
||||
Settings.objects.filter(name='ADDCOST_AMOUNT').update(value_decimal=addcost_form.cleaned_data['amount'])
|
||||
(Settings.objects.filter(name='ADDCOST_AMOUNT')
|
||||
.update(value_decimal=addcost_form.cleaned_data['amount']))
|
||||
cache.delete('ADDCOST_FOR')
|
||||
cache.delete('ADDCOST_AMOUNT')
|
||||
data = {
|
||||
|
@ -947,15 +949,18 @@ def kpsul_update_addcost(request):
|
|||
consumers.KPsul.group_send('kfet.kpsul', data)
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
def get_missing_perms(required_perms, user):
|
||||
missing_perms_codenames = [(perm.split('.'))[1]
|
||||
for perm in required_perms if not user.has_perm(perm)]
|
||||
for perm in required_perms
|
||||
if not user.has_perm(perm)]
|
||||
missing_perms = list(
|
||||
Permission.objects
|
||||
.filter(codename__in=missing_perms_codenames)
|
||||
.values_list('name', flat=True))
|
||||
return missing_perms
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def kpsul_perform_operations(request):
|
||||
# Initializing response data
|
||||
|
@ -996,13 +1001,15 @@ def kpsul_perform_operations(request):
|
|||
and addcost_for != operationgroup.on_acc)
|
||||
need_comment = operationgroup.on_acc.need_comment
|
||||
|
||||
# Filling data of each operations + operationgroup + calculating other stuffs
|
||||
# Filling data of each operations
|
||||
# + operationgroup + calculating other stuffs
|
||||
for operation in operations:
|
||||
if operation.type == Operation.PURCHASE:
|
||||
operation.amount = - operation.article.price * operation.article_nb
|
||||
if is_addcost & operation.article.category.has_addcost:
|
||||
operation.addcost_for = addcost_for
|
||||
operation.addcost_amount = addcost_amount * operation.article_nb
|
||||
operation.addcost_amount = addcost_amount \
|
||||
* operation.article_nb
|
||||
operation.amount -= operation.addcost_amount
|
||||
to_addcost_for_balance += operation.addcost_amount
|
||||
if operationgroup.on_acc.is_cash:
|
||||
|
@ -1012,12 +1019,14 @@ def kpsul_perform_operations(request):
|
|||
operation.is_checkout = False
|
||||
if operationgroup.on_acc.is_cof:
|
||||
if is_addcost & operation.article.category.has_addcost:
|
||||
operation.addcost_amount = operation.addcost_amount / cof_grant_divisor
|
||||
operation.addcost_amount = operation.addcost_amount \
|
||||
/ cof_grant_divisor
|
||||
operation.amount = operation.amount / cof_grant_divisor
|
||||
to_articles_stocks[operation.article] -= operation.article_nb
|
||||
else:
|
||||
if operationgroup.on_acc.is_cash:
|
||||
data['errors']['account'] = 'Charge et retrait impossible sur LIQ'
|
||||
data['errors']['account'] = ("Charge et retrait"
|
||||
" impossible sur LIQ")
|
||||
to_checkout_balance += operation.amount
|
||||
operationgroup.amount += operation.amount
|
||||
if operation.type == Operation.DEPOSIT:
|
||||
|
@ -1029,8 +1038,10 @@ def kpsul_perform_operations(request):
|
|||
if operationgroup.on_acc.is_cof:
|
||||
to_addcost_for_balance = to_addcost_for_balance / cof_grant_divisor
|
||||
|
||||
(perms, stop) = operationgroup.on_acc.perms_to_perform_operation(
|
||||
(perms, stop) = (operationgroup.on_acc
|
||||
.perms_to_perform_operation(
|
||||
amount=operationgroup.amount)
|
||||
)
|
||||
required_perms |= perms
|
||||
|
||||
if need_comment:
|
||||
|
@ -1116,11 +1127,14 @@ def kpsul_perform_operations(request):
|
|||
}]
|
||||
for operation in operations:
|
||||
ope_data = {
|
||||
'id': operation.pk, 'type': operation.type, 'amount': operation.amount,
|
||||
'id': operation.pk, 'type': operation.type,
|
||||
'amount': operation.amount,
|
||||
'addcost_amount': operation.addcost_amount,
|
||||
'addcost_for__trigramme': is_addcost and addcost_for.trigramme or None,
|
||||
'addcost_for__trigramme': is_addcost
|
||||
and addcost_for.trigramme or None,
|
||||
'is_checkout': operation.is_checkout,
|
||||
'article__name': operation.article and operation.article.name or None,
|
||||
'article__name': operation.article
|
||||
and operation.article.name or None,
|
||||
'article_nb': operation.article_nb,
|
||||
'group_id': operationgroup.pk,
|
||||
'canceled_by__trigramme': None, 'canceled_at': None,
|
||||
|
@ -1144,6 +1158,7 @@ def kpsul_perform_operations(request):
|
|||
consumers.KPsul.group_send('kfet.kpsul', websocket_data)
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
@teamkfet_required
|
||||
def kpsul_cancel_operations(request):
|
||||
# Pour la réponse
|
||||
|
|
Loading…
Reference in a new issue