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):
|
if not request.user.has_perms(required_perms):
|
||||||
data = {
|
data = {
|
||||||
'errors': {
|
'errors': {
|
||||||
'missing_perms': get_missing_perms(required_perms, request.user)
|
'missing_perms': get_missing_perms(required_perms,
|
||||||
|
request.user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return JsonResponse(data, status=403)
|
return JsonResponse(data, status=403)
|
||||||
|
@ -935,7 +936,8 @@ def kpsul_update_addcost(request):
|
||||||
trigramme = addcost_form.cleaned_data['trigramme']
|
trigramme = addcost_form.cleaned_data['trigramme']
|
||||||
account = trigramme and Account.objects.get(trigramme=trigramme) or None
|
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_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_FOR')
|
||||||
cache.delete('ADDCOST_AMOUNT')
|
cache.delete('ADDCOST_AMOUNT')
|
||||||
data = {
|
data = {
|
||||||
|
@ -947,15 +949,18 @@ def kpsul_update_addcost(request):
|
||||||
consumers.KPsul.group_send('kfet.kpsul', data)
|
consumers.KPsul.group_send('kfet.kpsul', data)
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
def get_missing_perms(required_perms, user):
|
def get_missing_perms(required_perms, user):
|
||||||
missing_perms_codenames = [(perm.split('.'))[1]
|
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(
|
missing_perms = list(
|
||||||
Permission.objects
|
Permission.objects
|
||||||
.filter(codename__in=missing_perms_codenames)
|
.filter(codename__in=missing_perms_codenames)
|
||||||
.values_list('name', flat=True))
|
.values_list('name', flat=True))
|
||||||
return missing_perms
|
return missing_perms
|
||||||
|
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def kpsul_perform_operations(request):
|
def kpsul_perform_operations(request):
|
||||||
# Initializing response data
|
# Initializing response data
|
||||||
|
@ -996,13 +1001,15 @@ def kpsul_perform_operations(request):
|
||||||
and addcost_for != operationgroup.on_acc)
|
and addcost_for != operationgroup.on_acc)
|
||||||
need_comment = operationgroup.on_acc.need_comment
|
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:
|
for operation in operations:
|
||||||
if operation.type == Operation.PURCHASE:
|
if operation.type == Operation.PURCHASE:
|
||||||
operation.amount = - operation.article.price * operation.article_nb
|
operation.amount = - operation.article.price * operation.article_nb
|
||||||
if is_addcost & operation.article.category.has_addcost:
|
if is_addcost & operation.article.category.has_addcost:
|
||||||
operation.addcost_for = addcost_for
|
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
|
operation.amount -= operation.addcost_amount
|
||||||
to_addcost_for_balance += operation.addcost_amount
|
to_addcost_for_balance += operation.addcost_amount
|
||||||
if operationgroup.on_acc.is_cash:
|
if operationgroup.on_acc.is_cash:
|
||||||
|
@ -1012,12 +1019,14 @@ def kpsul_perform_operations(request):
|
||||||
operation.is_checkout = False
|
operation.is_checkout = False
|
||||||
if operationgroup.on_acc.is_cof:
|
if operationgroup.on_acc.is_cof:
|
||||||
if is_addcost & operation.article.category.has_addcost:
|
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
|
operation.amount = operation.amount / cof_grant_divisor
|
||||||
to_articles_stocks[operation.article] -= operation.article_nb
|
to_articles_stocks[operation.article] -= operation.article_nb
|
||||||
else:
|
else:
|
||||||
if operationgroup.on_acc.is_cash:
|
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
|
to_checkout_balance += operation.amount
|
||||||
operationgroup.amount += operation.amount
|
operationgroup.amount += operation.amount
|
||||||
if operation.type == Operation.DEPOSIT:
|
if operation.type == Operation.DEPOSIT:
|
||||||
|
@ -1029,8 +1038,10 @@ def kpsul_perform_operations(request):
|
||||||
if operationgroup.on_acc.is_cof:
|
if operationgroup.on_acc.is_cof:
|
||||||
to_addcost_for_balance = to_addcost_for_balance / cof_grant_divisor
|
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)
|
amount=operationgroup.amount)
|
||||||
|
)
|
||||||
required_perms |= perms
|
required_perms |= perms
|
||||||
|
|
||||||
if need_comment:
|
if need_comment:
|
||||||
|
@ -1116,11 +1127,14 @@ def kpsul_perform_operations(request):
|
||||||
}]
|
}]
|
||||||
for operation in operations:
|
for operation in operations:
|
||||||
ope_data = {
|
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_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,
|
'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,
|
'article_nb': operation.article_nb,
|
||||||
'group_id': operationgroup.pk,
|
'group_id': operationgroup.pk,
|
||||||
'canceled_by__trigramme': None, 'canceled_at': None,
|
'canceled_by__trigramme': None, 'canceled_at': None,
|
||||||
|
@ -1144,6 +1158,7 @@ def kpsul_perform_operations(request):
|
||||||
consumers.KPsul.group_send('kfet.kpsul', websocket_data)
|
consumers.KPsul.group_send('kfet.kpsul', websocket_data)
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def kpsul_cancel_operations(request):
|
def kpsul_cancel_operations(request):
|
||||||
# Pour la réponse
|
# Pour la réponse
|
||||||
|
|
Loading…
Reference in a new issue