def get_queryset(self): print(self.kwargs.get('event_uuid', None), get_event_object_by_uuid(self.kwargs.get('event_uuid', None))) if self.kwargs.get('event_uuid', None): return TransportationPickupLocation.objects.filter( event=get_event_object_by_uuid( self.kwargs.get('event_uuid', None))) return TransportationPickupLocation.objects.filter( transportationinfo=1)
def get_queryset(self): """ Return a list of all receipt ordered items of given event """ event = get_event_object_by_uuid(self.kwargs['event_uuid']) order_list = Order.objects.filter(event=event) return OrderedItem.objects.filter(order__in=order_list).filter( transaction_type=dict(ORDER_ITEM_TRANSACTION_TYPE_CHOICES).get(RECEIPT))
def redeem_balance(request): event = get_event_object_by_uuid(request.data['event_uuid']) main_attendee = get_event_attendee_object_by_uuid(request.data['main_attendee_uuid']) latest_order = get_latest_order_of_main_user(main_attendee.user, event) amount_to_refund = abs(get_refundable_balance_from_latest_order(latest_order)) # here we apply the refund payment API of the payment-gateway # create payment object in transaction table , if response is valid, # we create order balance transfer ordered item ( reduce the actual balance field) # and also create refund ordered item # TODO : logic here to call REFUND API and get transaction detail transaction_detail = { 'transaction_reference_id': 'test', 'amount_to_refund': amount_to_refund, 'payment_method': dict(DEFAULT_ITEM_MASTERS_NAME).get(REFUND_ITEM) } order_data = get_basic_order_dict(main_attendee.user, main_attendee, event) order = create_order_object(order_data) refund_ordered_item_data = get_refund_ordered_item_dict(order, main_attendee.user, transaction_detail, dict(ORDER_ITEM_TRANSACTION_TYPE_CHOICES).get(REFUND), main_attendee) # now we create ordered_item object for given cart_item ordered_item = create_ordered_item_object(refund_ordered_item_data) # now we add ordered_item to order object order = add_ordered_item_to_order(order, ordered_item) # now we create balance-used ordered item and attach it to order balance_ordered_item = get_balance_ordered_item_dict(order, main_attendee.user, dict(DEFAULT_ITEM_MASTERS_NAME).get(BALANCE_USED), # since balance is to be subtracted , we need # to apply negation amount_to_refund.__neg__(), main_attendee) # now we create ordered_item object for given cart_item ordered_item = create_ordered_item_object(balance_ordered_item) # now we add ordered_item to order object order = add_ordered_item_to_order(order, ordered_item) # finally we update the balance field of the order, since we need to subtract the balance , to_add_balance has to # negative update_balance_of_order(order, latest_order, amount_to_refund.__neg__()) return Response({'code': getattr(settings, 'SUCCESS_CODE', 1), 'message': 'Your balance has been redeem successfully!'}, status=status.HTTP_200_OK)
def pay_balance(request): event = get_event_object_by_uuid(request.data['event_uuid']) main_attendee = get_event_attendee_object_by_uuid(request.data['main_attendee_uuid']) latest_order = get_latest_order_of_main_user(main_attendee.user, event) final_amount_to_be_paid = abs(get_net_positive_balance_credit_from_latest_order(latest_order)) # here we apply the refund payment API of the payment-gateway # create payment object in transaction table , if response is valid, # we create order balance transfer ordered item ( reduce the actual balance field) # and also create refund ordered item # TODO : logic here to call PAYMENT API and get transaction detail token = request.data['token']['id'] transaction_detail = perform_stripe_payment(token, final_amount_to_be_paid) order_data = get_basic_order_dict(main_attendee.user, main_attendee, event) order = create_order_object(order_data) payment_ordered_item_data = get_payment_ordered_item_dict(order, main_attendee.user, transaction_detail, dict(ORDER_ITEM_TRANSACTION_TYPE_CHOICES).get(RECEIPT), main_attendee) # now we create ordered_item object for given cart_item ordered_item = create_ordered_item_object(payment_ordered_item_data) # now we add ordered_item to order object order = add_ordered_item_to_order(order, ordered_item) # now we create balance-used ordered item and attach it to order balance_ordered_item = get_balance_ordered_item_dict(order, main_attendee.user, dict(DEFAULT_ITEM_MASTERS_NAME).get(BALANCE_USED), final_amount_to_be_paid, main_attendee) # now we create ordered_item object for given cart_item ordered_item = create_ordered_item_object(balance_ordered_item) # now we add ordered_item to order object order = add_ordered_item_to_order(order, ordered_item) # finally we update the balance field of the order, since we need to subtract the balance , to_add_balance has to # negative update_balance_credit_of_order(order, latest_order, final_amount_to_be_paid.__neg__()) return Response({'code': getattr(settings, 'SUCCESS_CODE', 1), 'message': 'Your payment has been done successfully!'}, status=status.HTTP_200_OK)
def get_queryset(self): """ Return a list of all event attendees who have been registered to given accommodation item obtained from request data.. """ event = get_event_object_by_uuid(self.kwargs['event_uuid']) event_item = get_event_item_object( self.request.query_params.get('event_item_uuid')) main_attendee_uuid_list = OrderedItem.objects.filter( event_attendee__in=EventAttendee.objects.filter( event=event)).filter(event_item=event_item).values_list( 'event_attendee__uuid', flat=True) return EventAttendee.objects.filter( registered_by__uuid__in=main_attendee_uuid_list).filter( registration_status=dict(EVENT_REGISTRATION_STATUS).get( CONFIRMED)).order_by('created_at')
def get_queryset(self): """ Return a list of all event attendees who are left to pay balance (whose latest order has net balance less than zero i.e balance_credit greater than balance in his/her latest order. """ event = get_event_object_by_uuid(self.kwargs['event_uuid']) # gives unique set of debitor attendee list whose have balance_credit greater than balance attendee_uuid_list = set( Order.objects.filter(event=event).filter( balance_credit__gt=F('balance')).values_list( 'event_attendee__uuid', flat=True)) debitor_attendee_uuid_list = [] for uuid in attendee_uuid_list: attendee = get_event_attendee_object_by_uuid(uuid) if get_net_positive_balance_credit_from_latest_order( get_latest_order_of_main_user(attendee.user, attendee.event)) > 0: debitor_attendee_uuid_list.append(uuid) return EventAttendee.objects.filter( uuid__in=debitor_attendee_uuid_list)
def get_serializer_context(self): context = super().get_serializer_context() context.update( {"event": get_event_object_by_uuid(self.kwargs['event_uuid'])}) return context
def get_event(self): return get_event_object_by_uuid(self.kwargs['event_uuid'])