Exemplo n.º 1
0
def get_order_price(order_obj, discount):
    """
    Fetches the price of the order after discount
    """
    if not valid_on_order(discount, order_obj):
        return order_obj.price

    return discount_price(orders.total_price(order_obj), discount)
Exemplo n.º 2
0
def valid_on_order(discount, order_obj):
    if discount.discount_scope != DiscountScope.ALL_ITEMS:
        return False
    utc_now = datetime.datetime.utcnow()
    if orders.total_price(order_obj) <= discount.order_minimum_spending:
        return False
    if discount.discount_lifetime_type == DiscountLifetime.LIMITED:
        if discount.expire_utc_datetime is not None and utc_now > discount.expire_utc_datetime:
            return False
        if discount.begins_utc_datetime is not None and utc_now < discount.begins_utc_datetime:
            return False
    if discount.status == DiscountStatus.DISABLED:
        return False
    return True
Exemplo n.º 3
0
def is_valid(coupon, order_obj):
    """
    Checks if a coupon is valid on an order
    """
    user_obj = users.get(order_obj.user_id)
    user_groups = user_obj.groups
    utc_now = datetime.datetime.utcnow()
    order_price = orders.total_price(order_obj)
    if coupon.user_scope == CouponUserScope.GROUP:
        if coupon.user_group not in user_groups:
            return False
    if coupon.user_scope == CouponUserScope.SPECIFIC:
        if coupon.user_id != user_obj._id:
            return False
    if coupon.valid_times <= 0:
        return False
    if coupon.coupon_lifetime_type == CouponLifetime.LIMITED:
        if utc_now > coupon.expire_utc_datetime:
            return False
        if utc_now < coupon.begins_utc_datetime:
            return False
    if coupon.order_minimum_spending < order_price:
        return False

    all_items = order_obj.items  # {obj_id: None, coll_name: None, quantity:None}

    flag = False
    for i in all_items:
        i["obj"] = items.get(i["obj_id"])
        i["container"] = items.item_container(i["obj"])

        if coupon.coupon_scope == CouponScope.CONTAINER_WIDE:
            container_obj = items.get_container(coupon.obj_id)
            if items.is_parent_container(container_obj, i["container"]) or i["container"]._id == coupon.obj_id:
                flag = True
                break

        if coupon.coupon_scope == CouponScope.ITEM_ONLY:
            if i["obj_id"] == coupon.obj_id:
                flag = True
                break
    if not flag:
        return False

    return True
Exemplo n.º 4
0
def _general_discount(coupon, order_obj):
    total_price = orders.total_price(order_obj)
    if total_price >= coupon.coupon_value:
        return Decimal(coupon.coupon_value)
    else:
        return Decimal(total_price)
Exemplo n.º 5
0
    def total_price(self):
        import orders


        return orders.total_price(self)
Exemplo n.º 6
0
def cashback_value(cashback_rule, order_obj):
    price = orders.total_price(order_obj)
    price = Decimal(price) * Decimal(cashback_rule.cashback_percentage) / Decimal(100)
    return float(price)