Merge branch 'dev' into 'master'

Dev

See merge request !246
master
Andrey 8 years ago
commit eebc1397b8
  1. 54
      finance/views.py

@ -42,24 +42,46 @@ class BillListView(APIView):
or request.user.is_superuser): or request.user.is_superuser):
bill = request.JSON.get('bill') bill = request.JSON.get('bill')
children = request.JSON.get('children', []) children = request.JSON.get('children', [])
bill_kwarg = dict()
if bill: if bill:
bill_kwarg['user'] = get_user_model().objects.get(email=bill['user']) user = get_user_model().objects.get(email=bill['user'])
bill_kwarg['opener'] = get_user_model().objects.get(email=bill['opener']) opener = get_user_model().objects.get(email=bill['opener'])
bill_kwarg['description'] = bill['description'] description = bill['description']
bill_kwarg['comment'] = bill['comment'] comment = bill['comment']
bill_kwarg['course_token'] = bill['course_token'] course_token = bill['course_token']
bill_obj, is_create = Bill.objects.update_or_create(**bill_kwarg) try:
invoices = bill_obj.invoice_set.all() bill_obj = Bill.objects.get(user=user, course_token=course_token)
except Bill.DoesNotExist:
bill_obj = Bill.objects.create(user=user, course_token=course_token)
bill_obj.opener = opener
bill_obj.description = description
bill_obj.comment = comment
bill_obj.save()
for i in children: for i in children:
i['method'] = get_real_name(elem=i['method'], array=Invoice.BILL_METHOD) status = get_real_name(elem=i['status'], array=Invoice.BILL_STATUSES)
i['status'] = get_real_name(elem=i['status'], array=Invoice.BILL_STATUSES) try:
i['bill'] = bill_obj invoice_id = i['id']
i['yandex_pay'] = None except KeyError:
invoice, _is_create = Invoice.objects.update_or_create(**i) invoice_id = None
try:
if not invoice_id is None:
invoice = Invoice.objects.get(id=i['id'])
if invoice.status == "P" or invoice.status == status:
continue
else:
raise Invoice.DoesNotExist
except Invoice.DoesNotExist:
i['method'] = get_real_name(elem=i['method'], array=Invoice.BILL_METHOD)
i['status'] = status
i['bill'] = bill_obj
i['yandex_pay'] = None
invoice = Invoice.objects.create(**i)
if i['method'] == 'Y' and invoice.yandex_pay is None: if i['method'] == 'Y' and invoice.yandex_pay is None:
yandex_pay = Payment.objects.create( yandex_pay = Payment.objects.create(
order_amount=i['price'], order_amount=i['price'],
@ -86,10 +108,6 @@ class BillListView(APIView):
msg.send() msg.send()
invoices = [j for j in invoices if not j.id == invoice.id]
[i.delete() for i in invoices]
res = { res = {
"bill": BillSerializer(bill_obj).data, "bill": BillSerializer(bill_obj).data,
"children": [InvoiceSerializer(i).data for i in bill_obj.invoice_set.all()], "children": [InvoiceSerializer(i).data for i in bill_obj.invoice_set.all()],

Loading…
Cancel
Save