def test_checkout_add_voucher_code_checkout_with_sale(
    api_client, checkout_with_item, voucher_percentage, discount_info
):
    assert calculations.checkout_subtotal(
        checkout_with_item
    ) > calculations.checkout_subtotal(checkout_with_item, discounts=[discount_info])
    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    variables = {"checkoutId": checkout_id, "promoCode": voucher_percentage.code}
    data = _mutate_checkout_add_promo_code(api_client, variables)

    checkout_with_item.refresh_from_db()
    assert not data["errors"]
    assert checkout_with_item.voucher_code == voucher_percentage.code
    assert checkout_with_item.discount_amount == Decimal(1.5)
Ejemplo n.º 2
0
def test_create_order_with_gift_card(
    checkout_with_gift_card, customer_user, shipping_method, is_anonymous_user
):
    checkout_user = None if is_anonymous_user else customer_user
    checkout = checkout_with_gift_card
    checkout.user = checkout_user
    checkout.billing_address = customer_user.default_billing_address
    checkout.shipping_address = customer_user.default_billing_address
    checkout.shipping_method = shipping_method
    checkout.save()

    subtotal = calculations.checkout_subtotal(checkout)
    shipping_price = calculations.checkout_shipping_price(checkout)
    total_gross_without_gift_cards = (
        subtotal.gross + shipping_price.gross - checkout.discount
    )
    gift_cards_balance = checkout.get_total_gift_cards_balance()

    order = create_order(
        checkout=checkout,
        order_data=prepare_order_data(
            checkout=checkout, tracking_code="tracking_code", discounts=None
        ),
        user=customer_user if not is_anonymous_user else AnonymousUser(),
        redirect_url="https://www.example.com",
    )

    assert order.gift_cards.count() == 1
    assert order.gift_cards.first().current_balance.amount == 0
    assert order.total.gross == (total_gross_without_gift_cards - gift_cards_balance)
Ejemplo n.º 3
0
def test_calculations_checkout_subtotal_with_vatlayer(vatlayer, settings,
                                                      checkout_with_item):
    settings.PLUGINS = ["saleor.plugins.vatlayer.plugin.VatlayerPlugin"]
    checkout_subtotal = calculations.checkout_subtotal(
        checkout=checkout_with_item, lines=list(checkout_with_item))
    assert checkout_subtotal == TaxedMoney(net=Money("30", "USD"),
                                           gross=Money("30", "USD"))
def test_checkout_lines_delete_with_not_applicable_voucher(
        user_api_client, checkout_with_item, voucher):
    subtotal = calculations.checkout_subtotal(checkout=checkout_with_item,
                                              lines=list(checkout_with_item))
    voucher.min_spent = subtotal.gross
    voucher.save(update_fields=["min_spent_amount", "currency"])

    add_voucher_to_checkout(checkout_with_item, list(checkout_with_item),
                            voucher)
    assert checkout_with_item.voucher_code == voucher.code

    line = checkout_with_item.lines.first()

    checkout_id = graphene.Node.to_global_id("Checkout", checkout_with_item.pk)
    line_id = graphene.Node.to_global_id("CheckoutLine", line.pk)
    variables = {"checkoutId": checkout_id, "lineId": line_id}
    response = user_api_client.post_graphql(MUTATION_CHECKOUT_LINES_DELETE,
                                            variables)
    content = get_graphql_content(response)

    data = content["data"]["checkoutLineDelete"]
    assert not data["errors"]
    checkout_with_item.refresh_from_db()
    assert checkout_with_item.lines.count() == 0
    assert checkout_with_item.voucher_code is None
Ejemplo n.º 5
0
def test_adding_same_variant(checkout, product):
    variant = product.variants.get()
    add_variant_to_checkout(checkout, variant, 1)
    add_variant_to_checkout(checkout, variant, 2)
    assert checkout.lines.count() == 1
    assert checkout.quantity == 3
    subtotal = TaxedMoney(Money("30.00", "USD"), Money("30.00", "USD"))
    assert calculations.checkout_subtotal(checkout) == subtotal
Ejemplo n.º 6
0
def test_recalculate_checkout_discount_free_shipping_subtotal_bigger_than_shipping(
    checkout_with_voucher_percentage_and_shipping,
    voucher_free_shipping,
    shipping_method,
):
    checkout = checkout_with_voucher_percentage_and_shipping

    shipping_method.price = calculations.checkout_subtotal(
        checkout).gross - Money("1.00", "USD")
    shipping_method.save()

    recalculate_checkout_discount(checkout, None)

    assert checkout.discount == shipping_method.price
    assert checkout.discount_name == "Free shipping"
    assert calculations.checkout_total(
        checkout) == calculations.checkout_subtotal(checkout)
def test_checkout_add_specific_product_voucher_code_checkout_with_sale(
    api_client, checkout_with_item, voucher_specific_product_type, discount_info
):
    voucher = voucher_specific_product_type
    checkout = checkout_with_item
    expected_discount = Decimal(1.5)
    assert calculations.checkout_subtotal(checkout) > calculations.checkout_subtotal(
        checkout, discounts=[discount_info]
    )
    checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
    variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
    data = _mutate_checkout_add_promo_code(api_client, variables)

    checkout.refresh_from_db()
    assert not data["errors"]
    assert checkout.voucher_code == voucher.code
    assert checkout.discount_amount == expected_discount
    assert checkout.discount == Money(expected_discount, "USD")
def test_checkout_add_products_voucher_code_checkout_with_sale(
        api_client, checkout_with_item, voucher_percentage, discount_info):
    checkout = checkout_with_item
    product = checkout.lines.first().variant.product
    voucher = voucher_percentage
    voucher.type = VoucherType.SPECIFIC_PRODUCT
    voucher.save()
    voucher.products.add(product)

    assert calculations.checkout_subtotal(
        checkout) > calculations.checkout_subtotal(checkout,
                                                   discounts=[discount_info])
    checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)
    variables = {"checkoutId": checkout_id, "promoCode": voucher.code}
    data = _mutate_checkout_add_promo_code(api_client, variables)

    checkout.refresh_from_db()
    assert not data["errors"]
    assert checkout.voucher_code == voucher.code
    assert checkout.discount_amount == Decimal(1.5)
Ejemplo n.º 9
0
def test_checkout_summary_page(settings, client, request_checkout_with_item):
    settings.DEFAULT_COUNTRY = "PL"
    response = client.get(reverse("checkout:dropdown"))
    assert response.status_code == 200
    content = response.context
    assert content["quantity"] == request_checkout_with_item.quantity
    checkout_total = calculations.checkout_subtotal(request_checkout_with_item)
    assert content["total"] == checkout_total
    assert len(content["lines"]) == 1
    checkout_line = content["lines"][0]
    variant = request_checkout_with_item.lines.get().variant
    assert checkout_line["variant"] == variant
    assert checkout_line["quantity"] == 1