finance logging

remotes/origin/yandex_rebiling
Andrey 8 years ago
parent f027b109a5
commit b815f04472
  1. 4
      finance/models.py
  2. 12
      finance/views.py

@ -21,8 +21,8 @@ class Bill(models.Model):
def get_full_price(self):
return sum([i.price for i in self.invoice_set.all() if not i.price is None])
def check_validate(self):
return self.invoice_set.filter(is_open=True).count() == 1
def check_validate(self, invoice_id):
return self.invoice_set.filter(is_open=True).exclude(id=invoice_id).count() == 1
def check_pay(self):
return self.invoice_set.filter(status="F").exists()

@ -87,7 +87,8 @@ class InvoiceDetailView(APIView):
def post(request, invoice_id):
if request.user.is_authenticated and (request.user.groups.filter(name__in=['managers','lead_managers']).exists()
or request.user.is_superuser):
bill_id = request.JSON.get('bill_id', None)
invoice_id = int(invoice_id)
bill_id = request.JSON.get('bill', None)
is_open = request.JSON.get('is_open', None)
method = request.JSON.get('method', None)
status = request.JSON.get('status', None)
@ -105,15 +106,18 @@ class InvoiceDetailView(APIView):
except Bill.DoesNotExist:
return Response('Не найден счёт с id=%s' % bill_id, status=404)
method = get_real_name(elem=method, array=Invoice.BILL_METHOD)
status = get_real_name(elem=status, array=Invoice.BILL_METHOD)
method = get_real_name(elem=method[0], array=Invoice.BILL_METHOD)
status = get_real_name(elem=status[0], array=Invoice.BILL_STATUSES)
if bill.check_validate() and is_open:
if bill.check_validate(invoice_id) and is_open:
return Response("Уже есть платёж открывающий курс", status=400)
try:
invoice = Invoice.objects.get(id=invoice_id)
except Invoice.DoesNotExist:
if not invoice_id == 0:
return Response("Платёж не найден", status=404)
if bill.check_pay():
return Response(
"Нельзя добавить новый платёж, так как один из платежей по счёту уже оплачен", status=400)

Loading…
Cancel
Save