|
|
|
|
@ -42,24 +42,40 @@ class BillListView(APIView): |
|
|
|
|
or request.user.is_superuser): |
|
|
|
|
bill = request.JSON.get('bill') |
|
|
|
|
children = request.JSON.get('children', []) |
|
|
|
|
bill_kwarg = dict() |
|
|
|
|
|
|
|
|
|
if bill: |
|
|
|
|
bill_kwarg['user'] = get_user_model().objects.get(email=bill['user']) |
|
|
|
|
bill_kwarg['opener'] = get_user_model().objects.get(email=bill['opener']) |
|
|
|
|
bill_kwarg['description'] = bill['description'] |
|
|
|
|
bill_kwarg['comment'] = bill['comment'] |
|
|
|
|
bill_kwarg['course_token'] = bill['course_token'] |
|
|
|
|
user = get_user_model().objects.get(email=bill['user']) |
|
|
|
|
opener = get_user_model().objects.get(email=bill['opener']) |
|
|
|
|
description = bill['description'] |
|
|
|
|
comment = bill['comment'] |
|
|
|
|
course_token = bill['course_token'] |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|
bill_obj, is_create = Bill.objects.update_or_create(**bill_kwarg) |
|
|
|
|
invoices = bill_obj.invoice_set.all() |
|
|
|
|
|
|
|
|
|
for i in children: |
|
|
|
|
i['method'] = get_real_name(elem=i['method'], array=Invoice.BILL_METHOD) |
|
|
|
|
i['status'] = get_real_name(elem=i['status'], array=Invoice.BILL_STATUSES) |
|
|
|
|
i['bill'] = bill_obj |
|
|
|
|
i['yandex_pay'] = None |
|
|
|
|
invoice, _is_create = Invoice.objects.update_or_create(**i) |
|
|
|
|
status = get_real_name(elem=i['status'], array=Invoice.BILL_STATUSES) |
|
|
|
|
try: |
|
|
|
|
invoice = Invoice.objects.get(id=i['id']) |
|
|
|
|
if invoice.status == "P" or invoice.status == status: |
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
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: |
|
|
|
|
yandex_pay = Payment.objects.create( |
|
|
|
|
order_amount=i['price'], |
|
|
|
|
|