Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add unit price to checkout line resolver (#9821)
Filip Owczarekb06ee4a01c39
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fe9323f972..a92e94d45a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ All notable, unreleased changes to this project will be documented in this file.- Migrate order discount id from int to UUID - #9729 by @IKarbowiak- Changed the order discount `id` from `int` to `UUID`, the old ids still can be usedfor old order discounts.+- Add `unitPrice`, `undiscountedUnitPrice`, `undiscountedTotalPrice` fields to `CheckoutLine` type - #9821 by @fowczarek## Breakingdiff --git a/saleor/checkout/base_calculations.py b/saleor/checkout/base_calculations.pyindex 6e53d27227..be0c616658 100644--- a/saleor/checkout/base_calculations.py+++ b/saleor/checkout/base_calculations.py@@ -22,23 +22,12 @@ if TYPE_CHECKING:from ..order.models import OrderLine-def calculate_base_line_unit_price(+def _calculate_base_line_unit_price(line_info: CheckoutLineInfo,channel: "Channel",discounts: Optional[Iterable[DiscountInfo]] = None,) -> CheckoutPricesData:- """Calculate line unit prices including discounts and vouchers.-- Returns a three money values. Undiscounted price, price and price with voucher.- Voucher is added to 'price_with_discounts' when line's product matches to products- applicable for voucher.- For voucher with 'apply once per order', the price will be reduced in calculation- of total price.- 'price' includes discount from sale if any valid exists.- 'price_with_discounts' includes voucher discount and sale discount if any valid- exists.- 'undiscounted_price' is a price without any sale and voucher.- """+ """Calculate base line unit price without voucher applied once per order."""variant = line_info.variantvariant_price = variant.get_price(line_info.product,@@ -81,6 +70,40 @@ def calculate_base_line_unit_price()+def calculate_base_line_unit_price(+ line_info: CheckoutLineInfo,+ channel: "Channel",+ discounts: Optional[Iterable[DiscountInfo]] = None,+) -> CheckoutPricesData:+ """Calculate line unit prices including discounts and vouchers.++ Returns a three money values. Undiscounted price, price and price with voucher.+ Voucher is added to 'price_with_discounts' when line's product matches to products+ applicable for voucher.+ For voucher with 'apply once per order', the price will be included in unit price.+ 'price' includes discount from sale if any valid exists.+ 'price_with_discounts' includes voucher discount and sale discount if any valid+ exists.+ 'undiscounted_price' is a price without any sale and voucher.+ """+ prices_data = calculate_base_line_total_price(+ line_info=line_info, channel=channel, discounts=discounts+ )+ quantity = line_info.line.quantity+ currency = prices_data.price_with_discounts.currency+ return CheckoutPricesData(+ undiscounted_price=quantize_price(+ prices_data.undiscounted_price / quantity, currency+ ),+ price_with_sale=quantize_price(+ prices_data.price_with_sale / quantity, currency+ ),+ price_with_discounts=quantize_price(+ prices_data.price_with_discounts / quantity, currency+ ),+ )++def calculate_base_line_total_price(line_info: CheckoutLineInfo,channel: "Channel",@@ -96,7 +119,7 @@ def calculate_base_line_total_price(exists.'undiscounted_price' is a price without any sale and voucher."""- prices_data = calculate_base_line_unit_price(+ prices_data = _calculate_base_line_unit_price(line_info=line_info, channel=channel, discounts=discounts)if line_info.voucher and line_info.voucher.apply_once_per_order:@@ -108,7 +131,7 @@ def calculate_base_line_total_price(zero_money(prices_data.price_with_sale.currency),)# we add -1 as we handle a case when voucher is applied only to single line- # of the cheapest line+ # of the cheapest itemquantity_without_voucher = line_info.line.quantity - 1prices_data = CheckoutPricesData(price_with_discounts=(diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex a2f2cc460d..ffbf9d7770 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -484,7 +484,7 @@ def _create_order(voucher = order_data.get("voucher")# When we have a voucher for specific products we track it directly in the# Orderline. Voucher with 'apply_once_per_order' is handled in the same way- # as we apply it only for single quantity of the cheapest line.+ # as we apply it only for single quantity of the cheapest item.if not voucher or (voucher.type != VoucherType.SPECIFIC_PRODUCTand not voucher.apply_once_per_order@@ -907,7 +907,7 @@ def _handle_checkout_discount(# When we have a voucher for specific products we track it directly in the# Orderline. Voucher with 'apply_once_per_order' is handled in the same way- # as we apply it only for single quantity of the cheapest line.+ # as we apply it only for single quantity of the cheapest item.if not voucher or (voucher.type != VoucherType.SPECIFIC_PRODUCTand not voucher.apply_once_per_orderdiff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex 84ea611ebe..ada060af21 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -331,7 +331,7 @@ def apply_voucher_to_checkout_line("""Attach voucher to valid checkout lines info.Apply a voucher to checkout line info when the voucher has the type- SPECIFIC_PRODUCTS or is applied only to the cheapest line.+ SPECIFIC_PRODUCTS or is applied only to the cheapest item."""from .utils import get_discounted_linesdiff --git a/saleor/checkout/tests/test_base_calculations.py b/saleor/checkout/tests/test_base_calculations.pyindex 7ce35b3e99..08c9d10d74 100644--- a/saleor/checkout/tests/test_base_calculations.py+++ b/saleor/checkout/tests/test_base_calculations.py@@ -336,10 +336,10 @@ def test_calculate_base_line_unit_price_with_discounts_apply_once_per_order(channel_listing=checkout_line_info.channel_listing,discounts=[],)+ expected_voucher_amount = expected_price * voucher_percent_value / 100assert prices_data.undiscounted_price == expected_priceassert prices_data.price_with_sale == expected_price- # apply once per order is applied when calculating line total.- assert prices_data.price_with_discounts == expected_price+ assert prices_data.price_with_discounts == expected_price - expected_voucher_amountdef test_calculate_base_line_unit_price_with_discounts_once_per_order_custom_prices(@@ -375,10 +375,10 @@ def test_calculate_base_line_unit_price_with_discounts_once_per_order_custom_pri# thencurrency = checkout_line_info.channel_listing.currencyexpected_price = Money(price_override, currency)+ expected_voucher_amount = expected_price * voucher_percent_value / 100assert prices_data.undiscounted_price == expected_priceassert prices_data.price_with_sale == expected_price- # apply once per order is applied when calculating line total.- assert prices_data.price_with_discounts == expected_price+ assert prices_data.price_with_discounts == expected_price - expected_voucher_amountdef test_calculate_base_line_unit_price_with_variant_on_sale_and_voucher(diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 6b60e8ea40..9600732cc8 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -37,6 +37,7 @@ from ....checkout.utils import (calculate_checkout_quantity,)from ....core.payments import PaymentInterface+from ....core.prices import quantize_pricefrom ....payment import TransactionAction, TransactionKindfrom ....payment.interface import GatewayResponsefrom ....plugins.base_plugin import ExcludedShippingMethod@@ -3643,12 +3644,25 @@ QUERY_CHECKOUT_PRICES = """}}lines {+ unitPrice {+ gross {+ amount+ }+ }+ undiscountedUnitPrice {+ amount+ currency+ }totalPrice {currencygross {amount}}+ undiscountedTotalPrice {+ amount+ currency+ }}}}@@ -3656,16 +3670,23 @@ QUERY_CHECKOUT_PRICES = """def test_checkout_prices(user_api_client, checkout_with_item):+ # givenquery = QUERY_CHECKOUT_PRICESvariables = {"token": str(checkout_with_item.token)}++ # whenresponse = user_api_client.post_graphql(query, variables)content = get_graphql_content(response)data = content["data"]["checkout"]++ # thenassert data["token"] == str(checkout_with_item.token)assert len(data["lines"]) == checkout_with_item.lines.count()+manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -3673,6 +3694,7 @@ def test_checkout_prices(user_api_client, checkout_with_item):address=checkout_with_item.shipping_address,)assert data["totalPrice"]["gross"]["amount"] == (total.gross.amount)+subtotal = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,@@ -3681,28 +3703,65 @@ def test_checkout_prices(user_api_client, checkout_with_item):)assert data["subtotalPrice"]["gross"]["amount"] == (subtotal.gross.amount)+ line_info = lines[0]+ assert line_info.line.quantity > 0+ line_total_price = calculations.checkout_line_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ discounts=[],+ ).price_with_discounts+ assert (+ data["lines"][0]["unitPrice"]["gross"]["amount"]+ == line_total_price.gross.amount / line_info.line.quantity+ )+ assert (+ data["lines"][0]["totalPrice"]["gross"]["amount"]+ == line_total_price.gross.amount+ )+ undiscounted_unit_price = line_info.variant.get_price(+ line_info.product,+ line_info.collections,+ checkout_info.channel,+ line_info.channel_listing,+ [],+ line_info.line.price_override,+ )+ assert (+ data["lines"][0]["undiscountedUnitPrice"]["amount"]+ == undiscounted_unit_price.amount+ )+ assert (+ data["lines"][0]["undiscountedTotalPrice"]["amount"]+ == undiscounted_unit_price.amount * line_info.line.quantity+ )+def test_checkout_prices_checkout_with_custom_prices(user_api_client, checkout_with_item):+ # givenquery = QUERY_CHECKOUT_PRICES-checkout_line = checkout_with_item.lines.first()price_override = Decimal("20.00")checkout_line.price_override = price_overridecheckout_line.save(update_fields=["price_override"])-variables = {"token": str(checkout_with_item.token)}+ # whenresponse = user_api_client.post_graphql(query, variables)-content = get_graphql_content(response)data = content["data"]["checkout"]++ # thenassert data["token"] == str(checkout_with_item.token)assert len(data["lines"]) == checkout_with_item.lines.count()+manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+shipping_price = base_calculations.base_checkout_delivery_price(checkout_info, lines)@@ -3714,6 +3773,234 @@ def test_checkout_prices_checkout_with_custom_prices(data["subtotalPrice"]["gross"]["amount"]== checkout_line.quantity * price_override)+ line_info = lines[0]+ assert line_info.line.quantity > 0+ assert data["lines"][0]["unitPrice"]["gross"]["amount"] == price_override+ assert (+ data["lines"][0]["totalPrice"]["gross"]["amount"]+ == checkout_line.quantity * price_override+ )+ assert data["lines"][0]["undiscountedUnitPrice"]["amount"] == price_override+ assert (+ data["lines"][0]["undiscountedTotalPrice"]["amount"]+ == price_override * line_info.line.quantity+ )+++def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discount_info):+ # given+ query = QUERY_CHECKOUT_PRICES+ variables = {"token": str(checkout_with_item.token)}++ # when+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkout"]++ # then+ assert data["token"] == str(checkout_with_item.token)+ assert len(data["lines"]) == checkout_with_item.lines.count()++ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)++ total = calculations.checkout_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_with_item.shipping_address,+ discounts=[discount_info],+ )+ assert data["totalPrice"]["gross"]["amount"] == (total.gross.amount)+ subtotal = calculations.checkout_subtotal(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_with_item.shipping_address,+ discounts=[discount_info],+ )+ assert data["subtotalPrice"]["gross"]["amount"] == (subtotal.gross.amount)+ line_info = lines[0]+ assert line_info.line.quantity > 0+ line_total_price = calculations.checkout_line_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ discounts=[discount_info],+ ).price_with_discounts+ assert (+ data["lines"][0]["unitPrice"]["gross"]["amount"]+ == line_total_price.gross.amount / line_info.line.quantity+ )+ assert (+ data["lines"][0]["totalPrice"]["gross"]["amount"]+ == line_total_price.gross.amount+ )+ undiscounted_unit_price = line_info.variant.get_price(+ line_info.product,+ line_info.collections,+ checkout_info.channel,+ line_info.channel_listing,+ [],+ line_info.line.price_override,+ )+ assert (+ data["lines"][0]["undiscountedUnitPrice"]["amount"]+ == undiscounted_unit_price.amount+ )+ assert (+ data["lines"][0]["undiscountedTotalPrice"]["amount"]+ == undiscounted_unit_price.amount * line_info.line.quantity+ )+++def test_checkout_prices_with_specific_voucher(+ user_api_client, checkout_with_item_and_voucher_specific_products+):+ # given+ checkout = checkout_with_item_and_voucher_specific_products+ query = QUERY_CHECKOUT_PRICES+ variables = {"token": str(checkout.token)}++ # when+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkout"]++ # then+ assert data["token"] == str(checkout.token)+ assert len(data["lines"]) == checkout.lines.count()++ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)++ total = calculations.checkout_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_info.shipping_address,+ )+ assert data["totalPrice"]["gross"]["amount"] == (total.gross.amount)+ subtotal = calculations.checkout_subtotal(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_info.shipping_address,+ )+ assert data["subtotalPrice"]["gross"]["amount"] == (subtotal.gross.amount)+ line_info = lines[0]+ assert line_info.line.quantity > 0+ line_total_prices = calculations.checkout_line_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ )+ assert (+ line_total_prices.price_with_discounts != line_total_prices.undiscounted_price+ )+ assert line_total_prices.price_with_discounts != line_total_prices.price_with_sale+ line_total_price = line_total_prices.price_with_discounts+ assert (+ data["lines"][0]["unitPrice"]["gross"]["amount"]+ == line_total_price.gross.amount / line_info.line.quantity+ )+ assert (+ data["lines"][0]["totalPrice"]["gross"]["amount"]+ == line_total_price.gross.amount+ )+ undiscounted_unit_price = line_info.variant.get_price(+ line_info.product,+ line_info.collections,+ checkout_info.channel,+ line_info.channel_listing,+ [],+ line_info.line.price_override,+ )+ assert (+ data["lines"][0]["undiscountedUnitPrice"]["amount"]+ == undiscounted_unit_price.amount+ )+ assert (+ data["lines"][0]["undiscountedTotalPrice"]["amount"]+ == undiscounted_unit_price.amount * line_info.line.quantity+ )+++def test_checkout_prices_with_voucher_once_per_order(+ user_api_client, checkout_with_item_and_voucher_once_per_order+):+ # given+ checkout = checkout_with_item_and_voucher_once_per_order+ query = QUERY_CHECKOUT_PRICES+ variables = {"token": str(checkout.token)}++ # when+ response = user_api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkout"]++ # then+ assert data["token"] == str(checkout.token)+ assert len(data["lines"]) == checkout.lines.count()+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ total = calculations.checkout_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_info.shipping_address,+ )+ assert data["totalPrice"]["gross"]["amount"] == (total.gross.amount)+ subtotal = calculations.checkout_subtotal(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_info.shipping_address,+ )+ assert data["subtotalPrice"]["gross"]["amount"] == (subtotal.gross.amount)+ line_info = lines[0]+ assert line_info.line.quantity > 0+ line_total_prices = calculations.checkout_line_total(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ )+ assert (+ line_total_prices.price_with_discounts != line_total_prices.undiscounted_price+ )+ assert line_total_prices.price_with_discounts != line_total_prices.price_with_sale+ line_total_price = line_total_prices.price_with_discounts+ assert data["lines"][0]["unitPrice"]["gross"]["amount"] == float(+ quantize_price(+ line_total_price.gross.amount / line_info.line.quantity, checkout.currency+ )+ )+ assert (+ data["lines"][0]["totalPrice"]["gross"]["amount"]+ == line_total_price.gross.amount+ )+ undiscounted_unit_price = line_info.variant.get_price(+ line_info.product,+ line_info.collections,+ checkout_info.channel,+ line_info.channel_listing,+ [],+ line_info.line.price_override,+ )+ assert (+ data["lines"][0]["undiscountedUnitPrice"]["amount"]+ == undiscounted_unit_price.amount+ )+ assert (+ data["lines"][0]["undiscountedTotalPrice"]["amount"]+ == undiscounted_unit_price.amount * line_info.line.quantity+ )MUTATION_UPDATE_SHIPPING_METHOD = """diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex faed057242..3e185a404a 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -87,11 +87,26 @@ class CheckoutLine(ModelObjectType):"saleor.graphql.product.types.ProductVariant", required=True)quantity = graphene.Int(required=True)+ unit_price = graphene.Field(+ TaxedMoney,+ description="The unit price of the checkout line, with taxes and discounts.",+ required=True,+ )+ undiscounted_unit_price = graphene.Field(+ Money,+ description="The unit price of the checkout line, without discounts.",+ required=True,+ )total_price = graphene.Field(TaxedMoney,description="The sum of the checkout line price, taxes and discounts.",required=True,)+ undiscounted_total_price = graphene.Field(+ Money,+ description="The sum of the checkout line price, without discounts.",+ required=True,+ )requires_shipping = graphene.Boolean(description="Indicates whether the item need to be delivered.",required=True,@@ -111,6 +126,116 @@ class CheckoutLine(ModelObjectType):lambda data: ChannelContext(node=data[0], channel_slug=data[1].slug))+ @staticmethod+ def resolve_unit_price(root, info):+ # Temporary solution in new tax interface introduced in PR#9526+ # this value will be denormalized and store in checkout line.+ def with_checkout(checkout):+ discounts = DiscountsByDateTimeLoader(info.context).load(+ info.context.request_time+ )+ checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )+ lines = CheckoutLinesInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )++ def calculate_line_unit_price(data):+ (+ discounts,+ checkout_info,+ lines,+ ) = data+ for line_info in lines:+ if line_info.line.pk == root.pk:+ address = (+ checkout_info.shipping_address+ or checkout_info.billing_address+ )+ return info.context.plugins.calculate_checkout_line_unit_price(+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ address=address,+ discounts=discounts,+ ).price_with_discounts+ return None++ return Promise.all(+ [+ discounts,+ checkout_info,+ lines,+ ]+ ).then(calculate_line_unit_price)++ return (+ CheckoutByTokenLoader(info.context)+ .load(root.checkout_id)+ .then(with_checkout)+ )++ @staticmethod+ def resolve_undiscounted_unit_price(root, info):+ # Temporary solution in new tax interface introduced in PR#9526+ # this value will be denormalized and store in checkout line.+ def with_checkout(checkout):+ discounts = DiscountsByDateTimeLoader(info.context).load(+ info.context.request_time+ )+ checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )+ lines = CheckoutLinesInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )++ def calculate_undiscounted_unit_price(data):+ (+ discounts,+ checkout_info,+ lines,+ ) = data+ for line_info in lines:+ if line_info.line.pk == root.pk:+ address = (+ checkout_info.shipping_address+ or checkout_info.billing_address+ )+ include_taxes_in_prices = (+ info.context.site.settings.include_taxes_in_prices+ )+ undiscounted_price = (+ info.context.plugins.calculate_checkout_line_unit_price(+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ address=address,+ discounts=discounts,+ ).undiscounted_price+ )+ return (+ undiscounted_price.gross+ if include_taxes_in_prices+ else undiscounted_price.net+ )+ return None++ return Promise.all(+ [+ discounts,+ checkout_info,+ lines,+ ]+ ).then(calculate_undiscounted_unit_price)++ return (+ CheckoutByTokenLoader(info.context)+ .load(root.checkout_id)+ .then(with_checkout)+ )+@staticmethod@traced_resolverdef resolve_total_price(root, info):@@ -160,6 +285,66 @@ class CheckoutLine(ModelObjectType):.then(with_checkout))+ @staticmethod+ def resolve_undiscounted_total_price(root, info):+ # Temporary solution in new tax interface introduced in PR#9526+ # this value will be denormalized and store in checkout line.+ def with_checkout(checkout):+ discounts = DiscountsByDateTimeLoader(info.context).load(+ info.context.request_time+ )+ checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )+ lines = CheckoutLinesInfoByCheckoutTokenLoader(info.context).load(+ checkout.token+ )++ def calculate_undiscounted_total_price(data):+ (+ discounts,+ checkout_info,+ lines,+ ) = data+ for line_info in lines:+ if line_info.line.pk == root.pk:+ address = (+ checkout_info.shipping_address+ or checkout_info.billing_address+ )+ include_taxes_in_prices = (+ info.context.site.settings.include_taxes_in_prices+ )+ undiscounted_price = (+ info.context.plugins.calculate_checkout_line_total(+ checkout_info=checkout_info,+ lines=lines,+ checkout_line_info=line_info,+ address=address,+ discounts=discounts,+ ).undiscounted_price+ )+ return (+ undiscounted_price.gross+ if include_taxes_in_prices+ else undiscounted_price.net+ )+ return None++ return Promise.all(+ [+ discounts,+ checkout_info,+ lines,+ ]+ ).then(calculate_undiscounted_total_price)++ return (+ CheckoutByTokenLoader(info.context)+ .load(root.checkout_id)+ .then(with_checkout)+ )+@staticmethoddef resolve_requires_shipping(root: models.CheckoutLine, info):def is_shipping_required(product_type):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 435ef6e02e..45a14a3182 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -7691,9 +7691,18 @@ type CheckoutLine implements Node {variant: ProductVariant!quantity: Int!+ """The unit price of the checkout line, with taxes and discounts."""+ unitPrice: TaxedMoney!++ """The unit price of the checkout line, without discounts."""+ undiscountedUnitPrice: Money!+"""The sum of the checkout line price, taxes and discounts."""totalPrice: TaxedMoney!+ """The sum of the checkout line price, without discounts."""+ undiscountedTotalPrice: Money!+"""Indicates whether the item need to be delivered."""requiresShipping: Boolean!}diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex ff66c47e91..95aeba108c 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -40,7 +40,7 @@ from ..attribute.models import (from ..attribute.utils import associate_attribute_values_to_instancefrom ..checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ..checkout.models import Checkout, CheckoutLine-from ..checkout.utils import add_variant_to_checkout+from ..checkout.utils import add_variant_to_checkout, add_voucher_to_checkoutfrom ..core import EventDeliveryStatus, JobStatus, TimePeriodTypefrom ..core.models import EventDelivery, EventDeliveryAttempt, EventPayloadfrom ..core.payments import PaymentInterface@@ -312,6 +312,32 @@ def checkout_with_item(checkout, product):return checkout+def checkout_with_item_and_voucher_specific_products(+ checkout_with_item, voucher_specific_product_type+):+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ add_voucher_to_checkout(+ manager, checkout_info, lines, voucher_specific_product_type+ )+ checkout_with_item.refresh_from_db()+ return checkout_with_item+++def checkout_with_item_and_voucher_once_per_order(checkout_with_item, voucher):+ voucher.apply_once_per_order = True+ voucher.save()+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ add_voucher_to_checkout(manager, checkout_info, lines, voucher)+ checkout_with_item.refresh_from_db()+ return checkout_with_item++@pytest.fixturedef checkout_line(checkout_with_item):return checkout_with_item.lines.first()@@ -3062,7 +3088,8 @@ def voucher_percentage(channel_USD):@pytest.fixture-def voucher_specific_product_type(voucher_percentage):+def voucher_specific_product_type(voucher_percentage, product):+ voucher_percentage.products.add(product)voucher_percentage.type = VoucherType.SPECIFIC_PRODUCTvoucher_percentage.save()return voucher_percentage