def test_matching_coupon_code(rf): default_price = 10 request, product = _init_test_for_product_without_basket(rf, default_price) discount_amount = 4 coupon_code = CouponCode.objects.create(code="HORSESHOW2018", active=True) coupon_code.shops = [request.shop] discount = Discount.objects.create( active=True, product=product, coupon_code=coupon_code, discount_amount_value=discount_amount) discount.shops.add(request.shop) # No basket means no coupon code in basket which means no discount assert product.get_price_info(request).price == request.shop.create_price(default_price) request, product, basket = _init_test_for_product_with_basket(rf, default_price) assert request.basket == basket # Ok now we have basket, but the coupon is not yet applied assert product.get_price_info(request).price == request.shop.create_price(default_price) # Make sure disabling discount makes coupon un-usable coupon_code_modifier = CouponCodeModule() assert coupon_code_modifier.can_use_code(request.basket, coupon_code.code) discount.active = False discount.save() assert not coupon_code_modifier.can_use_code(request.basket, coupon_code.code) discount.active = True discount.save() assert coupon_code_modifier.can_use_code(request.basket, coupon_code.code) basket.add_code(coupon_code) assert coupon_code.code in basket.codes assert coupon_code.code in request.basket.codes get_price_info(context=request, product=product.id) # Test if get_price_info works with product.id sent assert product.get_price_info(request).price == request.shop.create_price(default_price - discount_amount) # Apply coupon code after order is created basket.clear_codes() creator = OrderCreator() order = creator.create_order(basket) assert order.taxful_total_price == request.shop.create_price(default_price) # Make sure non active discount can't be used discount.active = False discount.save() order_modifier = CouponCodeModule() assert not order_modifier.use_code(order, coupon_code.code) discount.active = True discount.save() assert isinstance(order_modifier.use_code(order, coupon_code.code), CouponUsage)
def get_price_info(self, context, quantity=1): """ Get `PriceInfo` object for the product in given context. Returned `PriceInfo` object contains calculated `price` and `base_price`. The calculation of prices is handled in the current pricing module. :type context: shuup.core.pricing.PricingContextable :rtype: shuup.core.pricing.PriceInfo """ from shuup.core.pricing import get_price_info return get_price_info(product=self, context=context, quantity=quantity)
def test_get_price_info_with_quantity(rf): (request, products, price) = initialize_test(rf) pi = get_price_info(request, products[0], 20) assert pi.price == price(1800) assert pi.base_price == price(2400) assert pi.quantity == 20
def test_get_price_info(rf): (request, products, price) = initialize_test(rf) pi = get_price_info(request, products[0]) assert pi.price == price(90) assert pi.base_price == price(120) assert pi.quantity == 1