8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-25 04:43:10 +00:00

[Printer] Cancel jobs that couldn't be paid

This commit is contained in:
Maxime Bombar 2018-10-23 20:10:21 +02:00 committed by root
parent 505c5e13e4
commit b1a8f697f5

View file

@ -38,6 +38,8 @@ from cotisations.models import(
from cotisations.utils import find_payment_method from cotisations.utils import find_payment_method
from cotisations.payment_methods.balance.models import BalancePayment
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
# raise ValidationError("'%(path)s'", code='path', params = {'path': job.printAs}) # raise ValidationError("'%(path)s'", code='path', params = {'path': job.printAs})
@ -170,14 +172,13 @@ def payment(request):
users = {} users = {}
for job in jobs: for job in jobs:
try: try:
users[job.printAs]+=job.price users[job.printAs][0]+=job.price
job.paid = True users[job.printAs][1].append(job.id)
job.save()
except KeyError: except KeyError:
users[job.printAs]=job.price users[job.printAs]=[job.price, [job.id]]
job.paid = True
job.save()
balancePayment = BalancePayment.objects.get()
minimum_balance = balancePayment.minimum_balance
for user in users: for user in users:
### If payment_method balance doesn't exist, then you're not allowed to print. ### If payment_method balance doesn't exist, then you're not allowed to print.
try: try:
@ -197,10 +198,22 @@ def payment(request):
Vente.objects.create( Vente.objects.create(
facture=invoice, facture=invoice,
name='Printing (requested by %s)' % request.user, name='Printing (requested by %s)' % request.user,
prix=users[user], prix=users[user][0],
number=1, number=1,
) )
invoice.paiement.end_payment(invoice, request) invoice.paiement.end_payment(invoice, request)
### If we are here, then either we were able to pay and it's ok,
### Either we weren't able to pay and we need to cancel the jobs.
jobs = JobWithOptions.objects.filter(id__in=users[user][1])
if user.solde - users[user][0] < 0:
for job in jobs:
job.status = 'Cancelled'
job.save()
else:
for job in jobs:
job.paid = True
job.save()
return redirect(reverse( return redirect(reverse(
'printer:success', 'printer:success',
)) ))