Ejemplo n.º 1
0
def get_order_by_username(username):
    try:
        obj = user_handler.get_user_profile(username)
        sale_orders = SellOrders.objects.filter(farmer=obj)
        print sale_orders
        return sale_orders
    except:
        raise NotFoundException(entity='Order')
def delete_purchase_order_action(order_obj):
    cart_obj = order_obj.cart
    for item in cart_obj.cart_items.all():
        try:
            sell_obj = SellOrders.objects.get(id=item.sell_order.id)
            if sell_obj.quantity == 0:
                sell_obj.order_status = 'In Stock'
            sell_obj.quantity += item.quantity
            sell_obj.save()
        except:
            raise NotFoundException(entity='Product')
def post_purchase_order_action(cart_obj):
    for item in cart_obj.cart_items.all():
        try:
            sell_obj = SellOrders.objects.get(
                sell_order_token=item.sell_order.sell_order_token)
            sell_obj.quantity -= item.quantity
            sell_obj.save()
            if sell_obj.quantity == 0:
                sell_obj.order_status = 'Sold Out'
                sell_obj.save()
        except:
            raise NotFoundException(entity='Product')
Ejemplo n.º 4
0
def get_user_profile(user_id):
    try:
        user_obj = User.objects.get(username=user_id)
        try:
            farmer_obj = Farmer.objects.get(user=user_obj)
            return farmer_obj
        except:
            try:
                hotel_obj = Hotel.objects.get(user=user_obj)
                return hotel_obj
            except:
                return {}
    except:
        raise NotFoundException(entity='User')
Ejemplo n.º 5
0
def get_hotel_by_user_id(user_id):
    try:
        hotel = Hotel.objects.get(user_username=user_id)
        return hotel
    except:
        raise NotFoundException(entity='Hotel')
Ejemplo n.º 6
0
def get_farmer_by_user_id(user_id):
    try:
        farmer = Farmer.objects.get(user_username=user_id)
        return farmer
    except:
        raise NotFoundException(entity='Farmer')
Ejemplo n.º 7
0
def get_address_object_by_id(id):
    try:
        return Address.objects.get(id=id)
    except:
        raise NotFoundException(id)
Ejemplo n.º 8
0
def get_user_object_by_token(token):
    try:
        login_obj = Login.objects.get(login_token=token)
        return User.objects.get(username=login_obj.user_username)
    except:
        raise NotFoundException(token)
Ejemplo n.º 9
0
def get_login_object_by_token(token):
    try:
        return Login.objects.get(login_token=token)

    except:
        raise NotFoundException(token)
def get_order_by_token(token):
    try:
        return SellOrders.objects.get(sell_order_token=token)
    except:
        raise NotFoundException(entity='Order')
def get_user_object_by_token(token):
    try:
        login_obj = Login.objects.get(login_token=token)
        return user_handler.get_user_profile(login_obj.user.username)
    except:
        raise NotFoundException(token)
Ejemplo n.º 12
0
def get_cart_item_by_id(cart_item_id):
    try:
        return CartItem.objects.get(id=cart_item_id)
    except:
        raise NotFoundException(entity='Cart item')
def get_order_by_token(token):
    try:
        return PurchaseOrders.objects.get(purchase_order_token=token)
    except:
        raise NotFoundException(entity='Order')
def get_order_by_username(username):
    try:
        obj = user_handler.get_user_profile(username)
        return PurchaseOrders.objects.filter(hotel=obj)
    except:
        raise NotFoundException(entity='Order')
def get_product_by_id(product_id):
    try:
        return Product.objects.get(id=product_id)
    except:
        raise NotFoundException(entity='Product')
def get_product_by_name(product_name):
    try:
        return Product.objects.get(product_name=product_name)
    except:
        raise NotFoundException(entity='Product')
Ejemplo n.º 17
0
def get_cart_for_hotel(username):
    try:
        hotel = user_handler.get_user_profile(username)
        return Cart.objects.get(hotel=hotel, is_active=True)
    except:
        raise NotFoundException(entity='Cart')
def get_order_by_filter(criteria={}):
    try:
        return SellOrders.objects.filter(**criteria)
    except:
        raise NotFoundException(entity='Order')