Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refactor price calculation for Sales (#11934)
Filip Owczarekb8c8a482496b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ddaf93a2cc..0b2cb304f2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,15 @@ All notable, unreleased changes to this project will be documented in this file.### Breaking changes- `path` field for errors related with product variants input in `ProductBulkCreate` will return more detailed paths: `variants.1.stocks.0.warehouse` instead of `variants.1.warehouses` - #12534 by @SzymJ+- The `discounts` field has been removed from the listed plugin manager methods. Instead of the `discounts` argument, an applied `discount` is now assigned to each line in the `CheckoutLineInfo` inside the `CheckoutInfo` object. - #11934 by @fowczarek+ - `calculate_checkout_total`+ - `calculate_checkout_subtotal`+ - `calculate_checkout_shipping`+ - `get_checkout_shipping_tax_rate`+ - `calculate_checkout_line_total`+ - `calculate_checkout_line_unit_price`+ - `get_checkout_line_tax_rate`+ - `preprocess_order_creation`### GraphQL APIdiff --git a/conftest.py b/conftest.pyindex d29387f29e..ae925eca76 100644--- a/conftest.py+++ b/conftest.py@@ -10,6 +10,7 @@ from django.test.testcases import TransactionTestCasepytest_plugins = ["saleor.tests.fixtures",+ "saleor.discount.tests.test_utils.fixtures","saleor.plugins.tests.fixtures","saleor.graphql.tests.fixtures","saleor.graphql.channel.tests.fixtures",diff --git a/saleor/checkout/actions.py b/saleor/checkout/actions.pyindex b40de508c7..5dcd69141f 100644--- a/saleor/checkout/actions.py+++ b/saleor/checkout/actions.py@@ -1,7 +1,6 @@-from typing import Iterable, Optional, cast+from typing import castfrom ..core.utils.events import call_event-from ..discount import DiscountInfofrom ..payment.models import TransactionItemfrom ..plugins.manager import PluginsManagerfrom . import CheckoutChargeStatus@@ -12,19 +11,15 @@ from .models import Checkoutdef transaction_amounts_for_checkout_updated(transaction: TransactionItem,- discounts: Optional[Iterable["DiscountInfo"]],manager: "PluginsManager",):if not transaction.checkout_id:returncheckout = cast(Checkout, transaction.checkout)lines, _ = fetch_checkout_lines(checkout)- discounts = discounts or []- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)previous_charge_status = checkout_info.checkout.charge_status- fetch_checkout_data(- checkout_info, manager, lines, discounts=discounts, force_status_update=True- )+ fetch_checkout_data(checkout_info, manager, lines, force_status_update=True)previous_charge_status_is_fully_paid = previous_charge_status in [CheckoutChargeStatus.FULL,CheckoutChargeStatus.OVERCHARGED,diff --git a/saleor/checkout/base_calculations.py b/saleor/checkout/base_calculations.pyindex 5229855951..01cae874c7 100644--- a/saleor/checkout/base_calculations.py+++ b/saleor/checkout/base_calculations.py@@ -12,18 +12,16 @@ from prices import Moneyfrom ..core.prices import quantize_pricefrom ..core.taxes import zero_money-from ..discount import DiscountInfo, VoucherType-from .fetch import CheckoutInfo, CheckoutLineInfo+from ..discount import DiscountValueType, VoucherTypeif TYPE_CHECKING:from ..channel.models import Channel- from .fetch import ShippingMethodInfo+ from .fetch import CheckoutInfo, CheckoutLineInfo, ShippingMethodInfodef calculate_base_line_unit_price(line_info: "CheckoutLineInfo",channel: "Channel",- discounts: Optional[Iterable[DiscountInfo]] = None,) -> Money:"""Calculate line unit price including discounts and vouchers.@@ -32,7 +30,7 @@ def calculate_base_line_unit_price(The price does not include the entire order discount."""total_line_price = calculate_base_line_total_price(- line_info=line_info, channel=channel, discounts=discounts+ line_info=line_info, channel=channel)quantity = line_info.line.quantitycurrency = total_line_price.currency@@ -42,7 +40,6 @@ def calculate_base_line_unit_price(def calculate_base_line_total_price(line_info: "CheckoutLineInfo",channel: "Channel",- discounts: Optional[Iterable[DiscountInfo]] = None,) -> Money:"""Calculate line total price including discounts and vouchers.@@ -50,57 +47,61 @@ def calculate_base_line_total_price(voucher discounts.The price does not include the entire order discount."""- unit_price = _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:- variant_price_with_discounts = max(- unit_price- - line_info.voucher.get_discount_amount_for(unit_price, channel=channel),- zero_money(unit_price.currency),- )- # we add -1 as we handle a case when voucher is applied only to single line- # of the cheapest item- quantity_without_voucher = line_info.line.quantity - 1- total_price = (- unit_price * quantity_without_voucher + variant_price_with_discounts- )- else:- total_price = unit_price * line_info.line.quantity-- return quantize_price(total_price, total_price.currency)---def _calculate_base_line_unit_price(- line_info: "CheckoutLineInfo",- channel: "Channel",- discounts: Optional[Iterable[DiscountInfo]] = None,-) -> Money:- """Calculate base line unit price including discounts and vouchers.-- The price includes sales, specific product voucher discounts.- The price does not include the entire order discount.- """variant = line_info.variant+ currency = line_info.channel_listing.currency+ quantity = line_info.line.quantity+variant_price = variant.get_price(line_info.product,line_info.collections,channel,line_info.channel_listing,- discounts or [],+ [],line_info.line.price_override,)- if line_info.voucher and not line_info.voucher.apply_once_per_order:- unit_price = max(- variant_price- - line_info.voucher.get_discount_amount_for(variant_price, channel=channel),- zero_money(variant_price.currency),- )- else:- unit_price = variant_price+ total_price = variant_price * line_info.line.quantity++ for discount in line_info.discounts:+ discount_amount = Money(discount.amount_value, line_info.line.currency)+ total_price -= discount_amount++ if line_info.voucher:+ if not line_info.voucher.apply_once_per_order:+ if line_info.voucher.discount_value_type == DiscountValueType.PERCENTAGE:+ voucher_discount_amount = line_info.voucher.get_discount_amount_for(+ total_price, channel=channel+ )+ total_price = max(+ total_price - voucher_discount_amount, zero_money(currency)+ )+ else:+ unit_price = total_price / quantity+ voucher_unit_discount_amount = (+ line_info.voucher.get_discount_amount_for(+ unit_price, channel=channel+ )+ )+ total_price = max(+ total_price - (voucher_unit_discount_amount * quantity),+ zero_money(currency),+ )+ else:+ unit_price = total_price / quantity+ voucher_unit_discount_amount = line_info.voucher.get_discount_amount_for(+ unit_price, channel=channel+ )+ variant_price_with_discounts = max(+ unit_price - voucher_unit_discount_amount, zero_money(currency)+ )+ # we add -1 as we handle a case when voucher is applied only to single line+ # of the cheapest item+ quantity_without_voucher = line_info.line.quantity - 1+ total_price = (+ unit_price * quantity_without_voucher + variant_price_with_discounts+ )- return quantize_price(unit_price, unit_price.currency)+ return quantize_price(total_price, total_price.currency)def calculate_undiscounted_base_line_total_price(@@ -203,7 +204,6 @@ def calculate_base_price_for_shipping_method(def base_checkout_total(checkout_info: "CheckoutInfo",- discounts: Iterable[DiscountInfo],lines: Iterable["CheckoutLineInfo"],) -> Money:"""Return the total cost of the checkout.@@ -213,16 +213,7 @@ def base_checkout_total(The price does not include the entire order discount."""currency = checkout_info.checkout.currency- line_totals = [- calculate_base_line_total_price(- line_info,- checkout_info.channel,- discounts,- )- for line_info in lines- ]- subtotal = sum(line_totals, zero_money(currency))-+ subtotal = base_checkout_subtotal(lines, checkout_info.channel, currency)shipping_price = base_checkout_delivery_price(checkout_info, lines)return subtotal + shipping_price@@ -232,7 +223,6 @@ def base_checkout_subtotal(checkout_lines: Iterable["CheckoutLineInfo"],channel: "Channel",currency: str,- discounts: Optional[Iterable[DiscountInfo]] = None,) -> Money:"""Return the checkout subtotal value.@@ -244,7 +234,6 @@ def base_checkout_subtotal(calculate_base_line_total_price(line,channel,- discounts,)for line in checkout_lines]@@ -254,7 +243,6 @@ def base_checkout_subtotal(def checkout_total(checkout_info: "CheckoutInfo",- discounts: Iterable[DiscountInfo],lines: Iterable["CheckoutLineInfo"],) -> Money:"""Return the total cost of the checkout including discounts and vouchers.@@ -262,16 +250,7 @@ def checkout_total(It should be used as a based value when no flat rate/tax plugin/tax app is active."""currency = checkout_info.checkout.currency- line_totals = [- calculate_base_line_total_price(- line_info,- checkout_info.channel,- discounts,- )- for line_info in lines- ]- subtotal = sum(line_totals, zero_money(currency))-+ subtotal = base_checkout_subtotal(lines, checkout_info.channel, currency)shipping_price = base_checkout_delivery_price(checkout_info, lines)discount = checkout_info.checkout.discount@@ -294,7 +273,6 @@ def apply_checkout_discount_on_checkout_line(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable["DiscountInfo"],line_total_price: Money,):"""Calculate the checkout line price with discounts.@@ -331,7 +309,6 @@ def apply_checkout_discount_on_checkout_line(calculate_base_line_total_price(line_info,checkout_info.channel,- discounts,).amountfor line_info in linesif line_info.line.id != checkout_line_info.line.id@@ -342,7 +319,7 @@ def apply_checkout_discount_on_checkout_line(last_element = lines[-1].line.id == checkout_line_info.line.idif last_element:discount_amount = _calculate_discount_for_last_element(- lines_total_prices, total_price, total_discount_amount, currency+ lines_total_prices, total_price, total_discount_amount)else:discount_amount = line_total_price.amount / total_price * total_discount_amount@@ -353,7 +330,7 @@ def apply_checkout_discount_on_checkout_line(def _calculate_discount_for_last_element(- lines_total_prices, total_price, total_discount_amount, currency+ lines_total_prices, total_price, total_discount_amount):"""Calculate the discount for last element.diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.pyindex 7fbbaa9ca1..b61222f62f 100644--- a/saleor/checkout/calculations.py+++ b/saleor/checkout/calculations.py@@ -8,7 +8,7 @@ from prices import Money, TaxedMoneyfrom ..checkout import base_calculationsfrom ..core.prices import quantize_pricefrom ..core.taxes import TaxData, zero_money, zero_taxed_money-from ..discount import DiscountInfo+from ..discount.utils import generate_sale_discount_objects_for_checkoutfrom ..payment.models import TransactionItemfrom ..tax import TaxCalculationStrategyfrom ..tax.calculations.checkout import update_checkout_prices_with_flat_rates@@ -32,7 +32,6 @@ def checkout_shipping_price(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> "TaxedMoney":"""Return checkout shipping price.@@ -44,7 +43,6 @@ def checkout_shipping_price(manager=manager,lines=lines,address=address,- discounts=discounts,)return quantize_price(checkout_info.checkout.shipping_price, currency)@@ -55,7 +53,6 @@ def checkout_shipping_tax_rate(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> Decimal:"""Return checkout shipping tax rate.@@ -66,7 +63,6 @@ def checkout_shipping_tax_rate(manager=manager,lines=lines,address=address,- discounts=discounts,)return checkout_info.checkout.shipping_tax_rate@@ -77,7 +73,6 @@ def checkout_subtotal(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> "TaxedMoney":"""Return the total cost of all the checkout lines, taxes included.@@ -89,7 +84,6 @@ def checkout_subtotal(manager=manager,lines=lines,address=address,- discounts=discounts,)return quantize_price(checkout_info.checkout.subtotal, currency)@@ -99,7 +93,6 @@ def calculate_checkout_total_with_gift_cards(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> "TaxedMoney":total = (checkout_total(@@ -107,7 +100,6 @@ def calculate_checkout_total_with_gift_cards(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)- checkout_info.checkout.get_total_gift_cards_balance())@@ -121,7 +113,6 @@ def checkout_total(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> "TaxedMoney":"""Return the total cost of the checkout.@@ -136,7 +127,6 @@ def checkout_total(manager=manager,lines=lines,address=address,- discounts=discounts,)return quantize_price(checkout_info.checkout.total, currency)@@ -162,7 +152,6 @@ def checkout_line_total(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable[DiscountInfo] = [],) -> TaxedMoney:"""Return the total price of provided line, taxes included.@@ -175,7 +164,6 @@ def checkout_line_total(manager=manager,lines=lines,address=address,- discounts=discounts,)checkout_line = _find_checkout_line_info(lines, checkout_line_info).linereturn quantize_price(checkout_line.total_price, currency)@@ -187,7 +175,6 @@ def checkout_line_unit_price(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable[DiscountInfo],) -> TaxedMoney:"""Return the unit price of provided line, taxes included.@@ -200,7 +187,6 @@ def checkout_line_unit_price(manager=manager,lines=lines,address=address,- discounts=discounts,)checkout_line = _find_checkout_line_info(lines, checkout_line_info).lineunit_price = checkout_line.total_price / checkout_line.quantity@@ -213,7 +199,6 @@ def checkout_line_tax_rate(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable[DiscountInfo],) -> Decimal:"""Return the tax rate of provided line.@@ -225,7 +210,6 @@ def checkout_line_tax_rate(manager=manager,lines=lines,address=address,- discounts=discounts,)checkout_line_info = _find_checkout_line_info(lines, checkout_line_info)return checkout_line_info.line.tax_rate@@ -236,7 +220,6 @@ def _fetch_checkout_prices_if_expired(manager: "PluginsManager",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"] = None,- discounts: Optional[Iterable["DiscountInfo"]] = None,force_update: bool = False,) -> Tuple["CheckoutInfo", Iterable["CheckoutLineInfo"]]:"""Fetch checkout prices with taxes.@@ -261,6 +244,8 @@ def _fetch_checkout_prices_if_expired(charge_taxes = get_charge_taxes_for_checkout(checkout_info, lines)should_charge_tax = charge_taxes and not checkout.tax_exemption+ generate_sale_discount_objects_for_checkout(checkout_info, lines)+if prices_entered_with_tax:# If prices are entered with tax, we need to always calculate it anyway, to# display the tax rate to the user.@@ -272,7 +257,6 @@ def _fetch_checkout_prices_if_expired(lines,prices_entered_with_tax,address,- discounts,)if not should_charge_tax:@@ -293,11 +277,11 @@ def _fetch_checkout_prices_if_expired(lines,prices_entered_with_tax,address,- discounts,)else:# Calculate net prices without taxes.- _get_checkout_base_prices(checkout, checkout_info, lines, discounts)+ _get_checkout_base_prices(checkout, checkout_info, lines)+checkout.price_expiration = timezone.now() + settings.CHECKOUT_PRICES_TTLcheckout.save(update_fields=[@@ -337,20 +321,17 @@ def _calculate_and_add_tax(lines: Iterable["CheckoutLineInfo"],prices_entered_with_tax: bool,address: Optional["Address"] = None,- discounts: Optional[Iterable["DiscountInfo"]] = None,):if tax_calculation_strategy == TaxCalculationStrategy.TAX_APP:# Call the tax plugins.- _apply_tax_data_from_plugins(- checkout, manager, checkout_info, lines, address, discounts- )+ _apply_tax_data_from_plugins(checkout, manager, checkout_info, lines, address)# Get the taxes calculated with apps and apply to checkout.tax_data = manager.get_taxes_for_checkout(checkout_info, lines)_apply_tax_data(checkout, lines, tax_data)else:# Get taxes calculated with flat rates and apply to checkout.update_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, discounts+ checkout, checkout_info, lines, prices_entered_with_tax, address)@@ -422,11 +403,7 @@ def _apply_tax_data_from_plugins(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> None:- if not discounts:- discounts = []-for line_info in lines:line = line_info.line@@ -435,7 +412,6 @@ def _apply_tax_data_from_plugins(lines,line_info,address,- discounts,)line.total_price = total_price@@ -444,7 +420,6 @@ def _apply_tax_data_from_plugins(lines,line_info,address,- discounts,)line.tax_rate = manager.get_checkout_line_tax_rate(@@ -452,33 +427,26 @@ def _apply_tax_data_from_plugins(lines,line_info,address,- discounts,unit_price,)checkout.shipping_price = manager.calculate_checkout_shipping(- checkout_info, lines, address, discounts+ checkout_info, lines, address)checkout.shipping_tax_rate = manager.get_checkout_shipping_tax_rate(- checkout_info, lines, address, discounts, checkout.shipping_price+ checkout_info, lines, address, checkout.shipping_price)checkout.subtotal = manager.calculate_checkout_subtotal(- checkout_info, lines, address, discounts- )- checkout.total = manager.calculate_checkout_total(- checkout_info, lines, address, discounts+ checkout_info, lines, address)+ checkout.total = manager.calculate_checkout_total(checkout_info, lines, address)def _get_checkout_base_prices(checkout: "Checkout",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> None:- if not discounts:- discounts = []-currency = checkout_info.checkout.currencysubtotal = zero_money(currency)@@ -487,10 +455,10 @@ def _get_checkout_base_prices(quantity = line.quantityunit_price = base_calculations.calculate_base_line_unit_price(- line_info, checkout_info.channel, discounts+ line_info, checkout_info.channel)total_price = base_calculations.apply_checkout_discount_on_checkout_line(- checkout_info, lines, line_info, discounts, unit_price * quantity+ checkout_info, lines, line_info, unit_price * quantity)line_total_price = quantize_price(total_price, currency)subtotal += line_total_price@@ -522,7 +490,6 @@ def fetch_checkout_data(manager: "PluginsManager",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"] = None,- discounts: Optional[Iterable["DiscountInfo"]] = None,force_update: bool = False,checkout_transactions: Optional[Iterable["TransactionItem"]] = None,force_status_update: bool = False,@@ -538,7 +505,6 @@ def fetch_checkout_data(manager=manager,lines=lines,address=address,- discounts=discounts,force_update=force_update,)current_total_gross = checkout_info.checkout.total.grossdiff --git a/saleor/checkout/checkout_cleaner.py b/saleor/checkout/checkout_cleaner.pyindex 15df203fb3..e8dd4ce0a6 100644--- a/saleor/checkout/checkout_cleaner.py+++ b/saleor/checkout/checkout_cleaner.py@@ -1,12 +1,11 @@from datetime import date-from typing import TYPE_CHECKING, Iterable, List, Optional, Type, Union+from typing import TYPE_CHECKING, Iterable, Optional, Type, Unionimport graphenefrom django.core.exceptions import ValidationErrorfrom ..core.exceptions import GiftCardNotApplicablefrom ..core.taxes import TaxError-from ..discount import DiscountInfofrom ..giftcard.models import GiftCardfrom ..payment import gatewayfrom ..payment import models as payment_models@@ -86,12 +85,11 @@ def clean_checkout_payment(manager: PluginsManager,checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],error_code: Type[CheckoutErrorCode],last_payment: Optional[payment_models.Payment],):clean_billing_address(checkout_info, error_code)- if not is_fully_paid(manager, checkout_info, lines, discounts):+ if not is_fully_paid(manager, checkout_info, lines):gateway.payment_refund_or_void(last_payment, manager, channel_slug=checkout_info.channel.slug)@@ -125,7 +123,6 @@ def validate_checkout(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],unavailable_variant_pks: Iterable[int],- discounts: List["DiscountInfo"],manager: "PluginsManager",):"""Validate all required data for converting checkout into order."""@@ -181,7 +178,7 @@ def validate_checkout(# call plugin's hooks to validate if we are able to create an order# can raise TaxErrortry:- manager.preprocess_order_creation(checkout_info, discounts, lines)+ manager.preprocess_order_creation(checkout_info, lines)except TaxError as tax_error:raise ValidationError(f"Unable to calculate taxes - {str(tax_error)}",diff --git a/saleor/checkout/complete_checkout.py b/saleor/checkout/complete_checkout.pyindex e186468689..d358983a3f 100644--- a/saleor/checkout/complete_checkout.py+++ b/saleor/checkout/complete_checkout.py@@ -33,11 +33,10 @@ from ..core.taxes import TaxError, zero_taxed_moneyfrom ..core.tracing import traced_atomic_transactionfrom ..core.transactions import transaction_with_commit_on_errorsfrom ..core.utils.url import validate_storefront_url-from ..discount import DiscountInfo, DiscountValueType, OrderDiscountType+from ..discount import DiscountType, DiscountValueTypefrom ..discount.models import NotApplicablefrom ..discount.utils import (add_voucher_usage_by_customer,- get_sale_id_applied_as_a_discount,increase_voucher_usage,release_voucher_usage,)@@ -185,7 +184,6 @@ def _create_line_for_order(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable[DiscountInfo],products_translation: Dict[int, Optional[str]],variants_translation: Dict[int, Optional[str]],prices_entered_with_tax: bool,@@ -214,7 +212,7 @@ def _create_line_for_order(# the price with sale and discounts applied - base price that is used for# total price calculationbase_unit_price = calculate_base_line_unit_price(- line_info=checkout_line_info, channel=checkout_info.channel, discounts=discounts+ line_info=checkout_line_info, channel=checkout_info.channel)# the unit price before applying any discount (sale or voucher)undiscounted_base_unit_price = calculate_undiscounted_base_line_unit_price(@@ -238,7 +236,6 @@ def _create_line_for_order(checkout_info=checkout_info,lines=lines,checkout_line_info=checkout_line_info,- discounts=discounts,)# unit price after applying all discounts - sales and vouchersunit_price = calculations.checkout_line_unit_price(@@ -246,31 +243,16 @@ def _create_line_for_order(checkout_info=checkout_info,lines=lines,checkout_line_info=checkout_line_info,- discounts=discounts,)tax_rate = calculations.checkout_line_tax_rate(manager=manager,checkout_info=checkout_info,lines=lines,checkout_line_info=checkout_line_info,- discounts=discounts,)- price_override = checkout_line_info.line.price_override- channel_listing = checkout_line_info.channel_listing- price = (- channel_listing.price- if price_override is None- else Money(price_override, channel_listing.currency)- )- sale_id = get_sale_id_applied_as_a_discount(- product=checkout_line_info.product,- price=price,- discounts=discounts,- collections=checkout_line_info.collections,- channel=checkout_info.channel,- variant_id=checkout_line_info.variant.id,- )+ discount = checkout_line_info.get_sale_discount()+ sale_id = discount.sale.id if discount and discount.sale else Nonevoucher_code = Noneif checkout_line_info.voucher:@@ -341,7 +323,6 @@ def _create_lines_for_order(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],prices_entered_with_tax: bool,) -> Iterable[OrderLineInfo]:"""Create a lines for the given order.@@ -396,7 +377,6 @@ def _create_lines_for_order(checkout_info,lines,checkout_line_info,- discounts,product_translations,variants_translation,prices_entered_with_tax,@@ -410,7 +390,6 @@ def _prepare_order_data(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],prices_entered_with_tax: bool,) -> dict:"""Run checks and return all the data from a given checkout to create an order.@@ -428,7 +407,6 @@ def _prepare_order_data(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)base_shipping_price = base_checkout_delivery_price(checkout_info, lines)@@ -437,14 +415,12 @@ def _prepare_order_data(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)shipping_tax_rate = calculations.checkout_shipping_tax_rate(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)order_data.update(_process_shipping_data_for_order(@@ -457,7 +433,6 @@ def _prepare_order_data(manager,checkout_info,lines,- discounts,prices_entered_with_tax,)undiscounted_total = (@@ -489,14 +464,13 @@ def _prepare_order_data(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)+ shipping_total- checkout.discount).grosstry:- manager.preprocess_order_creation(checkout_info, discounts, lines)+ manager.preprocess_order_creation(checkout_info, lines)except TaxError:release_voucher_usage(order_data.get("voucher"), order_data.get("user_email"))raise@@ -515,7 +489,7 @@ def _create_order(manager: "PluginsManager",site_settings: Optional["SiteSettings"] = None,metadata_list: Optional[List] = None,- private_metadata_list: Optional[List] = None+ private_metadata_list: Optional[List] = None,) -> Order:"""Create an order from the checkout.@@ -646,10 +620,10 @@ def _prepare_checkout(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts,tracking_code,redirect_url,):+ """Prepare checkout object to complete the checkout process."""checkout = checkout_info.checkoutclean_checkout_shipping(checkout_info, lines, CheckoutErrorCode)if not checkout_info.channel.is_active:@@ -687,7 +661,6 @@ def _prepare_checkout_with_transactions(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],tracking_code: Optional[str],redirect_url: Optional[str],):@@ -707,7 +680,6 @@ def _prepare_checkout_with_transactions(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,tracking_code=tracking_code,redirect_url=redirect_url,)@@ -717,7 +689,6 @@ def _prepare_checkout_with_payment(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],tracking_code: Optional[str],redirect_url: Optional[str],payment: Optional[Payment],@@ -727,7 +698,6 @@ def _prepare_checkout_with_payment(manager,checkout_info,lines,- discounts,CheckoutErrorCode,last_payment=payment,)@@ -735,7 +705,6 @@ def _prepare_checkout_with_payment(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,tracking_code=tracking_code,redirect_url=redirect_url,)@@ -745,7 +714,6 @@ def _get_order_data(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: List[DiscountInfo],site_settings: "SiteSettings",) -> dict:"""Prepare data that will be converted to order and its lines."""@@ -756,7 +724,6 @@ def _get_order_data(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,prices_entered_with_tax=prices_entered_with_tax,)except InsufficientStock as e:@@ -819,7 +786,6 @@ def complete_checkout_pre_payment_part(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts,user,site_settings=None,tracking_code=None,@@ -834,7 +800,7 @@ def complete_checkout_pre_payment_part(if site_settings is None:site_settings = Site.objects.get_current().settings- fetch_checkout_data(checkout_info, manager, lines, discounts=discounts)+ fetch_checkout_data(checkout_info, manager, lines)checkout = checkout_info.checkoutchannel_slug = checkout_info.channel.slug@@ -844,7 +810,6 @@ def complete_checkout_pre_payment_part(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,tracking_code=tracking_code,redirect_url=redirect_url,payment=payment,@@ -854,9 +819,7 @@ def complete_checkout_pre_payment_part(raise exctry:- order_data = _get_order_data(- manager, checkout_info, lines, discounts, site_settings- )+ order_data = _get_order_data(manager, checkout_info, lines, site_settings)except ValidationError as exc:gateway.payment_refund_or_void(payment, manager, channel_slug=channel_slug)raise exc@@ -968,7 +931,6 @@ def _increase_voucher_usage(checkout_info: "CheckoutInfo"):def _create_order_lines_from_checkout_lines(checkout_info: CheckoutInfo,lines: List[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",order_pk: Union[str, UUID],prices_entered_with_tax: bool,@@ -977,7 +939,6 @@ def _create_order_lines_from_checkout_lines(manager,checkout_info,lines,- discounts,prices_entered_with_tax,)order_lines = []@@ -1024,8 +985,9 @@ def _handle_checkout_discount(order: "Order", checkout: "Checkout"):# store voucher as a fixed value as it this the simplest solution for now.# This will be solved when we refactor the voucher logic to use .discounts# relations+order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=checkout.discount.amount,name=checkout.discount_name,@@ -1073,7 +1035,6 @@ def _post_create_order_actions(def _create_order_from_checkout(checkout_info: CheckoutInfo,checkout_lines_info: List[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",user: Optional[User],app: Optional["App"],@@ -1097,7 +1058,6 @@ def _create_order_from_checkout(checkout_info=checkout_info,lines=checkout_lines_info,address=address,- discounts=discounts,)# voucher@@ -1112,14 +1072,12 @@ def _create_order_from_checkout(checkout_info=checkout_info,lines=checkout_lines_info,address=address,- discounts=discounts,)shipping_tax_rate = calculations.checkout_shipping_tax_rate(manager=manager,checkout_info=checkout_info,lines=checkout_lines_info,address=address,- discounts=discounts,)# status@@ -1176,7 +1134,6 @@ def _create_order_from_checkout(order_lines_info = _create_order_lines_from_checkout_lines(checkout_info=checkout_info,lines=checkout_lines_info,- discounts=discounts,manager=manager,order_pk=order.pk,prices_entered_with_tax=prices_entered_with_tax,@@ -1247,7 +1204,6 @@ def _create_order_from_checkout(def create_order_from_checkout(checkout_info: CheckoutInfo,checkout_lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",user: Optional["User"],app: Optional["App"],@@ -1283,7 +1239,6 @@ def create_order_from_checkout(order = _create_order_from_checkout(checkout_info=checkout_info,checkout_lines_info=list(checkout_lines),- discounts=discounts,manager=manager,user=user,app=app,@@ -1312,7 +1267,6 @@ def complete_checkout(lines: Iterable["CheckoutLineInfo"],payment_data: Dict[Any, Any],store_source: bool,- discounts: Iterable["DiscountInfo"],user: Optional["User"],app: Optional["App"],site_settings: Optional["SiteSettings"] = None,@@ -1322,7 +1276,7 @@ def complete_checkout(private_metadata_list: Optional[List] = None,) -> Tuple[Optional[Order], bool, dict]:transactions = checkout_info.checkout.payment_transactions.all()- fetch_checkout_data(checkout_info, manager, lines, discounts=discounts)+ fetch_checkout_data(checkout_info, manager, lines)# When checkout is zero, we don't need any transaction to cover the checkout total.# We check if checkout is zero, and we also check what flow for marking an order as@@ -1338,7 +1292,6 @@ def complete_checkout(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,user=user,app=app,tracking_code=tracking_code,@@ -1354,7 +1307,6 @@ def complete_checkout(lines=lines,payment_data=payment_data,store_source=store_source,- discounts=discounts,user=user,app=app,site_settings=site_settings,@@ -1369,7 +1321,6 @@ def complete_checkout_with_transaction(manager: "PluginsManager",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],user: Optional["User"],app: Optional["App"],tracking_code: Optional[str] = None,@@ -1381,7 +1332,6 @@ def complete_checkout_with_transaction(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,tracking_code=tracking_code,redirect_url=redirect_url,)@@ -1389,7 +1339,6 @@ def complete_checkout_with_transaction(return create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=discounts,manager=manager,user=user,app=app,@@ -1406,7 +1355,6 @@ def complete_checkout_with_payment(lines: Iterable["CheckoutLineInfo"],payment_data,store_source,- discounts,user,app,site_settings=None,@@ -1435,7 +1383,6 @@ def complete_checkout_with_payment(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,user=user,site_settings=site_settings,tracking_code=tracking_code,@@ -1486,7 +1433,6 @@ def complete_checkout_with_payment(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=discounts,user=user,site_settings=site_settings,tracking_code=tracking_code,diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.pyindex e6a1742286..5f5994eca5 100644--- a/saleor/checkout/fetch.py+++ b/saleor/checkout/fetch.py@@ -14,10 +14,11 @@ from typing import ()from uuid import UUID+from prices import Money+from ..core.utils.lazyobjects import lazy_no_retry-from ..discount import DiscountInfo, VoucherType+from ..discount import DiscountType, VoucherTypefrom ..discount.interface import fetch_voucher_info-from ..discount.utils import fetch_active_discountsfrom ..shipping.interface import ShippingMethodDatafrom ..shipping.models import ShippingMethod, ShippingMethodChannelListingfrom ..shipping.utils import (@@ -31,7 +32,7 @@ if TYPE_CHECKING:from ..account.models import Address, Userfrom ..channel.models import Channelfrom ..discount.interface import VoucherInfo- from ..discount.models import Voucher+ from ..discount.models import CheckoutLineDiscount, Voucherfrom ..plugins.manager import PluginsManagerfrom ..product.models import (Collection,@@ -53,9 +54,17 @@ class CheckoutLineInfo:product: "Product"product_type: "ProductType"collections: List["Collection"]+ discounts: List["CheckoutLineDiscount"]+ channel: "Channel"tax_class: Optional["TaxClass"] = Nonevoucher: Optional["Voucher"] = None+ def get_sale_discount(self) -> Optional["CheckoutLineDiscount"]:+ for discount in self.discounts:+ if discount.type == DiscountType.SALE:+ return discount+ return None+@dataclassclass CheckoutInfo:@@ -229,6 +238,7 @@ def fetch_checkout_lines("variant__product__product_type__tax_class__country_rates","variant__product__tax_class__country_rates","variant__channel_listings__channel",+ "discounts",]if prefetch_variant_attributes:prefetch_related_fields.extend(@@ -243,12 +253,14 @@ def fetch_checkout_lines(lines_info = []unavailable_variant_pks = []product_channel_listing_mapping: Dict[int, Optional["ProductChannelListing"]] = {}+ channel = checkout.channelfor line in lines:variant = line.variantproduct = variant.productproduct_type = product.product_typecollections = list(product.collections.all())+ discounts = list(line.discounts.all())variant_channel_listing = _get_variant_channel_listing(variant, checkout.channel_id@@ -268,6 +280,8 @@ def fetch_checkout_lines(product_type=product_type,collections=collections,tax_class=product.tax_class or product_type.tax_class,+ discounts=discounts,+ channel=channel,))continue@@ -281,24 +295,22 @@ def fetch_checkout_lines(product_type=product_type,collections=collections,tax_class=product.tax_class or product_type.tax_class,+ discounts=discounts,+ channel=channel,))if checkout.voucher_code and lines_info:- channel_slug = checkout.channel.slugvoucher = get_voucher_for_checkout(- checkout, channel_slug=channel_slug, with_prefetch=True+ checkout, channel_slug=channel.slug, with_prefetch=True)if not voucher:# in case when voucher is expired, it will be null so no need to apply any# discount from voucherreturn lines_info, unavailable_variant_pksif voucher.type == VoucherType.SPECIFIC_PRODUCT or voucher.apply_once_per_order:- discounts = fetch_active_discounts()voucher_info = fetch_voucher_info(voucher)- apply_voucher_to_checkout_line(- voucher_info, checkout, lines_info, discounts- )+ apply_voucher_to_checkout_line(voucher_info, checkout, lines_info)return lines_info, unavailable_variant_pks@@ -349,7 +361,6 @@ def apply_voucher_to_checkout_line(voucher_info: "VoucherInfo",checkout: "Checkout",lines_info: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],):"""Attach voucher to valid checkout lines info.@@ -367,9 +378,7 @@ def apply_voucher_to_checkout_line()lines_included_in_discount = discounted_lines_by_voucherif voucher.apply_once_per_order:- cheapest_line = _get_the_cheapest_line(- checkout, lines_included_in_discount, discounts- )+ cheapest_line = _get_the_cheapest_line(checkout, lines_included_in_discount)if cheapest_line:discounted_lines_by_voucher = [cheapest_line]for line_info in lines_info:@@ -380,19 +389,26 @@ def apply_voucher_to_checkout_line(def _get_the_cheapest_line(checkout: "Checkout",lines_info: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],):channel = checkout.channeldef variant_price(line_info):- return line_info.variant.get_price(+ variant_price = line_info.variant.get_price(product=line_info.product,collections=line_info.collections,channel=channel,channel_listing=line_info.channel_listing,- discounts=discounts,+ discounts=[],price_override=line_info.line.price_override,)+ for discount in line_info.discounts:+ total_discount_amount_for_line = discount.amount_value+ unit_discount_amount = (+ total_discount_amount_for_line / line_info.line.quantity+ )+ unit_discount = Money(unit_discount_amount, variant_price.currency)+ variant_price -= unit_discount+ return variant_pricereturn min(lines_info, default=None, key=variant_price)@@ -400,7 +416,6 @@ def _get_the_cheapest_line(def fetch_checkout_info(checkout: "Checkout",lines: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",shipping_channel_listings: Optional[Iterable["ShippingMethodChannelListing"]@@ -437,7 +452,6 @@ def fetch_checkout_info(checkout.collection_point,shipping_address,lines,- discounts,manager,shipping_channel_listings,)@@ -504,7 +518,6 @@ def update_checkout_info_shipping_address(checkout_info: CheckoutInfo,address: Optional["Address"],lines: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",shipping_channel_listings: Iterable["ShippingMethodChannelListing"],):@@ -516,7 +529,6 @@ def update_checkout_info_shipping_address(checkout_info.checkout.collection_point,address,lines,- discounts,manager,shipping_channel_listings,)@@ -526,7 +538,6 @@ def get_valid_internal_shipping_method_list_for_checkout_info(checkout_info: "CheckoutInfo",shipping_address: Optional["Address"],lines: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],shipping_channel_listings: Iterable[ShippingMethodChannelListing],) -> List["ShippingMethodData"]:from . import base_calculations@@ -538,7 +549,6 @@ def get_valid_internal_shipping_method_list_for_checkout_info(lines,checkout_info.channel,checkout_info.checkout.currency,- discounts,)# if a voucher is applied to shipping, we don't want to subtract the discount amount@@ -571,7 +581,6 @@ def get_valid_external_shipping_method_list_for_checkout_info(checkout_info: "CheckoutInfo",shipping_address: Optional["Address"],lines: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",) -> List["ShippingMethodData"]:return manager.list_shipping_methods_for_checkout(@@ -583,7 +592,6 @@ def get_all_shipping_methods_list(checkout_info,shipping_address,lines,- discounts,shipping_channel_listings,manager,):@@ -593,11 +601,10 @@ def get_all_shipping_methods_list(checkout_info,shipping_address,lines,- discounts,shipping_channel_listings,),get_valid_external_shipping_method_list_for_checkout_info(- checkout_info, shipping_address, lines, discounts, manager+ checkout_info, shipping_address, lines, manager),))@@ -609,7 +616,6 @@ def update_delivery_method_lists_for_checkout_info(collection_point: Optional["Warehouse"],shipping_address: Optional["Address"],lines: Iterable[CheckoutLineInfo],- discounts: Iterable["DiscountInfo"],manager: "PluginsManager",shipping_channel_listings: Iterable[ShippingMethodChannelListing],):@@ -628,7 +634,6 @@ def update_delivery_method_lists_for_checkout_info(checkout_info,shipping_address,lines,- discounts,shipping_channel_listings,manager,)diff --git a/saleor/checkout/tests/conftest.py b/saleor/checkout/tests/conftest.pyindex 2a6f99169c..3cb268d8e6 100644--- a/saleor/checkout/tests/conftest.py+++ b/saleor/checkout/tests/conftest.py@@ -14,7 +14,7 @@ def priced_checkout_factory():def factory(checkout):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)tax = Decimal("1.23")@@ -24,7 +24,7 @@ def priced_checkout_factory():lines_to_update.append(line)line.total_price = manager.calculate_checkout_line_total(- checkout_info, lines, line_info, None, []+ checkout_info, lines, line_info, None)line.total_price_gross_amount *= tax@@ -37,14 +37,12 @@ def priced_checkout_factory():)checkout.shipping_price = manager.calculate_checkout_shipping(- checkout_info, lines, None, []+ checkout_info, lines, None)checkout.subtotal = manager.calculate_checkout_subtotal(- checkout_info, lines, None, []- )- checkout.total = manager.calculate_checkout_total(- checkout_info, lines, None, []+ checkout_info, lines, None)+ checkout.total = manager.calculate_checkout_total(checkout_info, lines, None)checkout.shipping_price_gross_amount *= taxcheckout.subtotal_gross_amount *= taxdiff --git a/saleor/checkout/tests/test_actions.py b/saleor/checkout/tests/test_actions.pyindex 0a64b7552d..05b69826d8 100644--- a/saleor/checkout/tests/test_actions.py+++ b/saleor/checkout/tests/test_actions.py@@ -14,18 +14,14 @@ def test_transaction_amounts_for_checkout_updated_fully_paid(# givencheckout = checkout_with_itemslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)transaction = transaction_item_generator(checkout_id=checkout.pk, charged_value=checkout_info.checkout.total.gross.amount)# when- transaction_amounts_for_checkout_updated(- transaction, discounts=[], manager=plugins_manager- )+ transaction_amounts_for_checkout_updated(transaction, manager=plugins_manager)# thenflush_post_commit_hooks()@@ -42,24 +38,20 @@ def test_transaction_amounts_for_checkout_updated_with_already_fully_paid(# givencheckout = checkout_with_itemslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)transaction_item_generator(checkout_id=checkout.pk, charged_value=checkout_info.checkout.total.gross.amount)- fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[], force_status_update=True- )+ fetch_checkout_data(checkout_info, plugins_manager, lines, force_status_update=True)second_transaction = transaction_item_generator(checkout_id=checkout.pk, charged_value=checkout_info.checkout.total.gross.amount)# whentransaction_amounts_for_checkout_updated(- second_transaction, discounts=[], manager=plugins_manager+ second_transaction, manager=plugins_manager)# thendiff --git a/saleor/checkout/tests/test_base_calculations.py b/saleor/checkout/tests/test_base_calculations.pyindex 5a49898879..168def10ec 100644--- a/saleor/checkout/tests/test_base_calculations.py+++ b/saleor/checkout/tests/test_base_calculations.py@@ -3,7 +3,10 @@ from decimal import Decimalfrom prices import Money, TaxedMoneyfrom ...discount import DiscountValueType, VoucherType-from ...discount.utils import get_product_discount_on_sale+from ...discount.utils import (+ create_or_update_discount_objects_from_sale_for_checkout,+ get_product_discount_on_sale,+)from ...plugins.manager import get_plugins_managerfrom ...tax.utils import calculate_tax_ratefrom ..base_calculations import (@@ -23,7 +26,7 @@ def test_calculate_base_line_unit_price(checkout_with_single_item):# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -50,7 +53,7 @@ def test_calculate_base_line_unit_price_with_custom_price(checkout_with_single_i# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -63,7 +66,14 @@ def test_calculate_base_line_unit_price_with_variant_on_sale(checkout_with_single_item, discount_info, category):# given+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert not checkout_line_info.vouchervariant = checkout_line_info.variant@@ -74,7 +84,7 @@ def test_calculate_base_line_unit_price_with_variant_on_sale(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -107,7 +117,14 @@ def test_calculate_base_line_unit_price_with_variant_on_sale_custom_price(line.price_override = price_overrideline.save(update_fields=["price_override"])+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert not checkout_line_info.vouchervariant = checkout_line_info.variant@@ -118,7 +135,7 @@ def test_calculate_base_line_unit_price_with_variant_on_sale_custom_price(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -160,7 +177,7 @@ def test_calculate_base_line_unit_price_with_fixed_voucher(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -199,7 +216,7 @@ def test_calculate_base_line_unit_price_with_fixed_voucher_custom_prices(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -232,7 +249,7 @@ def test_calculate_base_line_unit_price_with_percentage_voucher(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -273,7 +290,7 @@ def test_calculate_base_line_unit_price_with_percentage_voucher_custom_prices(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -310,7 +327,7 @@ def test_calculate_base_line_unit_price_with_discounts_apply_once_per_order(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -352,7 +369,7 @@ def test_calculate_base_line_unit_price_with_discounts_once_per_order_custom_pri# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -375,7 +392,14 @@ def test_calculate_base_line_unit_price_with_variant_on_sale_and_voucher(voucher_channel_listing.discount = voucher_amountvoucher_channel_listing.save()checkout_with_single_item.voucher_code = voucher.code+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert checkout_line_info.vouchervariant = checkout_line_info.variant@@ -387,7 +411,7 @@ def test_calculate_base_line_unit_price_with_variant_on_sale_and_voucher(# whenunit_price = calculate_base_line_unit_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -426,7 +450,7 @@ def test_calculate_base_line_total_price(checkout_with_single_item):# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -449,7 +473,14 @@ def test_calculate_base_line_total_price_with_variant_on_sale(checkout_line.quantity = quantitycheckout_line.save()+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert not checkout_line_info.vouchervariant = checkout_line_info.variant@@ -460,7 +491,7 @@ def test_calculate_base_line_total_price_with_variant_on_sale(# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -485,6 +516,58 @@ def test_calculate_base_line_total_price_with_variant_on_sale(assert total_price == expected_price * quantity+def test_calculate_base_line_total_price_with_1_cent_variant_on_10_percentage_sale(+ checkout_with_single_item, discount_info, category+):+ # given+ quantity = 10+ checkout_line = checkout_with_single_item.lines.first()+ checkout_line.quantity = quantity+ checkout_line.save()++ # Create 10% sale+ sale = discount_info.sale+ sale.type = DiscountValueType.PERCENTAGE+ sale.save()+ sale_channel_listing = sale.channel_listings.get()+ sale_channel_listing.discount_value = Decimal(10)+ sale_channel_listing.save()++ # Set product price to 0.01 USD+ variant = checkout_line.variant+ variant_channel_listing = variant.channel_listings.get()+ variant_channel_listing.price_amount = Decimal("0.01")+ variant_channel_listing.save()++ manager = get_plugins_manager()+ checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )+ checkout_line_info = checkout_lines_info[0]+ assert not checkout_line_info.voucher+ variant = checkout_line_info.variant+ # set category on sale+ variant.product.category = category+ variant.product.save()+ checkout_line_info.product = variant.product++ # when+ total_price = calculate_base_line_total_price(+ checkout_line_info, checkout_with_single_item.channel+ )++ # then+ sale_channel_listing.refresh_from_db()+ variant_channel_listing.refresh_from_db()+ assert sale_channel_listing.discount_value == Decimal(10)+ assert variant_channel_listing.price_amount == Decimal("0.01")+ assert total_price == Money(Decimal("0.09"), checkout_line.currency)++def test_calculate_base_line_total_price_with_fixed_voucher(checkout_with_single_item, voucher, channel_USD):@@ -513,7 +596,7 @@ def test_calculate_base_line_total_price_with_fixed_voucher(# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -556,7 +639,7 @@ def test_calculate_base_line_total_price_with_percentage_voucher(# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -601,7 +684,7 @@ def test_calculate_base_line_total_price_with_discounts_apply_once_per_order(# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -638,7 +721,14 @@ def test_calculate_base_line_total_price_with_variant_on_sale_and_voucher(voucher_channel_listing.save()checkout_with_single_item.voucher_code = voucher.code+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert checkout_line_info.vouchervariant = checkout_line_info.variant@@ -650,7 +740,7 @@ def test_calculate_base_line_total_price_with_variant_on_sale_and_voucher(# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -697,7 +787,14 @@ def test_calculate_base_line_total_price_with_variant_on_sale_and_voucher_applievoucher_channel_listing.save()checkout_with_single_item.voucher_code = voucher.code+ manager = get_plugins_manager()checkout_lines_info, _ = fetch_checkout_lines(checkout_with_single_item)+ checkout_info = fetch_checkout_info(+ checkout_with_single_item, checkout_lines_info, manager+ )+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )checkout_line_info = checkout_lines_info[0]assert checkout_line_info.vouchervariant = checkout_line_info.variant@@ -709,7 +806,7 @@ def test_calculate_base_line_total_price_with_variant_on_sale_and_voucher_applie# whentotal_price = calculate_base_line_total_price(- checkout_line_info, checkout_with_single_item.channel, discounts=[discount_info]+ checkout_line_info, checkout_with_single_item.channel)# then@@ -759,10 +856,10 @@ def test_base_checkout_total(checkout_with_item, shipping_method, voucher_percencheckout_with_item.save()checkout_lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)# when- total = base_checkout_total(checkout_info, [], checkout_lines)+ total = base_checkout_total(checkout_info, checkout_lines)# thenvariant = checkout_with_item.lines.first().variant@@ -802,10 +899,10 @@ def test_base_checkout_total_high_discount_on_entire_order_apply_once_per_order().pricecheckout_lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)# when- total = base_checkout_total(checkout_info, [], checkout_lines)+ total = base_checkout_total(checkout_info, checkout_lines)# thenassert total == shipping_price@@ -827,10 +924,10 @@ def test_base_checkout_total_high_discount_on_shipping(checkout_with_item.save()checkout_lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)# when- total = base_checkout_total(checkout_info, [], checkout_lines)+ total = base_checkout_total(checkout_info, checkout_lines)# thenvariant = checkout_with_item.lines.first().variantdiff --git a/saleor/checkout/tests/test_calculations.py b/saleor/checkout/tests/test_calculations.pyindex f132c75671..4f03609f64 100644--- a/saleor/checkout/tests/test_calculations.py+++ b/saleor/checkout/tests/test_calculations.py@@ -87,16 +87,14 @@ def test_apply_tax_data(checkout_with_items, checkout_lines, tax_data):@pytest.fixturedef fetch_kwargs(checkout_with_items, plugins_manager):lines, _ = fetch_checkout_lines(checkout_with_items)- discounts = []return {"checkout_info": fetch_checkout_info(- checkout_with_items, lines, discounts, plugins_manager+ checkout_with_items, lines, plugins_manager),"manager": plugins_manager,"lines": lines,"address": checkout_with_items.shipping_addressor checkout_with_items.billing_address,- "discounts": discounts,}@@ -297,21 +295,20 @@ def test_get_checkout_base_prices_no_charge_taxes_with_voucher()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)add_promo_code_to_checkout(manager,checkout_info,lines,voucher_percentage.code,- [],)checkout.refresh_from_db()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# when- _get_checkout_base_prices(checkout, checkout_info, lines, [])+ _get_checkout_base_prices(checkout, checkout_info, lines)checkout.save()checkout.lines.bulk_update([line_info.line for line_info in lines],@@ -395,15 +392,13 @@ def test_fetch_checkout_prices_when_tax_exemption_and_include_taxes_in_prices(currency = checkout.currency- discounts = []lines_info, _ = fetch_checkout_lines(checkout)fetch_kwargs = {- "checkout_info": fetch_checkout_info(checkout, lines_info, discounts, manager),+ "checkout_info": fetch_checkout_info(checkout, lines_info, manager),"manager": manager,"lines": lines_info,"address": checkout.shipping_address or checkout.billing_address,- "discounts": discounts,}# when@@ -455,15 +450,13 @@ def test_fetch_checkout_prices_when_tax_exemption_and_not_include_taxes_in_pricecurrency = checkout.currency- discounts = []lines_info, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines_info, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines_info, manager)fetch_kwargs = {"checkout_info": checkout_info,"manager": manager,"lines": lines_info,"address": checkout.shipping_address or checkout.billing_address,- "discounts": discounts,}# when@@ -472,7 +465,7 @@ def test_fetch_checkout_prices_when_tax_exemption_and_not_include_taxes_in_price# thenone_line_total_prices = [- calculate_base_line_total_price(line_info, checkout_info.channel, discounts)+ calculate_base_line_total_price(line_info, checkout_info.channel)for line_info in lines_info]all_lines_total_price = sum(one_line_total_prices, zero_taxed_money(currency))diff --git a/saleor/checkout/tests/test_cart.py b/saleor/checkout/tests/test_cart.pyindex 3eb580b175..931e35d954 100644--- a/saleor/checkout/tests/test_cart.py+++ b/saleor/checkout/tests/test_cart.py@@ -28,14 +28,14 @@ def test_get_user_checkout(def test_adding_zero_quantity(checkout, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 0)assert checkout.lines.count() == 0def test_adding_same_variant(checkout, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)add_variant_to_checkout(checkout_info, variant, 2)lines, _ = fetch_checkout_lines(checkout)@@ -44,7 +44,7 @@ def test_adding_same_variant(checkout, product):assert checkout_quantity == 3subtotal = TaxedMoney(Money("30.00", "USD"), Money("30.00", "USD"))manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)manager = get_plugins_manager()assert (calculations.checkout_subtotal(@@ -59,7 +59,7 @@ def test_adding_same_variant(checkout, product):def test_replacing_same_variant(checkout, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1, replace=True)add_variant_to_checkout(checkout_info, variant, 2, replace=True)lines, _ = fetch_checkout_lines(checkout)@@ -69,7 +69,7 @@ def test_replacing_same_variant(checkout, product):def test_adding_invalid_quantity(checkout, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())with pytest.raises(ValueError):add_variant_to_checkout(checkout_info, variant, -1)@@ -77,7 +77,7 @@ def test_adding_invalid_quantity(checkout, product):def test_getting_line(checkout, product):variant = product.variants.get()assert checkout.get_line(variant) is None- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant)assert checkout.lines.get() == checkout.get_line(variant)@@ -85,7 +85,7 @@ def test_getting_line(checkout, product):def test_shipping_detection(checkout, product):assert not checkout.is_shipping_required()variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, replace=True)assert checkout.is_shipping_required()@@ -110,7 +110,7 @@ def test_get_prices_of_discounted_specific_product(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)prices = utils.get_prices_of_discounted_specific_product(manager, checkout_info, lines, voucher)@@ -139,7 +139,7 @@ def test_get_prices_of_discounted_specific_product_only_product(variant_channel_listing = line.variant.channel_listings.get(channel=channel)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, product2.variants.get(), 1)voucher.products.add(product)# assume that cache is correct@@ -175,7 +175,7 @@ def test_get_prices_of_discounted_specific_product_only_collection(variant_channel_listing = line.variant.channel_listings.get(channel=channel)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, product2.variants.get(), 1)product.collections.add(collection)voucher.collections.add(collection)@@ -217,7 +217,7 @@ def test_get_prices_of_discounted_specific_product_only_category(product2.category = category2product2.save()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, product2.variants.get(), 1)voucher.categories.add(category)# assume that cache is correct@@ -251,7 +251,7 @@ def test_get_prices_of_discounted_specific_product_all_products(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)prices = utils.get_prices_of_discounted_specific_product(manager, checkout_info, lines, voucher)diff --git a/saleor/checkout/tests/test_checkout.py b/saleor/checkout/tests/test_checkout.pyindex 6716c43b0b..aeaed4050e 100644--- a/saleor/checkout/tests/test_checkout.py+++ b/saleor/checkout/tests/test_checkout.py@@ -14,6 +14,7 @@ from ...account.models import Addressfrom ...core.taxes import zero_moneyfrom ...discount import DiscountValueType, VoucherTypefrom ...discount.models import NotApplicable, Voucher, VoucherChannelListing+from ...discount.utils import generate_sale_discount_objects_for_checkoutfrom ...payment.models import Paymentfrom ...plugins.manager import get_plugins_managerfrom ...shipping.interface import ShippingMethodData@@ -54,14 +55,14 @@ def test_is_valid_delivery_method(checkout_with_item, address, shipping_zone):checkout.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_info# no shipping method assignedassert not delivery_method_info.is_valid_delivery_method()shipping_method = shipping_zone.shipping_methods.first()checkout.shipping_method = shipping_methodcheckout.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert delivery_method_info.is_valid_delivery_method()@@ -69,7 +70,7 @@ def test_is_valid_delivery_method(checkout_with_item, address, shipping_zone):zone = ShippingZone.objects.create(name="DE", countries=["DE"])shipping_method.shipping_zone = zoneshipping_method.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert not delivery_method_info.is_method_in_valid_methods(checkout_info)@@ -106,7 +107,7 @@ def test_is_valid_delivery_method_external_method(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert delivery_method_info.is_method_in_valid_methods(checkout_info)@@ -146,7 +147,7 @@ def test_is_valid_delivery_method_external_method_shipping_app_id_with_identifiemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert delivery_method_info.is_method_in_valid_methods(checkout_info)@@ -186,7 +187,7 @@ def test_is_valid_delivery_method_external_method_old_shipping_app_id(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert delivery_method_info.is_method_in_valid_methods(checkout_info)@@ -219,7 +220,7 @@ def test_is_valid_delivery_method_external_method_no_longer_available(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert delivery_method_info.is_method_in_valid_methods(checkout_info) is False@@ -229,7 +230,7 @@ def test_clear_delivery_method(checkout, shipping_method):checkout.shipping_method = shipping_methodcheckout.save()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)clear_delivery_method(checkout_info)checkout.refresh_from_db()assert not checkout.shipping_method@@ -320,7 +321,9 @@ def test_get_discount_for_checkout_value_entire_order_voucher(collections=[],product=line.variant.product,variant=line.variant,+ discounts=list(line.discounts.all()),product_type=line.variant.product.product_type,+ channel=channel_USD,)for line in checkout_with_items.lines.all()]@@ -328,7 +331,11 @@ def test_get_discount_for_checkout_value_entire_order_voucher(# whendiscount = get_voucher_discount_for_checkout(- manager, voucher, checkout_info, lines, None, []+ manager,+ voucher,+ checkout_info,+ lines,+ None,)# then@@ -468,6 +475,8 @@ def test_get_discount_for_checkout_value_specific_product_voucher(line=line,channel_listing=line.variant.channel_listings.first(),collections=[],+ channel=channel_USD,+ discounts=list(line.discounts.all()),product=line.variant.product,variant=line.variant,product_type=line.variant.product.product_type,@@ -478,7 +487,11 @@ def test_get_discount_for_checkout_value_specific_product_voucher(# whendiscount = get_voucher_discount_for_checkout(- manager, voucher, checkout_info, lines, None, []+ manager,+ voucher,+ checkout_info,+ lines,+ None,)# then@@ -493,7 +506,7 @@ def test_get_voucher_discount_for_checkout_voucher_validation(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_voucher)quantity = calculate_checkout_quantity(lines)- checkout_info = fetch_checkout_info(checkout_with_voucher, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_voucher, lines, manager)manager = get_plugins_manager()address = checkout_with_voucher.shipping_address@@ -502,7 +515,7 @@ def test_get_voucher_discount_for_checkout_voucher_validation(# thensubtotal = base_calculations.base_checkout_subtotal(- lines, checkout_info.channel, checkout_with_voucher.currency, []+ lines, checkout_info.channel, checkout_with_voucher.currency)customer_email = checkout_with_voucher.get_customer_email()mock_validate_voucher.assert_called_once_with(@@ -567,7 +580,7 @@ def test_get_discount_for_checkout_entire_order_voucher_not_applicable()manager = get_plugins_manager()with pytest.raises(NotApplicable):- get_voucher_discount_for_checkout(manager, voucher, checkout_info, [], None, [])+ get_voucher_discount_for_checkout(manager, voucher, checkout_info, [], None)@pytest.mark.parametrize(@@ -605,16 +618,16 @@ def test_get_discount_for_checkout_specific_products_voucher(# whenlines, _ = fetch_checkout_lines(priced_checkout_with_items)- checkout_info = fetch_checkout_info(priced_checkout_with_items, lines, [], manager)+ checkout_info = fetch_checkout_info(priced_checkout_with_items, lines, manager)subtotal = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address).gross# thenfor line in lines:line.voucher = Nonesubtotal_without_voucher = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)currency = checkout_info.checkout.currency@@ -660,9 +673,9 @@ def test_get_discount_for_checkout_specific_products_voucher_apply_only_once(# whenlines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)subtotal = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address).gross# then@@ -671,7 +684,7 @@ def test_get_discount_for_checkout_specific_products_voucher_apply_only_once(for line in lines:line.voucher = Nonesubtotal_without_voucher = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)assert subtotal == subtotal_without_voucher.gross - Money(@@ -700,10 +713,9 @@ def test_get_discount_for_checkout_specific_products_voucher_not_applicable(min_checkout_items_quantity,channel_USD,):- discounts = []monkeypatch.setattr("saleor.checkout.utils.get_prices_of_discounted_specific_product",- lambda checkout, discounts, product: [],+ lambda checkout, product: [],)monkeypatch.setattr("saleor.checkout.calculations.checkout_shipping_price",@@ -740,9 +752,7 @@ def test_get_discount_for_checkout_specific_products_voucher_not_applicable(all_shipping_methods=[],)with pytest.raises(NotApplicable):- get_voucher_discount_for_checkout(- manager, voucher, checkout_info, [], None, discounts- )+ get_voucher_discount_for_checkout(manager, voucher, checkout_info, [], None)@pytest.mark.parametrize(@@ -852,7 +862,7 @@ def test_get_discount_for_checkout_shipping_voucher()discount = get_voucher_discount_for_checkout(- manager, voucher, checkout_info, [], None, None+ manager, voucher, checkout_info, [], None)assert discount == Money(expected_value, "USD")@@ -903,7 +913,7 @@ def test_get_discount_for_checkout_shipping_voucher_all_countries(all_shipping_methods=[],)discount = get_voucher_discount_for_checkout(- manager, voucher, checkout_info, [], None, None+ manager, voucher, checkout_info, [], None)assert discount == Money(5, "USD")@@ -950,7 +960,13 @@ def test_get_discount_for_checkout_shipping_voucher_limited_countries()manager = get_plugins_manager()with pytest.raises(NotApplicable):- get_voucher_discount_for_checkout(manager, voucher, checkout_info, [], None, [])+ get_voucher_discount_for_checkout(+ manager,+ voucher,+ checkout_info,+ [],+ None,+ )@pytest.mark.parametrize(@@ -1095,14 +1111,13 @@ def test_get_discount_for_checkout_shipping_voucher_not_applicable(checkout_info,[],checkout.shipping_address,- None,)assert str(e.value) == error_msgdef test_get_voucher_for_checkout_info(checkout_with_voucher, voucher):manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout_with_voucher, [], [], manager)+ checkout_info = fetch_checkout_info(checkout_with_voucher, [], manager)checkout_voucher = get_voucher_for_checkout_info(checkout_info)assert checkout_voucher == voucher@@ -1112,14 +1127,14 @@ def test_get_voucher_for_checkout_info_expired_voucher(checkout_with_voucher, vovoucher.end_date = date_yesterdayvoucher.save()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout_with_voucher, [], [], manager)+ checkout_info = fetch_checkout_info(checkout_with_voucher, [], manager)checkout_voucher = get_voucher_for_checkout_info(checkout_info)assert checkout_voucher is Nonedef test_get_voucher_for_checkout_info_no_voucher_code(checkout):manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)checkout_voucher = get_voucher_for_checkout_info(checkout_info)assert checkout_voucher is None@@ -1152,9 +1167,9 @@ def test_recalculate_checkout_discount(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_voucher)- checkout_info = fetch_checkout_info(checkout_with_voucher, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_voucher, lines, manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ recalculate_checkout_discount(manager, checkout_info, lines)assert (checkout_with_voucher.translated_discount_name == voucher_translation_fr.name) # noqa@@ -1167,10 +1182,10 @@ def test_recalculate_checkout_discount_percentage(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(priced_checkout_with_voucher_percentage)checkout_info = fetch_checkout_info(- priced_checkout_with_voucher_percentage, lines, [], manager+ priced_checkout_with_voucher_percentage, lines, manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ recalculate_checkout_discount(manager, checkout_info, lines)assert priced_checkout_with_voucher_percentage.discount == Money(Decimal("3.00"), "USD")@@ -1178,14 +1193,17 @@ def test_recalculate_checkout_discount_percentage(def test_recalculate_checkout_discount_with_sale(checkout_with_voucher_percentage,- discount_info,+ sale,):checkout = checkout_with_voucher_percentagemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)- recalculate_checkout_discount(manager, checkout_info, lines, [discount_info])+ # To properly apply a sale at checkout, we need to generate discount objects.+ generate_sale_discount_objects_for_checkout(checkout_info, lines)++ recalculate_checkout_discount(manager, checkout_info, lines)assert checkout.discount == Money("1.50", "USD")checkout.price_expiration = timezone.now()@@ -1195,7 +1213,6 @@ def test_recalculate_checkout_discount_with_sale(checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],).gross == Money("13.50", "USD")@@ -1207,8 +1224,8 @@ def test_recalculate_checkout_discount_voucher_not_applicable(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ recalculate_checkout_discount(manager, checkout_info, lines)assert not checkout.voucher_codeassert not checkout.discount_name@@ -1223,8 +1240,8 @@ def test_recalculate_checkout_discount_expired_voucher(checkout_with_voucher, vomanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ recalculate_checkout_discount(manager, checkout_info, lines)assert not checkout.voucher_codeassert not checkout.discount_name@@ -1239,7 +1256,7 @@ def test_recalculate_checkout_discount_free_shipping_subtotal_less_than_shippingcheckout = checkout_with_voucher_free_shippingmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)channel_listing = shipping_method.channel_listings.get(channel_id=channel_USD.id)channel_listing.price = calculations.checkout_subtotal(manager=manager,@@ -1249,8 +1266,8 @@ def test_recalculate_checkout_discount_free_shipping_subtotal_less_than_shipping).gross + Money("10.00", "USD")channel_listing.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ recalculate_checkout_discount(manager, checkout_info, lines)assert checkout.discount == channel_listing.priceassert checkout.discount_name == "Free shipping"@@ -1277,7 +1294,7 @@ def test_recalculate_checkout_discount_free_shipping_subtotal_bigger_than_shippicheckout = checkout_with_voucher_free_shippingmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)channel_listing = shipping_method.channel_listings.get(channel=channel_USD)channel_listing.price = calculations.checkout_subtotal(manager=manager,@@ -1287,8 +1304,8 @@ def test_recalculate_checkout_discount_free_shipping_subtotal_bigger_than_shippi).gross - Money("1.00", "USD")channel_listing.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ recalculate_checkout_discount(manager, checkout_info, lines)assert checkout.discount == channel_listing.priceassert checkout.discount_name == "Free shipping"@@ -1313,8 +1330,8 @@ def test_recalculate_checkout_discount_free_shipping_for_checkout_without_shippicheckout = checkout_with_voucher_percentagemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- recalculate_checkout_discount(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ recalculate_checkout_discount(manager, checkout_info, lines)assert not checkout.discount_nameassert not checkout.voucher_code@@ -1324,13 +1341,12 @@ def test_recalculate_checkout_discount_free_shipping_for_checkout_without_shippidef test_change_address_in_checkout(checkout, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,address,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)@@ -1350,12 +1366,11 @@ def test_change_address_in_checkout_to_none(checkout, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,None,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)@@ -1377,12 +1392,11 @@ def test_change_address_in_checkout_to_same(checkout, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,address,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)@@ -1404,12 +1418,11 @@ def test_change_address_in_checkout_to_other(checkout, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,other_address,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)@@ -1435,12 +1448,11 @@ def test_change_address_in_checkout_from_user_address_to_other(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_updated_fields = change_shipping_address_in_checkout(checkout_info,other_address,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)@@ -1458,7 +1470,7 @@ def test_add_voucher_to_checkout(checkout_with_item, voucher):assert checkout_with_item.voucher_code is Nonemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)assert checkout_with_item.voucher_code == voucher.code@@ -1470,7 +1482,7 @@ def test_add_staff_voucher_to_anonymous_checkout(checkout_with_item, voucher):assert checkout_with_item.voucher_code is Nonemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)with pytest.raises(NotApplicable):add_voucher_to_checkout(manager, checkout_info, lines, voucher)@@ -1486,7 +1498,7 @@ def test_add_staff_voucher_to_customer_checkout(assert checkout_with_item.voucher_code is Nonemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)with pytest.raises(NotApplicable):add_voucher_to_checkout(manager, checkout_info, lines, voucher)@@ -1500,7 +1512,7 @@ def test_add_staff_voucher_to_staff_checkout(checkout_with_item, voucher, staff_assert checkout_with_item.voucher_code is Nonemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)@@ -1510,14 +1522,13 @@ def test_add_voucher_to_checkout_fail():manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)with pytest.raises(NotApplicable):add_voucher_to_checkout(manager,checkout_info,lines,voucher_with_high_min_spent_amount,- False,)assert checkout_with_item.voucher_code is None@@ -1542,7 +1553,7 @@ def test_is_fully_paid(checkout_with_item, payment_dummy):checkout = checkout_with_itemmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -1556,7 +1567,7 @@ def test_is_fully_paid(checkout_with_item, payment_dummy):payment.currency = total.gross.currencypayment.checkout = checkoutpayment.save()- is_paid = is_fully_paid(manager, checkout_info, lines, None)+ is_paid = is_fully_paid(manager, checkout_info, lines)assert is_paid@@ -1564,7 +1575,7 @@ def test_is_fully_paid_mg_payments(checkout_with_item, payment_dummy):checkout = checkout_with_itemmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -1586,7 +1597,7 @@ def test_is_fully_paid_mg_payments(checkout_with_item, payment_dummy):payment2.currency = total.gross.currencypayment2.checkout = checkoutpayment2.save()- is_paid = is_fully_paid(manager, checkout_info, lines, None)+ is_paid = is_fully_paid(manager, checkout_info, lines)assert is_paid@@ -1594,7 +1605,7 @@ def test_is_fully_paid_partially_paid(checkout_with_item, payment_dummy):checkout = checkout_with_itemmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -1608,7 +1619,7 @@ def test_is_fully_paid_partially_paid(checkout_with_item, payment_dummy):payment.currency = total.gross.currencypayment.checkout = checkoutpayment.save()- is_paid = is_fully_paid(manager, checkout_info, lines, None)+ is_paid = is_fully_paid(manager, checkout_info, lines)assert not is_paid@@ -1616,8 +1627,8 @@ def test_is_fully_paid_no_payment(checkout_with_item):checkout = checkout_with_itemmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- is_paid = is_fully_paid(manager, checkout_info, lines, None)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ is_paid = is_fully_paid(manager, checkout_info, lines)assert not is_paid@@ -1640,7 +1651,7 @@ def test_checkout_without_delivery_method_creates_empty_delivery_method(checkout = checkout_with_itemmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method_info = checkout_info.delivery_method_infoassert isinstance(delivery_method_info, DeliveryMethodBase)diff --git a/saleor/checkout/tests/test_checkout_complete.py b/saleor/checkout/tests/test_checkout_complete.pyindex e1352b8b7e..10a3acdd9e 100644--- a/saleor/checkout/tests/test_checkout_complete.py+++ b/saleor/checkout/tests/test_checkout_complete.py@@ -68,7 +68,7 @@ def test_create_order_captured_payment_creates_expected_events(# Place checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -76,7 +76,6 @@ def test_create_order_captured_payment_creates_expected_events(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=customer_user,@@ -217,7 +216,7 @@ def test_create_order_captured_payment_creates_expected_events_anonymous_user(# Place checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -225,7 +224,6 @@ def test_create_order_captured_payment_creates_expected_events_anonymous_user(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=None,@@ -361,7 +359,7 @@ def test_create_order_preauth_payment_creates_expected_events(# Place checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -369,7 +367,6 @@ def test_create_order_preauth_payment_creates_expected_events(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=customer_user,@@ -474,7 +471,7 @@ def test_create_order_preauth_payment_creates_expected_events_anonymous_user(# Place checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -482,7 +479,6 @@ def test_create_order_preauth_payment_creates_expected_events_anonymous_user(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=None,@@ -555,7 +551,7 @@ def test_create_order_insufficient_stock():variant = product_without_shipping.variants.get()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, 10, check_quantity=False)checkout.user = customer_user@@ -570,7 +566,6 @@ def test_create_order_insufficient_stock(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,)@@ -589,12 +584,11 @@ def test_create_order_doesnt_duplicate_order(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order_data = _prepare_order_data(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,)@@ -635,7 +629,7 @@ def test_create_order_with_gift_card(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -661,7 +655,6 @@ def test_create_order_with_gift_card(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user if not is_anonymous_user else None,@@ -692,7 +685,7 @@ def test_create_order_with_gift_card_partial_use(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)price_without_gift_card = calculations.checkout_total(manager=manager,@@ -712,7 +705,6 @@ def test_create_order_with_gift_card_partial_use(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=customer_user,@@ -752,7 +744,7 @@ def test_create_order_with_many_gift_cards(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)price_without_gift_card = calculations.checkout_total(manager=manager,@@ -776,7 +768,6 @@ def test_create_order_with_many_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=customer_user,@@ -827,7 +818,7 @@ def test_create_order_gift_card_bought(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)amount = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, customer_user.default_billing_address@@ -867,7 +858,6 @@ def test_create_order_gift_card_bought(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user if not is_anonymous_user else None,@@ -924,7 +914,7 @@ def test_create_order_gift_card_bought_order_not_captured_gift_cards_not_sent(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -948,7 +938,6 @@ def test_create_order_gift_card_bought_order_not_captured_gift_cards_not_sent(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user if not is_anonymous_user else None,@@ -975,7 +964,7 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(is_anonymous_user,):checkout_user = None if is_anonymous_user else customer_user- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())shippable_variant = shippable_gift_card_product.variants.get()add_variant_to_checkout(checkout_info, shippable_variant, 2)@@ -989,7 +978,7 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -1012,7 +1001,6 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user if not is_anonymous_user else None,@@ -1050,7 +1038,7 @@ def test_create_order_gift_card_bought_do_not_fulfill_gift_cards_automatically(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -1073,7 +1061,6 @@ def test_create_order_gift_card_bought_do_not_fulfill_gift_cards_automatically(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user if not is_anonymous_user else None,@@ -1093,7 +1080,7 @@ def test_note_in_created_order(checkout_with_item, address, customer_user):checkout_with_item.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)order = _create_order(checkout_info=checkout_info,checkout_lines=lines,@@ -1101,7 +1088,6 @@ def test_note_in_created_order(checkout_with_item, address, customer_user):manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,),user=customer_user,@@ -1122,7 +1108,7 @@ def test_create_order_with_variant_tracking_false(checkout.redirect_url = "https://www.example.com"checkout.save()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, 10, check_quantity=False)lines, _ = fetch_checkout_lines(checkout)@@ -1130,7 +1116,6 @@ def test_create_order_with_variant_tracking_false(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,)@@ -1164,7 +1149,7 @@ def test_create_order_use_translations(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)variant = lines[0].variantproduct = lines[0].product@@ -1184,7 +1169,6 @@ def test_create_order_use_translations(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,)order_line = order_data["lines"][0].line@@ -1212,7 +1196,7 @@ def test_complete_checkout_0_total_with_transaction_for_mark_as_paid(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder, _, _ = complete_checkout(@@ -1221,7 +1205,6 @@ def test_complete_checkout_0_total_with_transaction_for_mark_as_paid(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=app,)@@ -1263,14 +1246,13 @@ def test_complete_checkout_0_total_captured_payment_creates_expected_events(# Place checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order, action_required, action_data = complete_checkout(checkout_info=checkout_info,manager=manager,lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=app,)@@ -1382,7 +1364,7 @@ def test_complete_checkout_action_required_voucher_once_per_customer(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder, action_required, _ = complete_checkout(@@ -1391,7 +1373,6 @@ def test_complete_checkout_action_required_voucher_once_per_customer(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=app,)@@ -1437,7 +1418,7 @@ def test_complete_checkout_order_not_created_when_the_refund_is_ongoing(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder, _, _ = complete_checkout(@@ -1446,7 +1427,6 @@ def test_complete_checkout_order_not_created_when_the_refund_is_ongoing(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,)@@ -1489,7 +1469,7 @@ def test_complete_checkout_when_checkout_doesnt_exists(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)order.checkout_token = checkout.tokenorder.save()@@ -1502,7 +1482,6 @@ def test_complete_checkout_when_checkout_doesnt_exists(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,)@@ -1543,7 +1522,7 @@ def test_complete_checkout_checkout_was_deleted_before_compliting(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whendef convert_checkout_to_order(*args, **kwargs):@@ -1560,7 +1539,6 @@ def test_complete_checkout_checkout_was_deleted_before_compliting(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=app,)@@ -1586,7 +1564,7 @@ def test_process_shipping_data_for_order_store_customer_shipping_address(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_price = zero_taxed_money(checkout.currency)base_shipping_price = zero_money(checkout.currency)@@ -1621,7 +1599,7 @@ def test_process_shipping_data_for_order_dont_store_customer_click_and_collect_amanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_price = zero_taxed_money(checkout.currency)base_shipping_price = zero_money(checkout.currency)@@ -1648,13 +1626,12 @@ def test_create_order_update_display_gross_prices(checkout_with_item, customer_utax_configuration.country_exceptions.all().delete()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)lines, _ = fetch_checkout_lines(checkout)order_data = _prepare_order_data(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=[],prices_entered_with_tax=True,)@@ -1696,7 +1673,7 @@ def test_create_order_store_shipping_prices()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder = _create_order(@@ -1706,7 +1683,6 @@ def test_create_order_store_shipping_prices(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user,@@ -1718,11 +1694,11 @@ def test_create_order_store_shipping_prices(assert order.base_shipping_price == expected_base_shipping_priceassert order.shipping_price == expected_shipping_pricemanager.calculate_checkout_shipping.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, []+ checkout_info, lines, checkout.shipping_address)assert order.shipping_tax_rate == expected_shipping_tax_ratemanager.get_checkout_shipping_tax_rate.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, [], expected_shipping_price+ checkout_info, lines, checkout.shipping_address, expected_shipping_price)@@ -1747,7 +1723,7 @@ def test_create_order_store_shipping_prices_with_free_shipping_voucher()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder = _create_order(@@ -1757,7 +1733,6 @@ def test_create_order_store_shipping_prices_with_free_shipping_voucher(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,prices_entered_with_tax=True,),user=customer_user,@@ -1769,11 +1744,11 @@ def test_create_order_store_shipping_prices_with_free_shipping_voucher(assert order.base_shipping_price == expected_base_shipping_priceassert order.shipping_price == expected_shipping_pricemanager.calculate_checkout_shipping.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, []+ checkout_info, lines, checkout.shipping_address)assert order.shipping_tax_rate == expected_shipping_tax_ratemanager.get_checkout_shipping_tax_rate.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, [], expected_shipping_price+ checkout_info, lines, checkout.shipping_address, expected_shipping_price)@@ -1813,7 +1788,7 @@ def test_complete_checkout_invalid_shipping_method(voucher.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenwith pytest.raises(ValidationError):@@ -1823,7 +1798,6 @@ def test_complete_checkout_invalid_shipping_method(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=app,)@@ -1859,7 +1833,7 @@ def test_checkout_complete_pick_transaction_flow(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)transaction_item_generator(checkout_id=checkout.pk)mocked_flow.return_value = order, False, {}@@ -1870,7 +1844,6 @@ def test_checkout_complete_pick_transaction_flow(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,)@@ -1880,7 +1853,6 @@ def test_checkout_complete_pick_transaction_flow(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,user=customer_user,app=None,tracking_code=None,@@ -1904,7 +1876,7 @@ def test_checkout_complete_pick_transaction_flow_when_checkout_total_zero(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout.total = zero_taxed_money(checkout.currency)update_checkout_payment_statuses(@@ -1923,7 +1895,6 @@ def test_checkout_complete_pick_transaction_flow_when_checkout_total_zero(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,)@@ -1933,7 +1904,6 @@ def test_checkout_complete_pick_transaction_flow_when_checkout_total_zero(manager=manager,checkout_info=checkout_info,lines=lines,- discounts=None,user=customer_user,app=None,tracking_code=None,@@ -1957,7 +1927,7 @@ def test_checkout_complete_pick_payment_flow(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_flow.return_value = order, False, {}@@ -1974,7 +1944,6 @@ def test_checkout_complete_pick_payment_flow(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,)@@ -1986,7 +1955,6 @@ def test_checkout_complete_pick_payment_flow(lines=lines,payment_data={},store_source=False,- discounts=None,user=customer_user,app=None,site_settings=None,diff --git a/saleor/checkout/tests/test_order_from_checkout.py b/saleor/checkout/tests/test_order_from_checkout.pyindex 3d7f409699..384b756450 100644--- a/saleor/checkout/tests/test_order_from_checkout.py+++ b/saleor/checkout/tests/test_order_from_checkout.py@@ -23,7 +23,7 @@ def test_create_order_insufficient_stock():variant = product_without_shipping.variants.get()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, 10, check_quantity=False)checkout.user = customer_user@@ -33,13 +33,12 @@ def test_create_order_insufficient_stock(checkout.save()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)lines, _ = fetch_checkout_lines(checkout)with pytest.raises(InsufficientStock):create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -63,7 +62,7 @@ def test_create_order_with_gift_card(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -85,7 +84,6 @@ def test_create_order_with_gift_card(order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -115,7 +113,7 @@ def test_create_order_with_gift_card_partial_use(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)price_without_gift_card = calculations.checkout_total(manager=manager,@@ -129,12 +127,11 @@ def test_create_order_with_gift_card_partial_use(checkout.save()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -174,7 +171,7 @@ def test_create_order_with_many_gift_cards(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)price_without_gift_card = calculations.checkout_total(manager=manager,@@ -192,12 +189,11 @@ def test_create_order_with_many_gift_cards(checkout.save()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -246,7 +242,7 @@ def test_create_order_gift_card_bought(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -272,7 +268,6 @@ def test_create_order_gift_card_bought(order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -316,7 +311,7 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(app,):checkout_user = None if is_anonymous_user else customer_user- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())shippable_variant = shippable_gift_card_product.variants.get()add_variant_to_checkout(checkout_info, shippable_variant, 2)@@ -330,7 +325,7 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -349,7 +344,6 @@ def test_create_order_gift_card_bought_only_shippable_gift_card(order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -387,7 +381,7 @@ def test_create_order_gift_card_bought_do_not_fulfill_gift_cards_automatically(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -406,7 +400,6 @@ def test_create_order_gift_card_bought_do_not_fulfill_gift_cards_automatically(order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -430,12 +423,11 @@ def test_note_in_created_order(manager = get_plugins_manager()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -463,7 +455,7 @@ def test_create_order_use_translations(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)variant = lines[0].variantproduct = lines[0].product@@ -481,7 +473,6 @@ def test_create_order_use_translations(order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -511,13 +502,12 @@ def test_create_order_from_checkout_updates_total_authorized_amount(manager = get_plugins_manager()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)# whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -550,13 +540,12 @@ def test_create_order_from_checkout_updates_total_charged_amount(manager = get_plugins_manager()checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, checkout_lines, manager)# whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -580,14 +569,13 @@ def test_create_order_from_checkout_update_display_gross_prices(tax_configuration.country_exceptions.all().delete()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)checkout_lines, _ = fetch_checkout_lines(checkout)# whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=[],manager=manager,user=None,app=app,@@ -622,13 +610,12 @@ def test_create_order_from_checkout_store_shipping_prices()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -639,11 +626,11 @@ def test_create_order_from_checkout_store_shipping_prices(assert order.base_shipping_price == expected_base_shipping_priceassert order.shipping_price == expected_shipping_pricemanager.calculate_checkout_shipping.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, []+ checkout_info, lines, checkout.shipping_address)assert order.shipping_tax_rate == expected_shipping_tax_ratemanager.get_checkout_shipping_tax_rate.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, [], expected_shipping_price+ checkout_info, lines, checkout.shipping_address, expected_shipping_price)@@ -670,13 +657,12 @@ def test_create_order_from_store_shipping_prices_with_free_shipping_voucher()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenorder = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=lines,- discounts=[],manager=manager,user=None,app=app,@@ -687,9 +673,9 @@ def test_create_order_from_store_shipping_prices_with_free_shipping_voucher(assert order.base_shipping_price == expected_base_shipping_priceassert order.shipping_price == expected_shipping_pricemanager.calculate_checkout_shipping.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, []+ checkout_info, lines, checkout.shipping_address)assert order.shipping_tax_rate == expected_shipping_tax_ratemanager.get_checkout_shipping_tax_rate.assert_called_once_with(- checkout_info, lines, checkout.shipping_address, [], expected_shipping_price+ checkout_info, lines, checkout.shipping_address, expected_shipping_price)diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 5458e22592..ce55326128 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -15,7 +15,7 @@ from ..core.utils.promo_code import (promo_code_is_gift_card,promo_code_is_voucher,)-from ..discount import DiscountInfo, VoucherType+from ..discount import VoucherTypefrom ..discount.interface import VoucherInfo, fetch_voucher_infofrom ..discount.models import NotApplicable, Voucherfrom ..discount.utils import (@@ -55,16 +55,15 @@ def invalidate_checkout_prices(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],manager: "PluginsManager",- discounts: Optional[Iterable["DiscountInfo"]] = None,*,recalculate_discount: bool = True,- save: bool+ save: bool,) -> List[str]:"""Mark checkout as ready for prices recalculation."""checkout = checkout_info.checkoutif recalculate_discount:- recalculate_checkout_discount(manager, checkout_info, lines, discounts or [])+ recalculate_checkout_discount(manager, checkout_info, lines)checkout.price_expiration = timezone.now()updated_fields = ["price_expiration", "last_change"]@@ -347,7 +346,6 @@ def change_shipping_address_in_checkout(checkout_info: "CheckoutInfo",address: "Address",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],manager: "PluginsManager",shipping_channel_listings: Iterable["ShippingMethodChannelListing"],):@@ -367,7 +365,7 @@ def change_shipping_address_in_checkout(checkout.shipping_address.delete()checkout.shipping_address = addressupdate_checkout_info_shipping_address(- checkout_info, address, lines, discounts, manager, shipping_channel_listings+ checkout_info, address, lines, manager, shipping_channel_listings)updated_fields = ["shipping_address", "last_change"]return updated_fields@@ -437,7 +435,6 @@ def get_prices_of_discounted_specific_product(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],voucher: Voucher,- discounts: Optional[Iterable[DiscountInfo]] = None,) -> List[Money]:"""Get prices of variants belonging to the discounted specific products.@@ -449,7 +446,7 @@ def get_prices_of_discounted_specific_product(discounted_lines: Iterable["CheckoutLineInfo"] = get_discounted_lines(lines, voucher_info)- line_prices = get_base_lines_prices(checkout_info, discounted_lines, discounts)+ line_prices = get_base_lines_prices(checkout_info, discounted_lines)return line_prices@@ -457,7 +454,6 @@ def get_prices_of_discounted_specific_product(def get_base_lines_prices(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Optional[Iterable[DiscountInfo]],):"""Get base total price of checkout lines without voucher discount applied."""line_prices = []@@ -468,9 +464,13 @@ def get_base_lines_prices(line_info.collections,checkout_info.channel,line_info.channel_listing,- discounts or [],+ [],line_info.line.price_override,)+ line_price = line_unit_price * line.quantity+ for discount in line_info.discounts:+ line_price -= Money(discount.amount_value, line_price.currency)+ line_unit_price = line_price / line.quantityline_prices.extend([line_unit_price] * line.quantity)return line_prices@@ -481,22 +481,20 @@ def get_voucher_discount_for_checkout(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> Money:"""Calculate discount value depending on voucher and discount types.Raise NotApplicable if voucher of given type cannot be applied."""- validate_voucher_for_checkout(manager, voucher, checkout_info, lines, discounts)+ validate_voucher_for_checkout(manager, voucher, checkout_info, lines)if voucher.type == VoucherType.ENTIRE_ORDER:if voucher.apply_once_per_order:- prices = get_base_lines_prices(checkout_info, lines, discounts)+ prices = get_base_lines_prices(checkout_info, lines)return voucher.get_discount_amount_for(min(prices), checkout_info.channel)subtotal = base_calculations.base_checkout_subtotal(lines,checkout_info.channel,checkout_info.checkout.currency,- discounts,)return voucher.get_discount_amount_for(subtotal, checkout_info.channel)if voucher.type == VoucherType.SHIPPING:@@ -507,9 +505,7 @@ def get_voucher_discount_for_checkout(address,)if voucher.type == VoucherType.SPECIFIC_PRODUCT:- return _get_products_voucher_discount(- manager, checkout_info, lines, voucher, discounts- )+ return _get_products_voucher_discount(manager, checkout_info, lines, voucher)raise NotImplementedError("Unknown discount type")@@ -518,13 +514,12 @@ def _get_products_voucher_discount(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],voucher,- discounts: Optional[Iterable[DiscountInfo]] = None,):"""Calculate products discount value for a voucher, depending on its type."""prices = Noneif voucher.type == VoucherType.SPECIFIC_PRODUCT:prices = get_prices_of_discounted_specific_product(- manager, checkout_info, lines, voucher, discounts+ manager, checkout_info, lines, voucher)if not prices:msg = "This offer is only valid for selected items."@@ -577,7 +572,6 @@ def check_voucher_for_checkout(manager: PluginsManager,checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],):checkout = checkout_info.checkoutaddress = checkout_info.shipping_address or checkout_info.billing_address@@ -588,7 +582,6 @@ def check_voucher_for_checkout(checkout_info,lines,address,- discounts,)return discountexcept NotApplicable:@@ -601,7 +594,6 @@ def recalculate_checkout_discount(manager: PluginsManager,checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],):"""Recalculate `checkout.discount` based on the voucher.@@ -615,14 +607,12 @@ def recalculate_checkout_discount(manager,checkout_info,lines,- discounts,)if discount:subtotal = base_calculations.base_checkout_subtotal(lines,checkout_info.channel,checkout_info.checkout.currency,- discounts,)checkout.discount = (min(discount, subtotal)@@ -653,7 +643,6 @@ def add_promo_code_to_checkout(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],promo_code: str,- discounts: Optional[Iterable[DiscountInfo]] = None,):"""Add gift card or voucher data to checkout.@@ -665,7 +654,6 @@ def add_promo_code_to_checkout(checkout_info,lines,promo_code,- discounts,)elif promo_code_is_gift_card(promo_code):user_email = cast(str, checkout_info.get_customer_email())@@ -684,7 +672,6 @@ def add_voucher_code_to_checkout(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],voucher_code: str,- discounts: Optional[Iterable[DiscountInfo]] = None,):"""Add voucher data to checkout by code.@@ -702,7 +689,6 @@ def add_voucher_code_to_checkout(checkout_info,lines,voucher,- discounts,)except NotApplicable:raise ValidationError(@@ -720,7 +706,6 @@ def add_voucher_to_checkout(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],voucher: Voucher,- discounts: Optional[Iterable[DiscountInfo]] = None,):"""Add voucher data to checkout.@@ -734,7 +719,6 @@ def add_voucher_to_checkout(checkout_info,lines,address,- discounts,)checkout.voucher_code = voucher.codecheckout.discount_name = voucher.name@@ -881,7 +865,6 @@ def is_fully_paid(manager: PluginsManager,checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],):"""Check if provided payment methods cover the checkout's total amount.@@ -896,7 +879,6 @@ def is_fully_paid(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)checkout_total = max(checkout_total, zero_taxed_money(checkout_total.currency)diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 31b190a178..0e877db5bb 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -1578,7 +1578,7 @@ def prepare_checkout_info():channel = Channel.objects.get(slug=settings.DEFAULT_CHANNEL_SLUG)checkout = Checkout.objects.create(currency=channel.currency_code, channel=channel)checkout.set_country(channel.default_country, commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())return checkout_infodiff --git a/saleor/discount/__init__.py b/saleor/discount/__init__.pyindex 1f2641bdf2..e7f59abb69 100644--- a/saleor/discount/__init__.py+++ b/saleor/discount/__init__.py@@ -15,10 +15,11 @@ class DiscountValueType:]-class OrderDiscountType:+class DiscountType:+ SALE = "sale"VOUCHER = "voucher"MANUAL = "manual"- CHOICES = [(VOUCHER, "Voucher"), (MANUAL, "Manual")]+ CHOICES = [(SALE, "Sale"), (VOUCHER, "Voucher"), (MANUAL, "Manual")]class VoucherType:diff --git a/saleor/discount/migrations/0044_auto_20230421_1018.py b/saleor/discount/migrations/0044_auto_20230421_1018.pynew file mode 100644index 0000000000..3e16c209a8--- /dev/null+++ b/saleor/discount/migrations/0044_auto_20230421_1018.py@@ -0,0 +1,144 @@+# Generated by Django 3.2.18 on 2023-04-21 10:18++from decimal import Decimal+from django.db import migrations, models+import django.db.models.deletion+import uuid+++class Migration(migrations.Migration):+ dependencies = [+ ("checkout", "0059_merge_0058"),+ ("discount", "0043_sale_notification_sent_datetime"),+ ]++ operations = [+ migrations.AddField(+ model_name="orderdiscount",+ name="sale",+ field=models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ related_name="+",+ to="discount.sale",+ ),+ ),+ migrations.AddField(+ model_name="orderdiscount",+ name="voucher",+ field=models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ related_name="+",+ to="discount.voucher",+ ),+ ),+ migrations.AlterField(+ model_name="orderdiscount",+ name="created_at",+ field=models.DateTimeField(auto_now_add=True, db_index=True),+ ),+ migrations.AlterField(+ model_name="orderdiscount",+ name="type",+ field=models.CharField(+ choices=[+ ("sale", "Sale"),+ ("voucher", "Voucher"),+ ("manual", "Manual"),+ ],+ default="manual",+ max_length=10,+ ),+ ),+ migrations.CreateModel(+ name="CheckoutLineDiscount",+ fields=[+ (+ "id",+ models.UUIDField(+ default=uuid.uuid4,+ editable=False,+ primary_key=True,+ serialize=False,+ unique=True,+ ),+ ),+ ("created_at", models.DateTimeField(auto_now_add=True, db_index=True)),+ (+ "type",+ models.CharField(+ choices=[+ ("sale", "Sale"),+ ("voucher", "Voucher"),+ ("manual", "Manual"),+ ],+ default="manual",+ max_length=10,+ ),+ ),+ (+ "value_type",+ models.CharField(+ choices=[("fixed", "fixed"), ("percentage", "%")],+ default="fixed",+ max_length=10,+ ),+ ),+ (+ "value",+ models.DecimalField(+ decimal_places=3, default=Decimal("0.0"), max_digits=12+ ),+ ),+ (+ "amount_value",+ models.DecimalField(+ decimal_places=3, default=Decimal("0.0"), max_digits=12+ ),+ ),+ ("currency", models.CharField(max_length=3)),+ ("name", models.CharField(blank=True, max_length=255, null=True)),+ (+ "translated_name",+ models.CharField(blank=True, max_length=255, null=True),+ ),+ ("reason", models.TextField(blank=True, null=True)),+ (+ "line",+ models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.CASCADE,+ related_name="discounts",+ to="checkout.checkoutline",+ ),+ ),+ (+ "sale",+ models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ related_name="+",+ to="discount.sale",+ ),+ ),+ (+ "voucher",+ models.ForeignKey(+ blank=True,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ related_name="+",+ to="discount.voucher",+ ),+ ),+ ],+ options={+ "ordering": ("created_at", "id"),+ },+ ),+ ]diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 431985d1f6..11f5dfa0c5 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -19,7 +19,7 @@ from ..channel.models import Channelfrom ..core.models import ModelWithMetadatafrom ..core.utils.translations import Translation, TranslationProxyfrom ..permission.enums import DiscountPermissions-from . import DiscountValueType, OrderDiscountType, VoucherType+from . import DiscountType, DiscountValueType, VoucherTypeif TYPE_CHECKING:from ..account.models import User@@ -358,21 +358,13 @@ class SaleTranslation(Translation):return {"name": self.name}-class OrderDiscount(models.Model):+class BaseDiscount(models.Model):id = models.UUIDField(primary_key=True, editable=False, unique=True, default=uuid4)- old_id = models.PositiveIntegerField(unique=True, null=True, blank=True)- created_at = models.DateTimeField(auto_now_add=True)- order = models.ForeignKey(- "order.Order",- related_name="discounts",- blank=True,- null=True,- on_delete=models.CASCADE,- )+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)type = models.CharField(max_length=10,- choices=OrderDiscountType.CHOICES,- default=OrderDiscountType.MANUAL,+ choices=DiscountType.CHOICES,+ default=DiscountType.MANUAL,)value_type = models.CharField(max_length=10,@@ -384,7 +376,6 @@ class OrderDiscount(models.Model):decimal_places=settings.DEFAULT_DECIMAL_PLACES,default=Decimal("0.0"),)-amount_value = models.DecimalField(max_digits=settings.DEFAULT_MAX_DIGITS,decimal_places=settings.DEFAULT_DECIMAL_PLACES,@@ -394,12 +385,44 @@ class OrderDiscount(models.Model):currency = models.CharField(max_length=settings.DEFAULT_CURRENCY_CODE_LENGTH,)-name = models.CharField(max_length=255, null=True, blank=True)translated_name = models.CharField(max_length=255, null=True, blank=True)reason = models.TextField(blank=True, null=True)+ sale = models.ForeignKey(+ Sale, related_name="+", blank=True, null=True, on_delete=models.SET_NULL+ )+ voucher = models.ForeignKey(+ Voucher, related_name="+", blank=True, null=True, on_delete=models.SET_NULL+ )++ class Meta:+ abstract = True+++class OrderDiscount(BaseDiscount):+ order = models.ForeignKey(+ "order.Order",+ related_name="discounts",+ blank=True,+ null=True,+ on_delete=models.CASCADE,+ )+ old_id = models.PositiveIntegerField(unique=True, null=True, blank=True)class Meta:# Orders searching indexindexes = [GinIndex(fields=["name", "translated_name"])]ordering = ("created_at", "id")+++class CheckoutLineDiscount(BaseDiscount):+ line = models.ForeignKey(+ "checkout.CheckoutLine",+ related_name="discounts",+ blank=True,+ null=True,+ on_delete=models.CASCADE,+ )++ class Meta:+ ordering = ("created_at", "id")diff --git a/saleor/discount/tests/test_rounding_isse.py b/saleor/discount/tests/test_rounding_isse.pynew file mode 100644index 0000000000..bfe19b93d4--- /dev/null+++ b/saleor/discount/tests/test_rounding_isse.py@@ -0,0 +1,123 @@+from decimal import Decimal++import pytest++from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines+from ...checkout.utils import add_variant_to_checkout+from ...plugins.manager import get_plugins_manager+from ...product.models import ProductVariantChannelListing+from .. import DiscountInfo, DiscountValueType+from ..models import Sale, SaleChannelListing+from ..utils import (+ create_or_update_discount_objects_from_sale_for_checkout,+ fetch_sale_channel_listings,+)+++def sale_10_percentage(channel_USD):+ sale = Sale.objects.create(name="Sale 10%", type=DiscountValueType.PERCENTAGE)+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=10,+ currency=channel_USD.currency_code,+ )+ return sale+++ "variant_prices, expected_discounts",+ [+ (+ [Decimal("1.06"), Decimal("2.06"), Decimal("3.06"), Decimal("4.06")],+ [Decimal("0.11"), Decimal("0.2"), Decimal("0.31"), Decimal("0.4")],+ ),+ (+ [Decimal("1.04"), Decimal("2.04"), Decimal("3.04"), Decimal("4.04")],+ [Decimal("0.1"), Decimal("0.21"), Decimal("0.3"), Decimal("0.41")],+ ),+ ],+)+def test_rounding_issue_with_percentage_sale(+ product_list,+ product,+ checkout,+ channel_USD,+ sale_10_percentage,+ variant_prices,+ expected_discounts,+):+ """Test checking that a rounding issue may appear in calculations.++ We want to test a scenario where a percentage sale is applied to each line+ separately, resulting in a total discount that is different from applying+ the same percentage sale to the sum of qualified lines.++ If we calculate 10% discount for first example we got:+ +-------+-------------+----------+----------++ | Line | Line total | New flow | Old flow |+ +-------+-------------+----------+----------++ | Line1 | 1.06 | 0.11 | 0.11 |+ | Line2 | 2.06 | 0.2 | 0.21 |+ | Line3 | 3.06 | 0.31 | 0.31 |+ | Line4 | 4.06 | 0.4 | 0.41 |+ +-------+-------------+----------+----------++ | Sum | 10.24 | 1.02 | 1.04 |+ +-------+-------------+----------+----------++ """++ # given+ product_list.append(product)+ sale = sale_10_percentage+ variants = []+ variant_channel_listings = []+ total_amount = Decimal("0")+ for product, price in zip(product_list, variant_prices):+ variant = product.variants.get()+ variant_channel_listing = variant.channel_listings.get(channel=channel_USD)+ variant_channel_listing.price_amount = price+ variant_channel_listings.append(variant_channel_listing)+ variants.append(variant)+ total_amount += price+ sale.variants.add(variant)+ ProductVariantChannelListing.objects.bulk_update(+ variant_channel_listings, ["price_amount"]+ )+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())+ for variant in variants:+ add_variant_to_checkout(checkout_info, variant, 1)++ lines_info, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())++ sale_channel_listings = fetch_sale_channel_listings([sale.pk])[sale.pk]+ sale_info = DiscountInfo(+ sale=sale,+ category_ids=set(),+ channel_listings=sale_channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids=set([variant.id for variant in variants]),+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines_info, [sale_info]+ )++ # then+ for line_info, expected_discount in zip(lines_info, expected_discounts):+ assert len(line_info.discounts) == 1+ discount_from_info = line_info.discounts[0]+ discount_from_db = line_info.line.discounts.get()+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount+ )diff --git a/saleor/discount/tests/test_utils/__init__.py b/saleor/discount/tests/test_utils/__init__.pynew file mode 100644index 0000000000..79d8025c38--- /dev/null+++ b/saleor/discount/tests/test_utils/__init__.py@@ -0,0 +1,23 @@+from ... import DiscountInfo+from ...utils import fetch_sale_channel_listings+++def generate_discount_info(+ sale,+ products_pks=set(),+ variant_pks=set(),+ collection_pks=set(),+ category_ids=set(),+ channel_listings=None,+):+ if not channel_listings:+ channel_listings = fetch_sale_channel_listings([sale.pk])[sale.pk]++ return DiscountInfo(+ sale=sale,+ category_ids=category_ids,+ channel_listings=channel_listings,+ collection_ids=collection_pks,+ product_ids=products_pks,+ variants_ids=variant_pks,+ )diff --git a/saleor/discount/tests/test_utils/fixtures.py b/saleor/discount/tests/test_utils/fixtures.pynew file mode 100644index 0000000000..b1e82f8de5--- /dev/null+++ b/saleor/discount/tests/test_utils/fixtures.py@@ -0,0 +1,106 @@+import pytest++from ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines+from ....plugins.manager import get_plugins_manager+from ... import DiscountInfo, DiscountValueType+from ...models import Sale, SaleChannelListing+from ...utils import fetch_sale_channel_listings+++def checkout_lines_info(checkout_with_items, categories, published_collections):+ lines = checkout_with_items.lines.all()+ category1, category2 = categories++ product1 = lines[0].variant.product+ product1.category = category1+ product1.collections.add(*published_collections[:2])+ product1.save()++ product2 = lines[1].variant.product+ product2.category = category2+ product2.collections.add(published_collections[0])+ product2.save()++ lines_info, _ = fetch_checkout_lines(checkout_with_items)+ return lines_info+++def checkout_info(checkout_lines_info):+ manager = get_plugins_manager()+ checkout = checkout_lines_info[0].line.checkout+ checkout_info = fetch_checkout_info(checkout, checkout_lines_info, manager)+ return checkout_info+++def checkout_lines_with_multiple_quantity_info(+ checkout_with_items, categories, published_collections+):+ checkout_with_items.lines.update(quantity=5)+ lines = checkout_with_items.lines.all()+ category1, category2 = categories++ product1 = lines[0].variant.product+ product1.category = category1+ product1.collections.add(*published_collections[:2])+ product1.save()++ product2 = lines[1].variant.product+ product2.category = category2+ product2.collections.add(published_collections[0])+ product2.save()++ lines_info, _ = fetch_checkout_lines(checkout_with_items)+ return lines_info+++def discount_info_for_new_sale(new_sale):+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ return DiscountInfo(+ sale=new_sale,+ category_ids=set(),+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids=set(),+ )+++def new_sale_percentage(channel_USD):+ sale = Sale.objects.create(name="Sale 25%", type=DiscountValueType.PERCENTAGE)+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=25,+ currency=channel_USD.currency_code,+ )+ return sale+++def sale_5_percentage(channel_USD):+ sale = Sale.objects.create(name="Sale 5%", type=DiscountValueType.PERCENTAGE)+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ return sale+++def sale_1_usd(channel_USD):+ sale = Sale.objects.create(name="Sale 1 USD", type=DiscountValueType.FIXED)+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=1,+ currency=channel_USD.currency_code,+ )+ return salediff --git a/saleor/discount/tests/test_utils/test_create_or_update_discount_objects_from_sale_for_checkout.py b/saleor/discount/tests/test_utils/test_create_or_update_discount_objects_from_sale_for_checkout.pynew file mode 100644index 0000000000..4c3fddd13a--- /dev/null+++ b/saleor/discount/tests/test_utils/test_create_or_update_discount_objects_from_sale_for_checkout.py@@ -0,0 +1,1205 @@+from decimal import Decimal++from django.utils import timezone+from freezegun import freeze_time++from ... import DiscountType, DiscountValueType+from ...utils import create_or_update_discount_objects_from_sale_for_checkout+from . import generate_discount_info+++def test_create_or_update_discount_objects_from_sale_for_checkout_without_sale(+ checkout_lines_info, checkout_info+):+ # given++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, []+ )++ # then+ for checkout_line_info in checkout_lines_info:+ assert not checkout_line_info.discounts+++@freeze_time("2020-12-12 12:00:00")+def test_create_fixed_sale(checkout_lines_info, checkout_info, new_sale):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = new_sale+ sale.products.add(product_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert len(line_info1.discounts) == 1+ now = timezone.now()+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.created_at == discount_from_db.created_at == now+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert (+ discount_from_info.translated_name == discount_from_db.translated_name is None+ )+ assert discount_from_info.reason == discount_from_db.reason is None+ assert discount_from_info.sale == discount_from_db.sale == sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++@freeze_time("2020-12-12 12:00:00")+def test_create_fixed_sale_multiple_quantity_in_lines(+ checkout_lines_with_multiple_quantity_info,+ checkout_info,+ new_sale,+):+ # given+ line_info1 = checkout_lines_with_multiple_quantity_info[0]+ product_line1 = line_info1.product++ sale = new_sale+ sale.products.add(product_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = (+ sale_channel_listing.discount_value * line_info1.line.quantity+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_with_multiple_quantity_info,+ [discount_info_for_new_sale],+ )++ # then+ assert len(line_info1.discounts) == 1+ now = timezone.now()+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.created_at == discount_from_db.created_at == now+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert (+ discount_from_info.translated_name == discount_from_db.translated_name is None+ )+ assert discount_from_info.reason == discount_from_db.reason is None+ assert discount_from_info.sale == discount_from_db.sale == sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_with_multiple_quantity_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_fixed_sale_multiple_quantity_in_lines_more_then_total(+ checkout_lines_with_multiple_quantity_info,+ checkout_info,+ new_sale,+):+ # given+ discount_value = Decimal(15)+ line_info1 = checkout_lines_with_multiple_quantity_info[0]+ product_line1 = line_info1.product++ sale = new_sale+ sale.products.add(product_line1)+ sale_channel_listing = sale.channel_listings.get()+ sale_channel_listing.discount_value = discount_value+ sale_channel_listing.save()+ discount_info_for_new_sale = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ expected_discount_amount = (+ sale_channel_listing.discount_value * line_info1.line.quantity+ )+ base_unit_price = line_info1.variant.get_base_price(+ line_info1.channel_listing, line_info1.line.price_override+ )+ expected_discount_amount = (base_unit_price * line_info1.line.quantity).amount++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_with_multiple_quantity_info,+ [discount_info_for_new_sale],+ )++ # then+ assert discount_value > base_unit_price.amount+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert discount_from_info.value == discount_from_db.value == discount_value+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"++ for checkout_line_info in checkout_lines_with_multiple_quantity_info[1:]:+ assert not checkout_line_info.discounts+++@freeze_time("2020-12-12 12:00:00")+def test_create_percentage_sale(+ checkout_lines_info, checkout_info, new_sale_percentage+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = new_sale_percentage+ sale.products.add(product_line1)+ discount_info_for_new_sale_percentage = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = variant_channel_listing.price_amount * (+ sale_channel_listing.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale_percentage]+ )++ # then+ assert len(line_info1.discounts) == 1+ now = timezone.now()+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.created_at == discount_from_db.created_at == now+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert (+ discount_from_info.translated_name == discount_from_db.translated_name is None+ )+ assert discount_from_info.reason == discount_from_db.reason is None+ assert discount_from_info.sale == discount_from_db.sale == sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++@freeze_time("2020-12-12 12:00:00")+def test_create_percentage_sale_multiple_quantity_in_lines(+ checkout_lines_with_multiple_quantity_info,+ checkout_info,+ new_sale_percentage,+):+ # given+ line_info1 = checkout_lines_with_multiple_quantity_info[0]+ product_line1 = line_info1.product++ sale = new_sale_percentage+ sale.products.add(product_line1)+ discount_info_for_new_sale_percentage = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = (+ variant_channel_listing.price_amount+ * line_info1.line.quantity+ * (sale_channel_listing.discount_value / 100)+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_with_multiple_quantity_info,+ [discount_info_for_new_sale_percentage],+ )++ # then+ assert len(line_info1.discounts) == 1+ now = timezone.now()+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert line_info1.line.quantity > 1+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.created_at == discount_from_db.created_at == now+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert (+ discount_from_info.translated_name == discount_from_db.translated_name is None+ )+ assert discount_from_info.reason == discount_from_db.reason is None+ assert discount_from_info.sale == discount_from_db.sale == sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_with_multiple_quantity_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_with_translation(+ checkout_lines_info,+ checkout_info,+ new_sale_translation_fr,+):+ # given+ checkout_info.checkout.language_code = "fr"+ checkout_info.checkout.save()++ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = new_sale_translation_fr.sale+ sale.products.add(product_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert checkout_info.checkout.language_code == "fr"++ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert (+ discount_from_info.translated_name+ == discount_from_db.translated_name+ == new_sale_translation_fr.name+ )+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_fixed_sale_more_then_total(+ checkout_lines_info, checkout_info, new_sale+):+ # given+ discount_value = Decimal(100)++ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = new_sale+ sale.products.add(product_line1)+ sale_channel_listing = sale.channel_listings.get()+ sale_channel_listing.discount_value = discount_value+ sale_channel_listing.save()++ discount_info_for_new_sale = generate_discount_info(+ sale,+ products_pks={product_line1.pk},+ channel_listings={sale_channel_listing.channel.slug: sale_channel_listing},+ )++ base_unit_price = line_info1.variant.get_base_price(+ line_info1.channel_listing, line_info1.line.price_override+ )+ expected_discount_amount = (base_unit_price * line_info1.line.quantity).amount++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert discount_value > expected_discount_amount+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert discount_from_info.value == discount_from_db.value == discount_value+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_by_product(checkout_lines_info, checkout_info, new_sale):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = new_sale+ sale.products.add(product_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, products_pks={product_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_by_variant(checkout_lines_info, checkout_info, new_sale):+ # given+ line_info1 = checkout_lines_info[0]+ variant_line1 = line_info1.variant++ sale = new_sale+ sale.variants.add(variant_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, variant_pks={variant_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_by_collection(checkout_lines_info, checkout_info, new_sale):+ # given+ line_info1 = checkout_lines_info[0]+ collection_line1 = line_info1.collections[1]++ sale = new_sale+ sale.collections.add(collection_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, collection_pks={collection_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_by_category(checkout_lines_info, checkout_info, new_sale):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product+ category_line1 = product_line1.category++ sale = new_sale+ sale.categories.add(category_line1)+ discount_info_for_new_sale = generate_discount_info(+ sale, category_ids={category_line1.pk}+ )++ sale_channel_listing = sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info_for_new_sale]+ )++ # then+ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_two_percentage_sales(+ checkout_lines_info,+ checkout_info,+ new_sale_percentage,+ sale_5_percentage,+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ not_applied_sale = sale_5_percentage+ applied_sale = new_sale_percentage++ sales = [not_applied_sale, applied_sale]+ discount_infos = []+ for sale in sales:+ sale.products.add(product_line1)+ discount_infos.append(+ generate_discount_info(sale, products_pks={product_line1.pk})+ )++ sale_channel_listing = applied_sale.channel_listings.get()+ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = variant_channel_listing.price_amount * (+ sale_channel_listing.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_info,+ discount_infos,+ )++ # then+ assert (+ not_applied_sale.channel_listings.get().discount_value+ < sale_channel_listing.discount_value+ )++ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()++ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.sale == discount_from_db.sale == applied_sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_two_fixed_sales(+ checkout_lines_info, checkout_info, new_sale, sale_1_usd+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ not_applied_sale = sale_1_usd+ applied_sale = new_sale++ sales = [not_applied_sale, applied_sale]+ discount_infos = []+ for sale in sales:+ sale.products.add(product_line1)+ discount_infos.append(+ generate_discount_info(sale, products_pks={product_line1.pk})+ )++ sale_channel_listing = applied_sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_info,+ discount_infos,+ )++ # then+ assert (+ not_applied_sale.channel_listings.get().discount_value+ < sale_channel_listing.discount_value+ )++ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == applied_sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_fixed_sales_more_then_percentage(+ checkout_lines_info, checkout_info, new_sale, sale_5_percentage+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ not_applied_sale = sale_5_percentage+ applied_sale = new_sale++ sales = [not_applied_sale, applied_sale]+ discount_infos = []+ for sale in sales:+ sale.products.add(product_line1)+ discount_infos.append(+ generate_discount_info(sale, products_pks={product_line1.pk})+ )++ sale_channel_listing = applied_sale.channel_listings.get()+ expected_discount_amount = sale_channel_listing.discount_value++ sale_channel_listing = not_applied_sale.channel_listings.get()+ variant_channel_listing = line_info1.variant.channel_listings.get()+ discount_amount_for_percentage_sale = variant_channel_listing.price_amount * (+ sale_channel_listing.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_info,+ discount_infos,+ )++ # then+ assert discount_amount_for_percentage_sale < sale_channel_listing.discount_value++ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.sale == discount_from_db.sale == applied_sale+ assert discount_from_info.voucher == discount_from_db.voucher is None++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_create_sale_percentage_sales_more_then_fixed(+ checkout_lines_info,+ checkout_info,+ new_sale_percentage,+ sale_1_usd,+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ not_applied_sale = sale_1_usd+ applied_sale = new_sale_percentage++ sales = [not_applied_sale, applied_sale]+ discount_infos = []+ for sale in sales:+ sale.products.add(product_line1)+ discount_infos.append(+ generate_discount_info(sale, products_pks={product_line1.pk})+ )++ sale_channel_listing = applied_sale.channel_listings.get()+ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = variant_channel_listing.price_amount * (+ sale_channel_listing.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_info,+ discount_infos,+ )++ # then+ assert (+ not_applied_sale.channel_listings.get().discount_value+ < expected_discount_amount+ )++ assert len(line_info1.discounts) == 1+ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()++ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.sale == discount_from_db.sale == applied_sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_two_sales_applied_to_two_different_lines(+ checkout_lines_info,+ checkout_info,+ new_sale_percentage,+ sale_1_usd,+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale1 = sale_1_usd+ sale1.products.add(product_line1)+ discount_info1 = generate_discount_info(sale1, products_pks={product_line1.pk})++ sale_channel_listing1 = sale1.channel_listings.get()+ expected_discount_amount1 = sale_channel_listing1.discount_value++ line_info2 = checkout_lines_info[1]+ product_line2 = line_info2.product++ sale2 = new_sale_percentage+ sale2.products.add(product_line2)+ discount_info2 = generate_discount_info(sale2, products_pks={product_line2.pk})++ sale_channel_listing2 = sale2.channel_listings.get()+ variant_channel_listing2 = line_info1.variant.channel_listings.get()+ expected_discount_amount2 = variant_channel_listing2.price_amount * (+ sale_channel_listing2.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info,+ checkout_lines_info,+ [discount_info1, discount_info2],+ )++ # then+ assert line_info1.product != line_info2.product+ # Checkout discount for first line with fixed sale+ assert len(line_info1.discounts) == 1+ discount_from_info1 = line_info1.discounts[0]+ discount_from_db1 = line_info1.line.discounts.get()++ assert discount_from_info1.line == discount_from_db1.line == line_info1.line+ assert discount_from_info1.type == discount_from_db1.type == DiscountType.SALE+ assert (+ discount_from_info1.value_type+ == discount_from_db1.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info1.value+ == discount_from_db1.value+ == sale_channel_listing1.discount_value+ )+ assert (+ discount_from_info1.amount_value+ == discount_from_db1.amount_value+ == expected_discount_amount1+ )+ assert discount_from_info1.currency == discount_from_db1.currency == "USD"+ assert discount_from_info1.sale == discount_from_db1.sale == sale1++ # Checkout discount for second line with percentage sale+ assert len(line_info2.discounts) == 1+ discount_from_info2 = line_info2.discounts[0]+ discount_from_db2 = line_info2.line.discounts.get()++ assert discount_from_info2.line == discount_from_db2.line == line_info2.line+ assert discount_from_info2.type == discount_from_db2.type == DiscountType.SALE+ assert (+ discount_from_info2.value_type+ == discount_from_db2.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info2.value+ == discount_from_db2.value+ == sale_channel_listing2.discount_value+ )+ assert (+ discount_from_info2.amount_value+ == discount_from_db2.amount_value+ == expected_discount_amount2+ )+ assert discount_from_info2.currency == discount_from_db2.currency == "USD"+ assert discount_from_info2.sale == discount_from_db2.sale == sale2++ for checkout_line_info in checkout_lines_info[2:]:+ assert not checkout_line_info.discounts+++def test_update_sale_from_fixed_to_percentage(+ checkout_lines_info,+ checkout_info,+ sale_1_usd,+):+ # given+ expected_discount_value = Decimal(50)++ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = sale_1_usd+ sale.products.add(product_line1)+ discount_info = generate_discount_info(sale, products_pks={product_line1.pk})++ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )++ sale.type = DiscountValueType.PERCENTAGE+ sale.save()+ sale_channel_listing = sale.channel_listings.get()+ sale_channel_listing.discount_value = expected_discount_value+ sale_channel_listing.save()+ updated_discount_info = generate_discount_info(+ sale,+ products_pks={product_line1.pk},+ channel_listings={sale_channel_listing.channel.slug: sale_channel_listing},+ )++ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = variant_channel_listing.price_amount * (+ expected_discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [updated_discount_info]+ )++ # then+ assert len(line_info1.discounts) == 1++ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert discount_from_info.value == discount_from_db.value == expected_discount_value+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_update_sale_from_percentage_to_fixed(+ checkout_lines_info,+ checkout_info,+ sale_5_percentage,+):+ # given+ expected_discount_value = Decimal(7)+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ sale = sale_5_percentage+ sale.products.add(product_line1)+ discount_info = generate_discount_info(sale, products_pks={product_line1.pk})++ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )++ sale.type = DiscountValueType.FIXED+ sale.save()+ sale_channel_listing = sale.channel_listings.get()+ sale_channel_listing.discount_value = expected_discount_value+ sale_channel_listing.save()+ updated_discount_info = generate_discount_info(+ sale,+ products_pks={product_line1.pk},+ channel_listings={sale_channel_listing.channel.slug: sale_channel_listing},+ )++ expected_discount_amount = expected_discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [updated_discount_info]+ )++ # then+ assert len(line_info1.discounts) == 1++ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert discount_from_info.value == discount_from_db.value == expected_discount_value+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == sale.name+ assert discount_from_info.sale == discount_from_db.sale == sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_replace_sale_from_fixed_to_percentage(+ checkout_lines_info,+ checkout_info,+ sale_1_usd,+ sale_5_percentage,+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ start_sale = sale_1_usd+ start_sale.products.add(product_line1)+ discount_info = generate_discount_info(start_sale, products_pks={product_line1.pk})++ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )++ target_sale = sale_5_percentage+ target_sale.products.add(product_line1)+ sale_channel_listing = target_sale.channel_listings.get()++ updated_discount_info = generate_discount_info(+ target_sale, products_pks={product_line1.pk}+ )++ variant_channel_listing = line_info1.variant.channel_listings.get()+ expected_discount_amount = variant_channel_listing.price_amount * (+ sale_channel_listing.discount_value / 100+ )++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [updated_discount_info]+ )++ # then+ assert len(line_info1.discounts) == 1++ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.PERCENTAGE+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == target_sale.name+ assert discount_from_info.sale == discount_from_db.sale == target_sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discounts+++def test_replace_sale_from_percentage_to_fixed(+ checkout_lines_info,+ checkout_info,+ sale_1_usd,+ sale_5_percentage,+):+ # given+ line_info1 = checkout_lines_info[0]+ product_line1 = line_info1.product++ start_sale = sale_5_percentage+ start_sale.products.add(product_line1)+ discount_info = generate_discount_info(start_sale, products_pks={product_line1.pk})++ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [discount_info]+ )++ target_sale = sale_1_usd+ target_sale.products.add(product_line1)+ sale_channel_listing = target_sale.channel_listings.get()++ updated_discount_info = generate_discount_info(+ target_sale,+ products_pks={product_line1.pk},+ )++ expected_discount_amount = sale_channel_listing.discount_value++ # when+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines_info, [updated_discount_info]+ )++ # then+ assert len(line_info1.discounts) == 1++ discount_from_info = line_info1.discounts[0]+ discount_from_db = line_info1.line.discounts.get()+ assert discount_from_info.line == discount_from_db.line == line_info1.line+ assert discount_from_info.type == discount_from_db.type == DiscountType.SALE+ assert (+ discount_from_info.value_type+ == discount_from_db.value_type+ == DiscountValueType.FIXED+ )+ assert (+ discount_from_info.value+ == discount_from_db.value+ == sale_channel_listing.discount_value+ )+ assert (+ discount_from_info.amount_value+ == discount_from_db.amount_value+ == expected_discount_amount+ )+ assert discount_from_info.currency == discount_from_db.currency == "USD"+ assert discount_from_info.name == discount_from_db.name == target_sale.name+ assert discount_from_info.sale == discount_from_db.sale == target_sale++ for checkout_line_info in checkout_lines_info[1:]:+ assert not checkout_line_info.discountsdiff --git a/saleor/discount/tests/test_utils/test_fetch_active_sales_for_checkout.py b/saleor/discount/tests/test_utils/test_fetch_active_sales_for_checkout.pynew file mode 100644index 0000000000..68cdaa2d59--- /dev/null+++ b/saleor/discount/tests/test_utils/test_fetch_active_sales_for_checkout.py@@ -0,0 +1,328 @@+from unittest import mock++from ....checkout.fetch import fetch_checkout_lines+from ....discount.models import Sale, SaleChannelListing+from ... import DiscountInfo+from ...utils import fetch_active_sales_for_checkout, fetch_sale_channel_listings+++def test_fetch_sale_channel_listings(new_sale, sale_with_many_channels):+ # given+ sales = [new_sale, sale_with_many_channels]++ expected_channel_listings_map = {}+ for sale in sales:+ expected_channel_listings_map[sale.pk] = {+ channel_listing.channel.slug: channel_listing+ for channel_listing in sale.channel_listings.all()+ }++ # when+ channel_listings_map = fetch_sale_channel_listings(sales)++ # then+ assert channel_listings_map == expected_channel_listings_map+++def test_fetch_active_sale_for_no_sale_to_apply(checkout_lines_info, new_sale):+ # given++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == []++[email protected]("saleor.discount.utils.fetch_products")[email protected]("saleor.discount.utils.fetch_variants")[email protected]("saleor.discount.utils.fetch_categories")[email protected]("saleor.discount.utils.fetch_collections")[email protected]("saleor.discount.utils.fetch_sale_channel_listings")+def test_fetch_active_sale_for_empty_checkout(+ mocked_fetch_sale_channel_listings,+ mocked_fetch_collections,+ mocked_fetch_categories,+ mocked_fetch_variants,+ mocked_fetch_products,+ checkout,+):+ # given+ lines_info, _ = fetch_checkout_lines(checkout)++ # when+ sales = fetch_active_sales_for_checkout(lines_info)++ # then+ assert sales == []+ mocked_fetch_sale_channel_listings.assert_not_called()+ mocked_fetch_collections.assert_not_called()+ mocked_fetch_categories.assert_not_called()+ mocked_fetch_variants.assert_not_called()+ mocked_fetch_products.assert_not_called()+++def test_fetch_active_sale_for_products(+ checkout_lines_info, new_sale, product_with_two_variants+):+ # given+ line_info1, line_info2 = checkout_lines_info[:2]+ new_sale.products.add(+ # We add a not-used product to the sale to check that+ # `fetch_active_sales_for_checkout` don't over-fetch data.+ *[line_info1.product, line_info2.product, product_with_two_variants]+ )+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids=set(),+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids={line_info1.product.pk, line_info2.product.pk},+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_variants(+ checkout_lines_info, new_sale, product_with_two_variants+):+ # given+ line_info1, line_info2 = checkout_lines_info[:2]+ # We add a not-used product variants to the sale to check that+ # `fetch_active_sales_for_checkout` don't over-fetch data.+ variants = list(product_with_two_variants.variants.all())+ variants.extend([line_info1.variant, line_info2.variant])+ new_sale.variants.add(*variants)+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids=set(),+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids={line_info1.variant.pk, line_info2.variant.pk},+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_categories(+ checkout_lines_info, new_sale, categories, categories_tree+):+ # given+ new_sale.categories.add(*categories)+ # We add a not-used category to the sale to check that+ # `fetch_active_sales_for_checkout` don't over-fetch data.+ new_sale.categories.add(categories_tree)+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids={cat.pk for cat in categories},+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_only_subcategory(+ checkout_lines_info, new_sale, categories_tree+):+ # given+ category = categories_tree+ subcategory = category.children.first()+ new_sale.categories.add(category)+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ product1 = checkout_lines_info[0].variant.product+ product1.category = subcategory+ product1.save()++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids={subcategory.pk},+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_subcategory_and_category(+ checkout_lines_info, new_sale, categories_tree+):+ # given+ category = categories_tree+ subcategory = category.children.first()+ new_sale.categories.add(*[category, subcategory])+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ product1 = checkout_lines_info[0].variant.product+ product1.category = subcategory+ product1.save()+ product2 = checkout_lines_info[1].variant.product+ product2.category = category+ product2.save()++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids={subcategory.pk, category.pk},+ channel_listings=channel_listings,+ collection_ids=set(),+ product_ids=set(),+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_collections(+ checkout_lines_info, new_sale, published_collections+):+ # given+ collections_in_sale = published_collections[:2]+ # We add a not-used collections to the sale to check that+ # `fetch_active_sales_for_checkout` don't over-fetch data.+ new_sale.collections.add(*published_collections)+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids=set(),+ channel_listings=channel_listings,+ collection_ids={col.pk for col in collections_in_sale},+ product_ids=set(),+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_all_relations(+ checkout_lines_info, new_sale, published_collections, categories+):+ # given+ line_info1, line_info2 = checkout_lines_info[:2]+ collections_in_sale = published_collections[:2]+ channel_listings = fetch_sale_channel_listings([new_sale.pk])[new_sale.pk]++ new_sale.products.add(*[line_info1.product, line_info2.product])+ new_sale.variants.add(*[line_info1.variant, line_info2.variant])+ new_sale.categories.add(*categories)+ new_sale.collections.add(*collections_in_sale)++ discount_info = DiscountInfo(+ sale=new_sale,+ category_ids={cat.pk for cat in categories},+ channel_listings=channel_listings,+ collection_ids={col.pk for col in collections_in_sale},+ product_ids={line_info1.product.pk, line_info2.product.pk},+ variants_ids={line_info1.variant.pk, line_info2.variant.pk},+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info]+++def test_fetch_active_sale_for_many_sales(+ checkout_lines_info, published_collections, categories, channel_USD+):+ # given+ line_info1, line_info2 = checkout_lines_info[:2]+ collections_in_sale = published_collections[:2]++ sales = Sale.objects.bulk_create(+ [+ Sale(name="Sale1"),+ Sale(name="Sale2"),+ Sale(name="Sale3"),+ ]+ )+ SaleChannelListing.objects.bulk_create(+ [+ SaleChannelListing(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ for sale in sales+ ]+ )++ channel_listings_by_sale_id_map = fetch_sale_channel_listings(+ [sale.pk for sale in sales]+ )++ sales[0].products.add(*[line_info1.product, line_info2.product])+ discount_info1 = DiscountInfo(+ sale=sales[0],+ category_ids=set(),+ channel_listings=channel_listings_by_sale_id_map[sales[0].pk],+ collection_ids=set(),+ product_ids={line_info1.product.pk, line_info2.product.pk},+ variants_ids=set(),+ )++ sales[1].variants.add(*[line_info1.variant, line_info2.variant])+ discount_info2 = DiscountInfo(+ sale=sales[1],+ category_ids=set(),+ channel_listings=channel_listings_by_sale_id_map[sales[1].pk],+ collection_ids=set(),+ product_ids=set(),+ variants_ids={line_info1.variant.pk, line_info2.variant.pk},+ )++ sales[2].categories.add(*categories)+ sales[2].collections.add(*collections_in_sale)+ discount_info3 = DiscountInfo(+ sale=sales[2],+ category_ids={cat.pk for cat in categories},+ channel_listings=channel_listings_by_sale_id_map[sales[2].pk],+ collection_ids={col.pk for col in collections_in_sale},+ product_ids=set(),+ variants_ids=set(),+ )++ # when+ sales = fetch_active_sales_for_checkout(checkout_lines_info)++ # then+ assert sales == [discount_info1, discount_info2, discount_info3]diff --git a/saleor/discount/utils.py b/saleor/discount/utils.pyindex 0720f8f3d4..68b75eb279 100644--- a/saleor/discount/utils.py+++ b/saleor/discount/utils.py@@ -16,7 +16,9 @@ from typing import (Union,cast,)+from uuid import UUID+from babel.numbers import get_currency_precisionfrom django.conf import settingsfrom django.db.models import Ffrom django.utils import timezone@@ -24,12 +26,14 @@ from prices import Money, TaxedMoney, fixed_discount, percentage_discountfrom ..channel.models import Channelfrom ..core.taxes import zero_money-from . import DiscountInfo+from . import DiscountInfo, DiscountTypefrom .models import (+ CheckoutLineDiscount,DiscountValueType,NotApplicable,Sale,SaleChannelListing,+ SaleTranslation,VoucherCustomer,)@@ -202,7 +206,6 @@ def validate_voucher_for_checkout(voucher: "Voucher",checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Optional[Iterable[DiscountInfo]],):from ..checkout import base_calculationsfrom ..checkout.utils import calculate_checkout_quantity@@ -212,7 +215,6 @@ def validate_voucher_for_checkout(lines,checkout_info.channel,checkout_info.checkout.currency,- discounts,)customer_email = cast(str, checkout_info.get_customer_email())@@ -271,6 +273,7 @@ def get_products_voucher_discount(def fetch_categories(sale_pks: Iterable[str],+ lines_info: Iterable["CheckoutLineInfo"] = [],database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,) -> Dict[int, Set[int]]:from ..product.models import Category@@ -284,60 +287,85 @@ def fetch_categories(category_map: Dict[int, Set[int]] = defaultdict(set)for sale_pk, category_pk in categories:category_map[sale_pk].add(category_pk)++ used_category_pks = {line_info.product.category_id for line_info in lines_info}+subcategory_map: Dict[int, Set[int]] = defaultdict(set)for sale_pk, category_pks in category_map.items():- subcategory_map[sale_pk] = set(- Category.tree.filter(pk__in=category_pks)- .get_descendants(include_self=True)- .values_list("pk", flat=True)+ subcategories = Category.tree.filter(pk__in=category_pks).get_descendants(+ include_self=True)++ if used_category_pks:+ subcategories = subcategories.filter(pk__in=used_category_pks)++ subcategory_map[sale_pk] = set(subcategories.values_list("pk", flat=True))return subcategory_mapdef fetch_collections(sale_pks: Iterable[str],+ lines_info: Iterable["CheckoutLineInfo"] = [],database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,) -> Dict[int, Set[int]]:- collections = (- Sale.collections.through.objects.using(database_connection_name)- .filter(sale_id__in=sale_pks)- .order_by("id")- .values_list("sale_id", "collection_id")- )+ collections = Sale.collections.through.objects.using(+ database_connection_name+ ).filter(sale_id__in=sale_pks)++ if lines_info:+ collection_pks = [+ collection.pk+ for line_info in lines_info+ for collection in line_info.collections+ ]+ collections = collections.filter(collection_id__in=collection_pks)+collection_map: Dict[int, Set[int]] = defaultdict(set)- for sale_pk, collection_pk in collections:+ for sale_pk, collection_pk in collections.order_by("id").values_list(+ "sale_id", "collection_id"+ ):collection_map[sale_pk].add(collection_pk)return collection_mapdef fetch_products(sale_pks: Iterable[str],+ lines_info: Iterable["CheckoutLineInfo"] = [],database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,) -> Dict[int, Set[int]]:- products = (- Sale.products.through.objects.using(database_connection_name)- .filter(sale_id__in=sale_pks)- .order_by("id")- .values_list("sale_id", "product_id")+ product_qs = Sale.products.through.objects.using(database_connection_name).filter(+ sale_id__in=sale_pks)++ if lines_info:+ product_pks = [line_info.product.pk for line_info in lines_info]+ product_qs = product_qs.filter(product_id__in=product_pks)+product_map: Dict[int, Set[int]] = defaultdict(set)- for sale_pk, product_pk in products:+ for sale_pk, product_pk in product_qs.order_by("id").values_list(+ "sale_id", "product_id"+ ):product_map[sale_pk].add(product_pk)return product_mapdef fetch_variants(sale_pks: Iterable[str],+ lines_info: Iterable["CheckoutLineInfo"] = [],database_connection_name: str = settings.DATABASE_CONNECTION_DEFAULT_NAME,) -> Dict[int, Set[int]]:- variants = (- Sale.variants.through.objects.using(database_connection_name)- .filter(sale_id__in=sale_pks)- .order_by("id")- .values_list("sale_id", "productvariant_id")+ variant_qs = Sale.variants.through.objects.using(database_connection_name).filter(+ sale_id__in=sale_pks)++ if lines_info:+ variant_pks = [line_info.variant.pk for line_info in lines_info]+ variant_qs = variant_qs.filter(productvariant_id__in=variant_pks)+variants_map: Dict[int, Set[int]] = defaultdict(set)- for sale_pk, variant_pk in variants:+ for sale_pk, variant_pk in variant_qs.order_by("id").values_list(+ "sale_id", "productvariant_id"+ ):variants_map[sale_pk].add(variant_pk)return variants_map@@ -412,3 +440,280 @@ def apply_discount_to_value(**discount_kwargs,)return discount(price_to_discount)+++def fetch_active_sales_for_checkout(+ lines_info: Iterable["CheckoutLineInfo"],+) -> Iterable[DiscountInfo]:+ """Return list of `DiscountInfo` applicable for list of `CheckoutLineInfo`.++ Return list of `DiscountInfo` applicable for list of `CheckoutLineInfo`.+ This function returns only a list of `DiscountInfo` for `Sale` which+ are able to be applied on specified lines. When the function receives empty+ lines in input we return an empty list of applicable `DiscountInfo`.+ """+ if not lines_info:+ return []++ sales = list(Sale.objects.active(timezone.now()))++ pks = {s.pk for s in sales}+ channel_listings = fetch_sale_channel_listings(pks)+ product_pks_by_sale_pk_map = fetch_products(pks, lines_info)+ variant_pks_by_sale_pk_map = fetch_variants(pks, lines_info)+ category_pks_by_sale_pk_map = fetch_categories(pks, lines_info)+ collection_pks_by_sale_pk_map = fetch_collections(pks, lines_info)++ discounts_info = []+ for sale in sales:+ category_ids = category_pks_by_sale_pk_map[sale.pk]+ collection_ids = collection_pks_by_sale_pk_map[sale.pk]+ product_ids = product_pks_by_sale_pk_map[sale.pk]+ variants_ids = variant_pks_by_sale_pk_map[sale.pk]+ if category_ids or collection_ids or product_ids or variants_ids:+ discounts_info.append(+ DiscountInfo(+ sale=sale,+ category_ids=category_ids,+ channel_listings=channel_listings[sale.pk],+ collection_ids=collection_ids,+ product_ids=product_ids,+ variants_ids=variants_ids,+ )+ )++ return discounts_info+++def is_sale_applicable_on_line(+ line_info: "CheckoutLineInfo",+ discount: DiscountInfo,+) -> bool:+ collection_ids = set(collection.id for collection in line_info.collections)+ is_product_on_sale = line_info.product.id in discount.product_ids+ is_variant_on_sale = line_info.variant.id in discount.variants_ids+ is_category_on_sale = line_info.product.category_id in discount.category_ids+ is_collection_on_sale = bool(collection_ids.intersection(discount.collection_ids))+ return (+ is_product_on_sale+ or is_variant_on_sale+ or is_category_on_sale+ or is_collection_on_sale+ )+++def _apply_percentage_sale_on_lines(+ lines_info: Iterable["CheckoutLineInfo"],+ sale_info: DiscountInfo,+ sales_data_by_line_map: Dict[UUID, dict],+ currency_precision: Decimal,+):+ """Calculate discount amounts for percentage sales.++ This function calculates the discount amount for the sale. If the calculated+ discount amount is greater than the currently applied discount, the function+ saves the sale as the best sale for the calculated lines. All data are stored+ in the `sales_data_by_line_map`.+ """+ sale = sale_info.sale+ qualified_lines = []+ base_line_total_price_by_line_id_map = defaultdict(Decimal)+ remaining_total_amount = Decimal(0)+ for line_info in lines_info:+ if is_sale_applicable_on_line(line_info, sale_info):+ qualified_lines.append(line_info)+ line = line_info.line+ quantity = line.quantity+ base_unit_price = line_info.variant.get_base_price(+ line_info.channel_listing, line.price_override+ )+ base_unit_price = cast(Money, base_unit_price)+ base_line_total_price = base_unit_price * quantity+ base_line_total_amount = base_line_total_price.amount++ remaining_total_amount += base_line_total_amount+ base_line_total_price_by_line_id_map[line.id] = base_line_total_amount++ sale_channel_listing = sale_info.channel_listings.get(line_info.channel.slug)+ if sale_channel_listing and remaining_total_amount != Decimal(0):+ currency = sale_channel_listing.currency+ discounted_amount = apply_discount_to_value(+ sale_channel_listing.discount_value,+ sale.type,+ currency,+ Money(remaining_total_amount, currency),+ ).amount+ remaining_discount_amount = remaining_total_amount - discounted_amount+ for line_info in qualified_lines:+ line = line_info.line+ base_line_total_amount = base_line_total_price_by_line_id_map[line.pk]+ line_discount_amount = Decimal(+ base_line_total_amount+ * remaining_discount_amount+ / remaining_total_amount+ ).quantize(currency_precision, ROUND_HALF_UP)+ remaining_discount_amount -= line_discount_amount+ remaining_total_amount -= base_line_total_amount+ if (+ sales_data_by_line_map[line.id].get(+ "best_discount_amount",+ Decimal("-Inf"),+ )+ < line_discount_amount+ ):+ sales_data_by_line_map[line.id] = {+ "sale": sale,+ "sale_channel_listing": sale_channel_listing,+ "best_discount_amount": line_discount_amount,+ }+++def _apply_fixed_sale_on_lines(+ lines_info: Iterable["CheckoutLineInfo"],+ sale_info: DiscountInfo,+ sales_data_by_line_map: Dict[UUID, dict],+):+ """Calculate discount amounts for for fixed sales.++ This function calculates the discount amount for the sale. If the calculated+ discount amount is greater than the currently applied discount, the function+ saves the sale as the best sale for the calculated lines. All data are stored+ in the `sales_data_by_line_map`.+ """+ sale = sale_info.sale+ for line_info in lines_info:+ if is_sale_applicable_on_line(line_info, sale_info):+ line = line_info.line+ quantity = line.quantity+ base_unit_price = line_info.variant.get_base_price(+ line_info.channel_listing, line.price_override+ )+ base_unit_price = cast(Money, base_unit_price)++ channel_listing = sale_info.channel_listings.get(line_info.channel.slug)+ if not channel_listing:+ continue+ unit_price_with_applied_sale = apply_discount_to_value(+ channel_listing.discount_value,+ sale.type,+ channel_listing.currency,+ base_unit_price,+ )+ unit_price_with_applied_sale = cast(Money, unit_price_with_applied_sale)+ unit_discount = min(+ base_unit_price - unit_price_with_applied_sale,+ base_unit_price,+ )+ total_discount = unit_discount * quantity+ discount_amount = total_discount.amount+ if (+ sales_data_by_line_map[line.id].get(+ "best_discount_amount", Decimal("-Inf")+ )+ < discount_amount+ ):+ sales_data_by_line_map[line.id] = {+ "sale": sale,+ "sale_channel_listing": channel_listing,+ "best_discount_amount": discount_amount,+ }+++def create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info: "CheckoutInfo",+ lines_info: Iterable["CheckoutLineInfo"],+ sales_info: Iterable[DiscountInfo],+):+ line_discounts_to_create = []+ line_discounts_to_update = []+ updated_fields = []++ currency_precision = Decimal("0.1") ** get_currency_precision(+ checkout_info.checkout.currency+ )++ sales_data_by_line_map: Dict[UUID, dict] = defaultdict(dict)++ for sale_info in sales_info:+ if sale_info.sale.type == DiscountValueType.FIXED:+ _apply_fixed_sale_on_lines(lines_info, sale_info, sales_data_by_line_map)++ else:+ _apply_percentage_sale_on_lines(+ lines_info, sale_info, sales_data_by_line_map, currency_precision+ )++ for line_info in lines_info:+ line = line_info.line+ sale = sales_data_by_line_map[line.id].get("sale")+ sale_channel_listing = sales_data_by_line_map[line.id].get(+ "sale_channel_listing"+ )+ discount_amount = sales_data_by_line_map[line.id].get("best_discount_amount")++ if sale and sale_channel_listing and discount_amount:+ sale = cast(Sale, sale)+ sale_channel_listing = cast(SaleChannelListing, sale_channel_listing)++ # Fetch Sale translation+ translation_language_code = checkout_info.checkout.language_code+ sale_translation = SaleTranslation.objects.filter(+ sale_id=sale.pk, language_code=translation_language_code+ ).first()+ translated_name = None+ if sale_translation:+ translated_name = sale_translation.name+ discount_to_update = line_info.get_sale_discount()+ if not discount_to_update:+ line_discount = CheckoutLineDiscount(+ line=line,+ type=DiscountType.SALE,+ value_type=sale.type,+ value=sale_channel_listing.discount_value,+ amount_value=discount_amount,+ currency=line.currency,+ name=sale.name,+ translated_name=translated_name,+ reason=None,+ sale=sale,+ )+ line_discounts_to_create.append(line_discount)+ line_info.discounts.append(line_discount)+ else:+ if discount_to_update.value_type != sale.type:+ discount_to_update.value_type = sale.type+ updated_fields.append("value_type")+ if discount_to_update.value != sale_channel_listing.discount_value:+ discount_to_update.value = sale_channel_listing.discount_value+ updated_fields.append("value")+ if discount_to_update.amount_value != discount_amount:+ discount_to_update.amount_value = discount_amount+ updated_fields.append("amount_value")+ if discount_to_update.name != sale.name:+ discount_to_update.name = sale.name+ updated_fields.append("name")+ if discount_to_update.translated_name != translated_name:+ discount_to_update.translated_name = translated_name+ updated_fields.append("translated_name")+ if discount_to_update.sale != sale:+ discount_to_update.sale = sale+ updated_fields.append("sale")++ line_discounts_to_update.append(discount_to_update)++ if line_discounts_to_create:+ CheckoutLineDiscount.objects.bulk_create(line_discounts_to_create)+ if line_discounts_to_update and updated_fields:+ CheckoutLineDiscount.objects.bulk_update(+ line_discounts_to_update, updated_fields+ )+++def generate_sale_discount_objects_for_checkout(+ checkout_info: "CheckoutInfo",+ lines_info: Iterable["CheckoutLineInfo"],+):+ sales_info = fetch_active_sales_for_checkout(lines_info)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines_info, sales_info+ )diff --git a/saleor/graphql/channel/dataloaders.py b/saleor/graphql/channel/dataloaders.pyindex 4fe22a5ad4..8fa985bee0 100644--- a/saleor/graphql/channel/dataloaders.py+++ b/saleor/graphql/channel/dataloaders.py@@ -2,7 +2,6 @@ from django.db.models import Exists, OuterReffrom ...channel.models import Channelfrom ...order.models import Order-from ..checkout.dataloaders import CheckoutByTokenLoader, CheckoutLineByIdLoaderfrom ..core.dataloaders import DataLoaderfrom ..order.dataloaders import OrderByIdLoader, OrderLineByIdLoader@@ -25,29 +24,6 @@ class ChannelBySlugLoader(DataLoader):return [channels.get(slug) for slug in keys]-class ChannelByCheckoutLineIDLoader(DataLoader):- context_key = "channel_by_checkout_line"-- def batch_load(self, keys):- def channel_by_lines(checkout_lines):- checkout_ids = [line.checkout_id for line in checkout_lines]-- def channels_by_checkout(checkouts):- channel_ids = [checkout.channel_id for checkout in checkouts]-- return ChannelByIdLoader(self.context).load_many(channel_ids)-- return (- CheckoutByTokenLoader(self.context)- .load_many(checkout_ids)- .then(channels_by_checkout)- )-- return (- CheckoutLineByIdLoader(self.context).load_many(keys).then(channel_by_lines)- )--class ChannelByOrderLineIdLoader(DataLoader):context_key = "channel_by_orderline"diff --git a/saleor/graphql/checkout/dataloaders.py b/saleor/graphql/checkout/dataloaders.pyindex f12fb35157..24c53b076a 100644--- a/saleor/graphql/checkout/dataloaders.py+++ b/saleor/graphql/checkout/dataloaders.py@@ -15,11 +15,12 @@ from ...checkout.models import Checkout, CheckoutLine, CheckoutMetadatafrom ...discount import VoucherTypefrom ...payment.models import TransactionItemfrom ..account.dataloaders import AddressByIdLoader, UserByUserIdLoader+from ..channel.dataloaders import ChannelByIdLoaderfrom ..core.dataloaders import DataLoaderfrom ..discount.dataloaders import (+ CheckoutLineDiscountsByCheckoutLineIdLoader,VoucherByCodeLoader,VoucherInfoByVoucherCodeLoader,- load_discounts,)from ..plugins.dataloaders import get_plugin_manager_promisefrom ..product.dataloaders import (@@ -51,9 +52,15 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineIndef batch_load(self, keys):def with_checkout_lines(results):checkouts, checkout_lines = results- variants_pks = list(- {line.variant_id for lines in checkout_lines for line in lines}- )++ variants_pks = set()+ lines_pks = set()+ for lines in checkout_lines:+ for line in lines:+ lines_pks.add(line.id)+ variants_pks.add(line.variant_id)+ lines_pks = list(lines_pks)+ variants_pks = list(variants_pks)if not variants_pks:return [[] for _ in keys]@@ -68,6 +75,8 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineIntax_classes,channel_listings,voucher_infos,+ channels,+ checkout_lines_discounts,) = resultsvariants_map = dict(zip(variants_pks, variants))products_map = dict(zip(variants_pks, products))@@ -77,6 +86,10 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineInchannel_listings_map = dict(zip(variant_ids_channel_ids, channel_listings))+ channels = dict(zip(channel_pks, channels))+ checkout_lines_discounts = dict(+ zip(lines_pks, checkout_lines_discounts)+ )lines_info_map = defaultdict(list)voucher_infos_map = {@@ -96,7 +109,9 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineInproduct=products_map[line.variant_id],product_type=product_types_map[line.variant_id],collections=collections_map[line.variant_id],+ discounts=checkout_lines_discounts[line.id],tax_class=tax_class_map[line.variant_id],+ channel=channels[checkout.channel_id],)for line in lines]@@ -113,15 +128,16 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineInvoucher.type == VoucherType.SPECIFIC_PRODUCTor voucher.apply_once_per_order):- discounts = load_discounts(self.context)apply_voucher_to_checkout_line(voucher_info=voucher_info,checkout=checkout,lines_info=lines_info_map[checkout.pk],- discounts=discounts,)return [lines_info_map[key] for key in keys]+ checkout_lines_discounts = CheckoutLineDiscountsByCheckoutLineIdLoader(+ self.context+ ).load_many(lines_pks)variants = ProductVariantByIdLoader(self.context).load_many(variants_pks)products = ProductByVariantIdLoader(self.context).load_many(variants_pks)product_types = ProductTypeByVariantIdLoader(self.context).load_many(@@ -150,6 +166,8 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineInchannel_listings = VariantChannelListingByVariantIdAndChannelIdLoader(self.context).load_many(variant_ids_channel_ids)++ channels = ChannelByIdLoader(self.context).load_many(channel_pks)return Promise.all([variants,@@ -159,6 +177,8 @@ class CheckoutLinesInfoByCheckoutTokenLoader(DataLoader[str, List[CheckoutLineIntax_classes,channel_listings,voucher_infos,+ channels,+ checkout_lines_discounts,]).then(with_variants_products_collections)@@ -323,7 +343,6 @@ class CheckoutInfoByCheckoutTokenLoader(DataLoader[str, CheckoutInfo]):all_shipping_methods=[],voucher=voucher,)- discounts = load_discounts(self.context)shipping_method_listings = [listingfor channel_listings in listings_for_channels@@ -336,7 +355,6 @@ class CheckoutInfoByCheckoutTokenLoader(DataLoader[str, CheckoutInfo]):collection_point,shipping_address,checkout_lines,- discounts,manager,shipping_method_listings,)@@ -418,3 +436,26 @@ class CheckoutMetadataByCheckoutIdLoader(DataLoader[str, CheckoutMetadata]):self.database_connection_name).in_bulk(keys, field_name="checkout_id")return [checkout_metadata.get(checkout_id) for checkout_id in keys]+++class ChannelByCheckoutLineIDLoader(DataLoader):+ context_key = "channel_by_checkout_line"++ def batch_load(self, keys):+ def channel_by_lines(checkout_lines):+ checkout_ids = [line.checkout_id for line in checkout_lines]++ def channels_by_checkout(checkouts):+ channel_ids = [checkout.channel_id for checkout in checkouts]++ return ChannelByIdLoader(self.context).load_many(channel_ids)++ return (+ CheckoutByTokenLoader(self.context)+ .load_many(checkout_ids)+ .then(channels_by_checkout)+ )++ return (+ CheckoutLineByIdLoader(self.context).load_many(keys).then(channel_by_lines)+ )diff --git a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py b/saleor/graphql/checkout/mutations/checkout_add_promo_code.pyindex 8156a2dc04..0aead36ff0 100644--- a/saleor/graphql/checkout/mutations/checkout_add_promo_code.py+++ b/saleor/graphql/checkout/mutations/checkout_add_promo_code.py@@ -14,7 +14,6 @@ from ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ..types import Checkoutfrom .utils import get_checkout, update_checkout_shipping_method_if_invalid@@ -60,12 +59,11 @@ class CheckoutAddPromoCode(BaseMutation):checkout_id=None,id=None,promo_code,- token=None+ token=None,):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)lines, unavailable_variant_pks = fetch_checkout_lines(checkout)if unavailable_variant_pks:@@ -85,7 +83,7 @@ class CheckoutAddPromoCode(BaseMutation):shipping_channel_listings = checkout.channel.shipping_method_listings.all()checkout_info = fetch_checkout_info(- checkout, lines, discounts, manager, shipping_channel_listings+ checkout, lines, manager, shipping_channel_listings)add_promo_code_to_checkout(@@ -93,7 +91,6 @@ class CheckoutAddPromoCode(BaseMutation):checkout_info,lines,promo_code,- discounts,)update_delivery_method_lists_for_checkout_info(@@ -102,7 +99,6 @@ class CheckoutAddPromoCode(BaseMutation):checkout_info.checkout.collection_point,checkout_info.shipping_address,lines,- discounts,manager,shipping_channel_listings,)@@ -112,7 +108,6 @@ class CheckoutAddPromoCode(BaseMutation):checkout_info,lines,manager,- discounts,recalculate_discount=False,save=True,)diff --git a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py b/saleor/graphql/checkout/mutations/checkout_billing_address_update.pyindex 5775cdbdd9..d7751901c7 100644--- a/saleor/graphql/checkout/mutations/checkout_billing_address_update.py+++ b/saleor/graphql/checkout/mutations/checkout_billing_address_update.py@@ -13,7 +13,6 @@ from ...core.descriptions import ADDED_IN_34, ADDED_IN_35, DEPRECATED_IN_3X_INPUfrom ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ..types import Checkoutfrom .checkout_create import CheckoutAddressValidationRules@@ -90,13 +89,11 @@ class CheckoutBillingAddressUpdate(CheckoutShippingAddressUpdate):checkout, billing_address)lines, _ = fetch_checkout_lines(checkout)- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)invalidate_prices_updated_fields = invalidate_checkout_prices(checkout_info,lines,manager,- discounts,recalculate_discount=False,save=False,)diff --git a/saleor/graphql/checkout/mutations/checkout_complete.py b/saleor/graphql/checkout/mutations/checkout_complete.pyindex 178b313213..ce4a5c9bd3 100644--- a/saleor/graphql/checkout/mutations/checkout_complete.py+++ b/saleor/graphql/checkout/mutations/checkout_complete.py@@ -30,7 +30,6 @@ from ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError, NonNullListfrom ...core.validators import validate_one_of_args_is_in_mutation-from ...discount.dataloaders import load_discountsfrom ...meta.mutations import MetadataInputfrom ...order.types import Orderfrom ...plugins.dataloaders import get_plugin_manager_promise@@ -251,8 +250,7 @@ class CheckoutComplete(BaseMutation, I18nMixin):)})- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)cls.validate_checkout_addresses(checkout_info, lines)@@ -272,7 +270,6 @@ class CheckoutComplete(BaseMutation, I18nMixin):lines=lines,payment_data=payment_data or {},store_source=store_source,- discounts=discounts,user=customer,app=get_app_promise(info.context).get(),site_settings=site.settings,diff --git a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.pyindex 1b08a0164d..81d177d169 100644--- a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py+++ b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py@@ -17,7 +17,6 @@ from ....checkout.utils import (is_shipping_required,set_external_shipping_id,)-from ....discount import DiscountInfofrom ....plugins.webhook.utils import APP_ID_PREFIXfrom ....shipping import interface as shipping_interfacefrom ....shipping import models as shipping_models@@ -30,7 +29,6 @@ from ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutErrorfrom ...core.utils import from_global_id_or_error-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...shipping.types import ShippingMethodfrom ...warehouse.types import Warehouse@@ -103,12 +101,10 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):checkout_info, lines, shipping_method=delivery_method, collection_point=None)- discounts = load_discounts(info.context)cls._update_delivery_method(manager,checkout_info,lines,- discounts,shipping_method=shipping_method,external_shipping_method=None,collection_point=None,@@ -145,12 +141,10 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):checkout_info, lines, shipping_method=delivery_method, collection_point=None)- discounts = load_discounts(info.context)cls._update_delivery_method(manager,checkout_info,lines,- discounts,shipping_method=None,external_shipping_method=delivery_method,collection_point=None,@@ -180,12 +174,10 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):shipping_method=None,collection_point=collection_point,)- discounts = load_discounts(info.context)cls._update_delivery_method(manager,checkout_info,lines,- discounts,shipping_method=None,external_shipping_method=None,collection_point=collection_point,@@ -198,7 +190,7 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):lines,*,shipping_method: Optional[shipping_interface.ShippingMethodData],- collection_point: Optional[Warehouse]+ collection_point: Optional[Warehouse],) -> None:delivery_method = shipping_methoderror_msg = "This shipping method is not applicable."@@ -226,11 +218,10 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):manager,checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Iterable["DiscountInfo"],*,shipping_method: Optional[ShippingMethod],external_shipping_method: Optional[shipping_interface.ShippingMethodData],- collection_point: Optional[Warehouse]+ collection_point: Optional[Warehouse],) -> None:checkout = checkout_info.checkoutif external_shipping_method:@@ -242,7 +233,7 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):checkout.shipping_method = shipping_methodcheckout.collection_point = collection_pointinvalidate_prices_updated_fields = invalidate_checkout_prices(- checkout_info, lines, manager, discounts or [], save=False+ checkout_info, lines, manager, save=False)checkout.save(update_fields=[@@ -315,8 +306,7 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):)type_name = cls._resolve_delivery_method_type(delivery_method_id)- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)if type_name == "Warehouse":return cls.perform_on_collection_point(info, delivery_method_id, checkout_info, lines, checkout, managerdiff --git a/saleor/graphql/checkout/mutations/checkout_line_delete.py b/saleor/graphql/checkout/mutations/checkout_line_delete.pyindex f9545731df..f93cc82f1b 100644--- a/saleor/graphql/checkout/mutations/checkout_line_delete.py+++ b/saleor/graphql/checkout/mutations/checkout_line_delete.py@@ -8,7 +8,6 @@ from ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ..types import Checkout, CheckoutLinefrom .utils import get_checkout, update_checkout_shipping_method_if_invalid@@ -50,7 +49,7 @@ class CheckoutLineDelete(BaseMutation):checkout_id=None,id=None,line_id,- token=None+ token=None,):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)@@ -63,10 +62,9 @@ class CheckoutLineDelete(BaseMutation):manager = get_plugin_manager_promise(info.context).get()lines, _ = fetch_checkout_lines(checkout)- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)update_checkout_shipping_method_if_invalid(checkout_info, lines)- invalidate_checkout_prices(checkout_info, lines, manager, discounts, save=True)+ invalidate_checkout_prices(checkout_info, lines, manager, save=True)cls.call_event(manager.checkout_updated, checkout)return CheckoutLineDelete(checkout=checkout)diff --git a/saleor/graphql/checkout/mutations/checkout_lines_add.py b/saleor/graphql/checkout/mutations/checkout_lines_add.pyindex 8a672e23bf..edbf7ea4f8 100644--- a/saleor/graphql/checkout/mutations/checkout_lines_add.py+++ b/saleor/graphql/checkout/mutations/checkout_lines_add.py@@ -18,7 +18,6 @@ from ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError, NonNullListfrom ...core.validators import validate_variants_available_in_channel-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...product.types import ProductVariantfrom ...site.dataloaders import get_site_promise@@ -108,7 +107,6 @@ class CheckoutLinesAdd(BaseMutation):checkout_info,lines,manager,- discounts,replace,):channel_slug = checkout_info.channel.slug@@ -165,7 +163,6 @@ class CheckoutLinesAdd(BaseMutation):checkout_info.checkout.collection_point,checkout_info.shipping_address,lines,- discounts,manager,shipping_channel_listings,)@@ -189,11 +186,10 @@ class CheckoutLinesAdd(BaseMutation):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)variants = cls._get_variants_from_lines_input(lines)shipping_channel_listings = checkout.channel.shipping_method_listings.all()checkout_info = fetch_checkout_info(- checkout, [], discounts, manager, shipping_channel_listings+ checkout, [], manager, shipping_channel_listings)existing_lines_info, _ = fetch_checkout_lines(@@ -209,11 +205,10 @@ class CheckoutLinesAdd(BaseMutation):checkout_info,existing_lines_info,manager,- discounts,replace,)update_checkout_shipping_method_if_invalid(checkout_info, lines)- invalidate_checkout_prices(checkout_info, lines, manager, discounts, save=True)+ invalidate_checkout_prices(checkout_info, lines, manager, save=True)cls.call_event(manager.checkout_updated, checkout)return CheckoutLinesAdd(checkout=checkout)diff --git a/saleor/graphql/checkout/mutations/checkout_lines_delete.py b/saleor/graphql/checkout/mutations/checkout_lines_delete.pyindex 64b2e2c9cd..f009f4b26b 100644--- a/saleor/graphql/checkout/mutations/checkout_lines_delete.py+++ b/saleor/graphql/checkout/mutations/checkout_lines_delete.py@@ -9,7 +9,6 @@ from ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError, NonNullList-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...utils import resolve_global_ids_to_primary_keysfrom ..types import Checkout@@ -76,10 +75,9 @@ class CheckoutLinesDelete(BaseMutation):lines, _ = fetch_checkout_lines(checkout)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)update_checkout_shipping_method_if_invalid(checkout_info, lines)- invalidate_checkout_prices(checkout_info, lines, manager, discounts, save=True)+ invalidate_checkout_prices(checkout_info, lines, manager, save=True)cls.call_event(manager.checkout_updated, checkout)return CheckoutLinesDelete(checkout=checkout)diff --git a/saleor/graphql/checkout/mutations/checkout_lines_update.py b/saleor/graphql/checkout/mutations/checkout_lines_update.pyindex 7248a5f208..b36068dd9f 100644--- a/saleor/graphql/checkout/mutations/checkout_lines_update.py+++ b/saleor/graphql/checkout/mutations/checkout_lines_update.py@@ -132,7 +132,6 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):checkout_info,lines,manager,- discounts,replace,):app = get_app_promise(info.context).get()@@ -161,7 +160,6 @@ class CheckoutLinesUpdate(CheckoutLinesAdd):checkout_info,lines,manager,- discounts,replace,)diff --git a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.pyindex 2eec2f42c9..78e318ce19 100644--- a/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py+++ b/saleor/graphql/checkout/mutations/checkout_remove_promo_code.py@@ -20,7 +20,6 @@ from ...core.scalars import UUIDfrom ...core.types import CheckoutErrorfrom ...core.utils import from_global_id_or_errorfrom ...core.validators import validate_one_of_args_is_in_mutation-from ...discount.dataloaders import load_discountsfrom ...discount.types import Voucherfrom ...giftcard.types import GiftCardfrom ...plugins.dataloaders import get_plugin_manager_promise@@ -83,8 +82,7 @@ class CheckoutRemovePromoCode(BaseMutation):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)removed = Falseif promo_code:@@ -100,7 +98,6 @@ class CheckoutRemovePromoCode(BaseMutation):checkout_info,lines,manager,- discounts,recalculate_discount=False,save=True,)diff --git a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.pyindex 0f58f78f8b..6e50383d5d 100644--- a/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/mutations/checkout_shipping_address_update.py@@ -24,7 +24,6 @@ from ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutError-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...site.dataloaders import get_site_promisefrom ..types import Checkout@@ -151,10 +150,9 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):),)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)shipping_channel_listings = checkout.channel.shipping_method_listings.all()checkout_info = fetch_checkout_info(- checkout, lines, discounts, manager, shipping_channel_listings+ checkout, lines, manager, shipping_channel_listings)country = shipping_address_instance.country.code@@ -179,12 +177,11 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):checkout_info,shipping_address_instance,lines,- discounts,manager,shipping_channel_listings,)invalidate_prices_updated_fields = invalidate_checkout_prices(- checkout_info, lines, manager, discounts, save=False+ checkout_info, lines, manager, save=False)checkout.save(update_fields=shipping_address_updated_fieldsdiff --git a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.pyindex 2c8ca799e2..ac39680f83 100644--- a/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py+++ b/saleor/graphql/checkout/mutations/checkout_shipping_method_update.py@@ -23,7 +23,6 @@ from ...core.mutations import BaseMutationfrom ...core.scalars import UUIDfrom ...core.types import CheckoutErrorfrom ...core.utils import from_global_id_or_error-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promisefrom ...shipping.types import ShippingMethodfrom ..types import Checkout@@ -87,7 +86,7 @@ class CheckoutShippingMethodUpdate(BaseMutation):checkout_id=None,id=None,shipping_method_id,- token=None+ token=None,):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)@@ -108,8 +107,7 @@ class CheckoutShippingMethodUpdate(BaseMutation):)})- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)if not is_shipping_required(lines):raise ValidationError({@@ -192,9 +190,8 @@ class CheckoutShippingMethodUpdate(BaseMutation):delete_external_shipping_id(checkout=checkout)checkout.shipping_method = shipping_method- discounts = load_discounts(info.context)invalidate_prices_updated_fields = invalidate_checkout_prices(- checkout_info, lines, manager, discounts, save=False+ checkout_info, lines, manager, save=False)checkout.save(update_fields=[@@ -229,9 +226,8 @@ class CheckoutShippingMethodUpdate(BaseMutation):set_external_shipping_id(checkout=checkout, app_shipping_id=delivery_method.id)checkout.shipping_method = None- discounts = load_discounts(info.context)invalidate_prices_updated_fields = invalidate_checkout_prices(- checkout_info, lines, manager, discounts, save=False+ checkout_info, lines, manager, save=False)checkout.save(update_fields=[diff --git a/saleor/graphql/checkout/mutations/order_create_from_checkout.py b/saleor/graphql/checkout/mutations/order_create_from_checkout.pyindex 4a20944027..781f328d99 100644--- a/saleor/graphql/checkout/mutations/order_create_from_checkout.py+++ b/saleor/graphql/checkout/mutations/order_create_from_checkout.py@@ -14,7 +14,6 @@ from ...core.descriptions import ADDED_IN_32, ADDED_IN_38from ...core.doc_category import DOC_CATEGORY_CHECKOUTfrom ...core.mutations import BaseMutationfrom ...core.types import Error, NonNullList-from ...discount.dataloaders import load_discountsfrom ...meta.mutations import MetadataInputfrom ...order.types import Orderfrom ...plugins.dataloaders import get_plugin_manager_promise@@ -105,7 +104,7 @@ class OrderCreateFromCheckout(BaseMutation):id,metadata=None,private_metadata=None,- remove_checkout+ remove_checkout,):user = info.context.usercheckout = cls.get_node_or_error(@@ -126,17 +125,13 @@ class OrderCreateFromCheckout(BaseMutation):tracking_code = analytics.get_client_id(info.context)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)checkout_lines, unavailable_variant_pks = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(- checkout, checkout_lines, discounts, manager- )+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)validate_checkout(checkout_info=checkout_info,lines=checkout_lines,unavailable_variant_pks=unavailable_variant_pks,- discounts=discounts,manager=manager,)app = get_app_promise(info.context).get()@@ -144,7 +139,6 @@ class OrderCreateFromCheckout(BaseMutation):order = create_order_from_checkout(checkout_info=checkout_info,checkout_lines=checkout_lines,- discounts=discounts,manager=manager,user=user,app=app,diff --git a/saleor/graphql/checkout/tests/benchmark/conftest.py b/saleor/graphql/checkout/tests/benchmark/conftest.pyindex 5b9450fca7..e62742a130 100644--- a/saleor/graphql/checkout/tests/benchmark/conftest.py+++ b/saleor/graphql/checkout/tests/benchmark/conftest.py@@ -24,7 +24,7 @@ def checkout_with_variants(product_with_single_variant,product_with_two_variants,):- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, product_with_default_variant.variants.get(), 1@@ -129,7 +129,7 @@ def checkout_with_voucher(checkout_with_billing_address, voucher):checkout = checkout_with_billing_addressmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)return checkout@@ -139,7 +139,7 @@ def checkout_with_charged_payment(checkout_with_voucher):checkout = checkout_with_vouchermanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout_with_voucher, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_voucher, lines, manager)manager = get_plugins_manager()taxed_total = calculations.checkout_total(manager=manager,@@ -179,7 +179,7 @@ def checkout_with_digital_line_with_charged_payment(site_settings.automatic_fulfillment_digital_products = Truesite_settings.save(update_fields=["automatic_fulfillment_digital_products"])- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)@@ -215,7 +215,7 @@ def checkout_with_charged_payment_for_cc(checkout_with_billing_address_for_cc):checkout = checkout_with_billing_address_for_ccmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)manager = get_plugins_manager()taxed_total = calculations.checkout_total(manager=manager,@@ -254,7 +254,7 @@ def checkout_preorder_with_charged_payment(checkout = checkout_with_billing_addressmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)add_variant_to_checkout(checkout_info, preorder_variant_channel_threshold, 1)add_variant_to_checkout(checkout_info, preorder_variant_global_threshold, 1)diff --git a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.pyindex babdd90030..40a34d665d 100644--- a/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py+++ b/saleor/graphql/checkout/tests/benchmark/test_checkout_mutations.py@@ -390,7 +390,7 @@ def test_create_checkout_with_reservations(}}- with django_assert_num_queries(66):+ with django_assert_num_queries(68):response = api_client.post_graphql(query, variables)assert get_graphql_content(response)["data"]["checkoutCreate"]assert Checkout.objects.first().lines.count() == 1@@ -408,7 +408,7 @@ def test_create_checkout_with_reservations(}}- with django_assert_num_queries(66):+ with django_assert_num_queries(68):response = api_client.post_graphql(query, variables)assert get_graphql_content(response)["data"]["checkoutCreate"]assert Checkout.objects.first().lines.count() == 10@@ -658,7 +658,7 @@ def test_update_checkout_lines_with_reservations(reservation_length=5,)- with django_assert_num_queries(72):+ with django_assert_num_queries(76):variant_id = graphene.Node.to_global_id("ProductVariant", variants[0].pk)variables = {"id": to_global_id_or_none(checkout),@@ -672,7 +672,7 @@ def test_update_checkout_lines_with_reservations(assert not data["errors"]# Updating multiple lines in checkout has same query count as updating one- with django_assert_num_queries(72):+ with django_assert_num_queries(76):variables = {"id": to_global_id_or_none(checkout),"lines": [],@@ -916,7 +916,7 @@ def test_add_checkout_lines_with_reservations(new_lines.append({"quantity": 2, "variantId": variant_id})# Adding multiple lines to checkout has same query count as adding one- with django_assert_num_queries(71):+ with django_assert_num_queries(75):variables = {"id": Node.to_global_id("Checkout", checkout.pk),"lines": [new_lines[0]],@@ -929,7 +929,7 @@ def test_add_checkout_lines_with_reservations(checkout.lines.exclude(id=line.id).delete()- with django_assert_num_queries(71):+ with django_assert_num_queries(75):variables = {"id": Node.to_global_id("Checkout", checkout.pk),"lines": new_lines,@@ -1055,9 +1055,7 @@ def test_checkout_payment_charge(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_billing_address)- checkout_info = fetch_checkout_info(- checkout_with_billing_address, lines, [], manager- )+ checkout_info = fetch_checkout_info(checkout_with_billing_address, lines, manager)manager = get_plugins_manager()total = calculations.checkout_total(manager=manager,diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.pyindex 6336b99f7e..f80f449cc5 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_complete.py@@ -93,7 +93,7 @@ def test_checkout_complete(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -255,7 +255,7 @@ def test_checkout_complete_for_token_as_input(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.pyindex f783cb3a0c..1ebcff1649 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_line_delete.py@@ -60,7 +60,7 @@ def test_checkout_line_delete_by_id(assert checkout.lines.count() == 0assert calculate_checkout_quantity(lines) == 0manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -92,7 +92,7 @@ def test_checkout_line_delete_by_token(assert checkout.lines.count() == 0assert calculate_checkout_quantity(lines) == 0manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -163,5 +163,5 @@ def test_checkout_line_delete_by_old_line_id(assert checkout.lines.count() == 0assert calculate_checkout_quantity(lines) == 0manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.pyindex db9a4fc7f0..f010a359cd 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_add.py@@ -67,7 +67,7 @@ def test_checkout_lines_add_by_checkout_id(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -108,7 +108,7 @@ def test_checkout_lines_add_by_checkout_token(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.pyindex 28a5ff6e07..343d06910e 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_lines_update.py@@ -72,7 +72,7 @@ def test_checkout_lines_update(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -113,7 +113,7 @@ def test_checkout_lines_update_with_token(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.pyindex 22a1ed2304..1854c9679f 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_address_update.py@@ -68,7 +68,7 @@ def test_checkout_shipping_address_update_by_id(assert checkout.shipping_address.city == shipping_address["city"].upper()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -114,7 +114,7 @@ def test_checkout_shipping_address_update_by_token(assert checkout.shipping_address.city == shipping_address["city"].upper()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)diff --git a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.pyindex fc0a74887f..fefe034680 100644--- a/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py+++ b/saleor/graphql/checkout/tests/deprecated/test_checkout_shipping_method_update.py@@ -61,7 +61,7 @@ def test_checkout_shipping_method_update_by_id(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_info.delivery_method_info = get_delivery_method_info(convert_to_shipping_method_data(old_shipping_method, old_shipping_method.channel_listings.first()@@ -109,7 +109,7 @@ def test_checkout_shipping_method_update_by_token(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_info.delivery_method_info = get_delivery_method_info(convert_to_shipping_method_data(old_shipping_method, old_shipping_method.channel_listings.first()@@ -210,7 +210,7 @@ def test_checkout_shipping_method_update_by_id_no_checkout_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_info.delivery_method_info = get_delivery_method_info(convert_to_shipping_method_data(old_shipping_method, old_shipping_method.channel_listings.first()diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.pyindex c669a4d8c8..1a8111e658 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_add_promo_code.py@@ -12,6 +12,8 @@ from .....checkout.error_codes import CheckoutErrorCodefrom .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....checkout.utils import add_variant_to_checkout, set_external_shipping_idfrom .....discount import VoucherType+from .....discount.models import Sale, SaleChannelListing+from .....discount.utils import generate_sale_discount_objects_for_checkoutfrom .....plugins.manager import get_plugins_managerfrom .....product.models import ProductVariantChannelListingfrom .....warehouse.models import Stock@@ -81,13 +83,12 @@ def test_checkout_add_voucher_for_entire_order(api_client, checkout_with_item, vassert voucher.type == VoucherType.ENTIRE_ORDERmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)taxed_total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout_with_item.shipping_address,- discounts=[],)# when@@ -288,25 +289,34 @@ def test_checkout_add_voucher_code_variant_unavailable(def test_checkout_add_voucher_code_checkout_with_sale(- api_client, checkout_with_item, voucher_percentage, discount_info+ api_client, checkout_with_item, voucher_percentage, product, channel_USD):+ # givenmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)address = checkout_with_item.shipping_address- subtotal = calculations.checkout_subtotal(+ pre_discount_subtotal = calculations.checkout_subtotal(manager=manager, checkout_info=checkout_info, lines=lines, address=address)+ sale = Sale.objects.create(name="Sale")+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ sale.products.add(product)++ # when+ generate_sale_discount_objects_for_checkout(checkout_info, lines)checkout_info.checkout.price_expiration = timezone.now()subtotal_discounted = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=[discount_info],)- assert subtotal > subtotal_discounted- previous_checkout_last_change = checkout_with_item.last_changevariables = {"id": to_global_id_or_none(checkout_with_item),@@ -314,6 +324,10 @@ def test_checkout_add_voucher_code_checkout_with_sale(}data = _mutate_checkout_add_promo_code(api_client, variables)+ # then+ assert pre_discount_subtotal > subtotal_discounted+ previous_checkout_last_change = checkout_with_item.last_change+checkout_with_item.refresh_from_db()assert not data["errors"]assert checkout_with_item.voucher_code == voucher_percentage.code@@ -322,7 +336,7 @@ def test_checkout_add_voucher_code_checkout_with_sale(def test_checkout_add_specific_product_voucher_code_checkout_with_sale(- api_client, checkout_with_item, voucher_specific_product_type, discount_info+ api_client, checkout_with_item, voucher_specific_product_type, product, channel_USD):# givenvoucher = voucher_specific_product_type@@ -330,7 +344,7 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(expected_discount = Decimal(1.5)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -339,13 +353,22 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(address=checkout.shipping_address,)checkout.price_expiration = timezone.now()- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)++ sale = Sale.objects.create(name="Sale")+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ sale.products.add(product)+subtotal_discounted = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert subtotal > subtotal_discounted@@ -365,7 +388,6 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert not data["errors"]assert subtotal_discounted == subtotal_with_voucher + Money(@@ -376,7 +398,7 @@ def test_checkout_add_specific_product_voucher_code_checkout_with_sale(def test_checkout_add_products_voucher_code_checkout_with_sale(- api_client, checkout_with_item, voucher_percentage, discount_info+ api_client, checkout_with_item, voucher_percentage, channel_USD):# givencheckout = checkout_with_item@@ -389,7 +411,7 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -398,14 +420,22 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(address=checkout.shipping_address,)+ sale = Sale.objects.create(name="Sale")+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ sale.products.add(product)+checkout.price_expiration = timezone.now()- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal_discounted = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert subtotal > subtotal_discountedvariables = {@@ -424,7 +454,6 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert not data["errors"]assert subtotal_discounted == subtotal_with_voucher + expected_discount@@ -433,7 +462,7 @@ def test_checkout_add_products_voucher_code_checkout_with_sale(def test_checkout_add_collection_voucher_code_checkout_with_sale(- api_client, checkout_with_item, voucher_percentage, discount_info, collection+ api_client, checkout_with_item, voucher_percentage, collection, channel_USD):# givencheckout = checkout_with_item@@ -447,21 +476,30 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,)++ sale = Sale.objects.create(name="Sale")+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ sale.products.add(product)+checkout.price_expiration = timezone.now()- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal_discounted = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert subtotal > subtotal_discountedvariables = {@@ -480,7 +518,6 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert not data["errors"]@@ -490,11 +527,12 @@ def test_checkout_add_collection_voucher_code_checkout_with_sale(def test_checkout_add_category_code_checkout_with_sale(- api_client, checkout_with_item, voucher_percentage, discount_info+ api_client, checkout_with_item, voucher_percentage, channel_USD):# givencheckout = checkout_with_item- category = checkout.lines.first().variant.product.category+ product = checkout.lines.first().variant.product+ category = product.categoryvoucher = voucher_percentagevoucher.type = VoucherType.SPECIFIC_PRODUCTvoucher.save()@@ -503,7 +541,7 @@ def test_checkout_add_category_code_checkout_with_sale(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -511,14 +549,23 @@ def test_checkout_add_category_code_checkout_with_sale(lines=lines,address=checkout.shipping_address,)++ sale = Sale.objects.create(name="Sale")+ SaleChannelListing.objects.create(+ sale=sale,+ channel=channel_USD,+ discount_value=5,+ currency=channel_USD.currency_code,+ )+ sale.products.add(product)+checkout.price_expiration = timezone.now()- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)subtotal_discounted = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert subtotal > subtotal_discountedvariables = {@@ -537,7 +584,6 @@ def test_checkout_add_category_code_checkout_with_sale(checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[discount_info],)assert not data["errors"]assert subtotal_discounted == subtotal_with_voucher + expected_discount@@ -588,14 +634,13 @@ def test_checkout_add_variant_voucher_code_apply_once_per_order(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout.price_expiration = timezone.now()subtotal_before_voucher = calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=[],)variables = {@@ -609,7 +654,7 @@ def test_checkout_add_variant_voucher_code_apply_once_per_order(# thencheckout.refresh_from_db()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)assert not data["errors"]assert checkout.voucher_code == voucher.codeassert checkout.discount_amount == expected_discount.amount@@ -769,7 +814,7 @@ def test_checkout_add_used_gift_card_code_invalid_user(def test_checkout_get_total_with_gift_card(api_client, checkout_with_item, gift_card):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)taxed_total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -795,7 +840,7 @@ def test_checkout_get_total_with_many_gift_card():manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_gift_card)- checkout_info = fetch_checkout_info(checkout_with_gift_card, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_gift_card, lines, manager)taxed_total = calculations.calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,@@ -929,7 +974,7 @@ def test_checkout_add_promo_code_invalidate_shipping_method(checkout.billing_address = address_usacheckout.save()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())variant = variant_with_many_stocks_different_shipping_zonesadd_variant_to_checkout(checkout_info, variant, 5)checkout.save()@@ -1091,7 +1136,7 @@ def test_checkout_add_voucher_code_invalidates_price(# givenmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)subtotal = base_calculations.base_checkout_subtotal(lines,checkout_info.channel,diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.pyindex 56cdd65f1c..0046f02fcb 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete.py@@ -19,7 +19,8 @@ from .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....checkout.models import Checkoutfrom .....core.exceptions import InsufficientStock, InsufficientStockDatafrom .....core.taxes import TaxError, zero_money, zero_taxed_money-from .....discount import OrderDiscountType+from .....discount import DiscountType, DiscountValueType+from .....discount.models import Sale, SaleChannelListingfrom .....giftcard import GiftCardEventsfrom .....giftcard.models import GiftCard, GiftCardEventfrom .....order import OrderOrigin, OrderStatus@@ -198,14 +199,13 @@ def test_checkout_complete_with_inactive_channel(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=[],)payment = payment_dummypayment.is_active = True@@ -261,7 +261,7 @@ def test_checkout_complete(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -370,7 +370,7 @@ def test_checkout_complete_with_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -447,7 +447,7 @@ def test_checkout_complete_with_metadata_updates_existing_keys(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -511,7 +511,7 @@ def test_checkout_complete_with_metadata_checkout_without_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -584,7 +584,7 @@ def test_checkout_complete_by_app(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -617,7 +617,6 @@ def test_checkout_complete_by_app(lines=ANY,payment_data=ANY,store_source=ANY,- discounts=ANY,user=checkout.user,app=ANY,site_settings=ANY,@@ -649,7 +648,7 @@ def test_checkout_complete_by_app_with_missing_permission(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -682,7 +681,6 @@ def test_checkout_complete_by_app_with_missing_permission(lines=ANY,payment_data=ANY,store_source=ANY,- discounts=ANY,user=None,app=ANY,site_settings=ANY,@@ -720,7 +718,7 @@ def test_checkout_complete_gift_card_bought(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -812,7 +810,7 @@ def test_checkout_complete_with_variant_without_sku(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -948,7 +946,7 @@ def test_checkout_with_voucher_complete(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address@@ -1000,7 +998,7 @@ def test_checkout_with_voucher_complete(voucher_percentage.refresh_from_db()assert voucher_percentage.used == voucher_used_count + 1- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -1052,7 +1050,7 @@ def test_checkout_complete_with_voucher_apply_once_per_order(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address@@ -1104,7 +1102,7 @@ def test_checkout_complete_with_voucher_apply_once_per_order(voucher_percentage.refresh_from_db()assert voucher_percentage.used == voucher_used_count + 1- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -1151,14 +1149,13 @@ def test_checkout_with_voucher_complete_product_on_sale(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=[discount_info],)payment = payment_dummypayment.is_active = True@@ -1200,6 +1197,7 @@ def test_checkout_with_voucher_complete_product_on_sale(assert checkout_line_quantity == order_line.quantityassert checkout_line_variant == order_line.variant+ assert order_line.sale_id == graphene.Node.to_global_id("Sale", sale.id)assert order.shipping_address == addressassert order.shipping_method == checkout.shipping_methodassert order.payments.exists()@@ -1245,7 +1243,7 @@ def test_checkout_with_voucher_on_specific_product_complete(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address@@ -1297,7 +1295,7 @@ def test_checkout_with_voucher_on_specific_product_complete(assert order_payment == paymentassert payment.transactions.count() == 1- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -1315,7 +1313,6 @@ def test_checkout_with_voucher_on_specific_product_complete(def test_checkout_complete_product_on_sale(user_api_client,checkout_with_item,- discount_info,sale,payment_dummy,address,@@ -1337,19 +1334,17 @@ def test_checkout_complete_product_on_sale(checkout_line_quantity = checkout_line.quantitycheckout_line_variant = checkout_line.variant- discount_info.variants_ids.add(checkout_line_variant.id)sale.variants.add(checkout_line_variant)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discount_info, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=[discount_info],)payment = payment_dummypayment.is_active = True@@ -1391,6 +1386,113 @@ def test_checkout_complete_product_on_sale(assert checkout_line_quantity == order_line.quantityassert checkout_line_variant == order_line.variant+ assert order_line.sale_id == graphene.Node.to_global_id("Sale", sale.id)+ assert order.shipping_address == address+ assert order.shipping_method == checkout.shipping_method+ assert order.payments.exists()+ order_payment = order.payments.first()+ assert order_payment == payment+ assert payment.transactions.count() == 1++ assert not Checkout.objects.filter(+ pk=checkout.pk+ ).exists(), "Checkout should have been deleted"+++def test_checkout_complete_product_on_many_sales(+ user_api_client,+ checkout_with_item,+ sale,+ payment_dummy,+ address,+ shipping_method,+):+ # given+ checkout = checkout_with_item+ checkout.shipping_address = address+ checkout.shipping_method = shipping_method+ checkout.billing_address = address+ checkout.metadata_storage.store_value_in_metadata(items={"accepted": "true"})+ checkout.metadata_storage.store_value_in_private_metadata(+ items={"accepted": "false"}+ )+ checkout.save()+ checkout.metadata_storage.save()++ checkout_line = checkout.lines.first()+ checkout_line_quantity = checkout_line.quantity+ checkout_line_variant = checkout_line.variant++ small_sale = Sale.objects.create(type=DiscountValueType.FIXED)+ SaleChannelListing.objects.create(+ sale=small_sale,+ discount_value=1,+ currency=checkout.channel.currency_code,+ channel=checkout.channel,+ )++ small_sale.variants.add(checkout_line_variant)+ sale.variants.add(checkout_line_variant)++ 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=address,+ )+ payment = payment_dummy+ payment.is_active = True+ payment.order = None+ payment.total = total.gross.amount+ payment.currency = total.gross.currency+ payment.checkout = checkout+ payment.save()+ assert not payment.transactions.exists()++ orders_count = Order.objects.count()+ variables = {+ "id": to_global_id_or_none(checkout),+ "redirectUrl": "https://www.example.com",+ }++ # when+ response = user_api_client.post_graphql(MUTATION_CHECKOUT_COMPLETE, variables)++ # then+ content = get_graphql_content(response)+ data = content["data"]["checkoutComplete"]+ assert not data["errors"]++ assert Sale.objects.count() > 1+ assert (+ Sale.variants.through.objects.filter(+ productvariant_id=checkout_line_variant.id+ ).count()+ > 1+ )++ order_token = data["order"]["token"]+ order_id = data["order"]["id"]+ assert Order.objects.count() == orders_count + 1+ order = Order.objects.first()+ assert str(order.id) == order_token+ assert order_id == graphene.Node.to_global_id("Order", order.id)+ assert order.metadata == checkout.metadata_storage.metadata+ assert order.private_metadata == checkout.metadata_storage.private_metadata++ order_line = order.lines.first()+ assert order.total == total+ assert order.undiscounted_total == total + (+ order_line.undiscounted_total_price - order_line.total_price+ )++ assert checkout_line_quantity == order_line.quantity+ assert checkout_line_variant == order_line.variant+ assert order_line.sale_id == graphene.Node.to_global_id("Sale", sale.id)assert order.shipping_address == addressassert order.shipping_method == checkout.shipping_methodassert order.payments.exists()@@ -1407,7 +1509,6 @@ def test_checkout_with_voucher_on_specific_product_complete_with_product_on_saleuser_api_client,checkout_with_item_and_voucher_specific_products,voucher_specific_product_type,- discount_info,sale,payment_dummy,address,@@ -1433,19 +1534,17 @@ def test_checkout_with_voucher_on_specific_product_complete_with_product_on_salecheckout_line_quantity = checkout_line.quantitycheckout_line_variant = checkout_line.variant- discount_info.variants_ids.add(checkout_line_variant.id)sale.variants.add(checkout_line_variant)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discount_info, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=[discount_info],)payment = payment_dummypayment.is_active = True@@ -1487,6 +1586,7 @@ def test_checkout_with_voucher_on_specific_product_complete_with_product_on_saleassert checkout_line_quantity == order_line.quantityassert checkout_line_variant == order_line.variant+ assert order_line.sale_id == graphene.Node.to_global_id("Sale", sale.id)assert order.shipping_address == addressassert order.shipping_method == checkout.shipping_methodassert order.payments.exists()@@ -1575,7 +1675,7 @@ def test_checkout_complete_without_inventory_tracking(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1647,7 +1747,7 @@ def test_checkout_complete_checkout_without_lines(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)assert not lines- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1707,7 +1807,7 @@ def test_checkout_complete_error_in_gateway_response_for_dummy_credit_card(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1783,7 +1883,7 @@ def test_checkout_complete_does_not_delete_checkout_after_unsuccessful_payment(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)taxed_total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1876,7 +1976,7 @@ def test_checkout_complete_confirmation_needed(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1933,7 +2033,7 @@ def test_checkout_confirm(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1980,7 +2080,7 @@ def test_checkout_complete_insufficient_stock(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2028,7 +2128,7 @@ def test_checkout_complete_insufficient_stock_payment_refunded(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2087,7 +2187,7 @@ def test_checkout_complete_insufficient_stock_payment_voided(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2157,7 +2257,7 @@ def test_checkout_complete_insufficient_stock_reserved_by_other_user(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2211,7 +2311,7 @@ def test_checkout_complete_own_reservation(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2276,7 +2376,7 @@ def test_checkout_complete_without_redirect_url(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -2342,7 +2442,7 @@ def test_checkout_complete_payment_payment_total_different_than_checkout(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2415,7 +2515,7 @@ def test_create_order_raises_insufficient_stock(mocked_create_order.side_effect = InsufficientStock([InsufficientStockData(variant=lines[0].variant, available_quantity=0)])- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, checkout.shipping_address)@@ -2461,7 +2561,7 @@ def test_checkout_complete_with_digital(# Create a dummy payment to chargemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2521,7 +2621,7 @@ def test_checkout_complete_0_total_value(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2592,7 +2692,7 @@ def test_complete_checkout_for_local_click_and_collect(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2661,7 +2761,7 @@ def test_complete_checkout_for_global_click_and_collect(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2772,7 +2872,7 @@ def test_comp_checkout_builds_order_for_all_warehouse_even_if_not_available_locamanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2826,7 +2926,7 @@ def test_checkout_complete_raises_InsufficientStock_when_quantity_above_stock_sumanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2873,7 +2973,7 @@ def test_checkout_complete_raises_InvalidShippingMethod_when_warehouse_disabled(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -2923,7 +3023,7 @@ def test_checkout_complete_with_preorder_variant(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3025,7 +3125,7 @@ def test_checkout_complete_with_click_collect_preorder_fails_for_disabled_warehomanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -3080,7 +3180,7 @@ def test_checkout_complete_variant_channel_listing_does_not_exist(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3147,7 +3247,7 @@ def test_checkout_complete_variant_channel_listing_no_price(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3210,7 +3310,7 @@ def test_checkout_complete_product_channel_listing_does_not_exist(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3279,7 +3379,7 @@ def test_checkout_complete_product_channel_listing_not_available_for_purchase(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3338,7 +3438,7 @@ def test_checkout_complete_0_total_value_no_payment(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -3402,7 +3502,7 @@ def test_checkout_complete_0_total_value_from_voucher(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -3463,7 +3563,7 @@ def test_checkout_complete_0_total_value_from_giftcard(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -3525,7 +3625,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_required_manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3586,7 +3686,7 @@ def test_checkout_complete_error_when_shipping_address_doesnt_have_all_valid_fiemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3646,7 +3746,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_required_fmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3706,7 +3806,7 @@ def test_checkout_complete_error_when_billing_address_doesnt_have_all_valid_fielmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3773,7 +3873,7 @@ def test_checkout_complete_with_not_normalized_shipping_address(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3838,7 +3938,7 @@ def test_checkout_complete_with_not_normalized_billing_address(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -3890,7 +3990,7 @@ def test_checkout_complete_check_reservations_create(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -3949,7 +4049,7 @@ def test_checkout_complete_reservations_drop(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -4001,7 +4101,7 @@ def test_checkout_complete_payment_create_create_run_in_meantime(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.pyindex 66093d28ca..9bb3a3540b 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_complete_with_transactions.py@@ -96,7 +96,7 @@ def test_checkout_without_any_transaction(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -140,7 +140,7 @@ def test_checkout_with_total_0(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -205,7 +205,7 @@ def test_checkout_with_authorized(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -301,7 +301,7 @@ def test_checkout_with_charged(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -387,7 +387,7 @@ def test_checkout_paid_with_multiple_transactions(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -448,7 +448,7 @@ def test_checkout_partially_paid(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -499,7 +499,7 @@ def test_checkout_with_pending_charged(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -575,7 +575,7 @@ def test_checkout_with_pending_authorized(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.pyindex 20f9a841a6..120bb6b033 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py@@ -81,7 +81,7 @@ def test_checkout_delivery_method_update(checkout = checkout_with_item_for_ccmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_method_data = delivery_methodif attribute_name == "shipping_method":@@ -153,7 +153,7 @@ def test_checkout_delivery_method_update_no_checkout_metadata(checkout.metadata_storage.delete()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_method_data = delivery_methodif attribute_name == "shipping_method":@@ -477,7 +477,7 @@ def test_checkout_delivery_method_update_with_not_all_required_shipping_address_checkout.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_method_data = delivery_methodif attribute_name == "shipping_method":@@ -552,7 +552,7 @@ def test_checkout_delivery_method_update_with_not_valid_address_data(checkout.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)shipping_method_data = delivery_methodif attribute_name == "shipping_method":diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.pyindex b1320c0706..291a954201 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_line_delete.py@@ -76,7 +76,7 @@ def test_checkout_line_delete(assert calculate_checkout_quantity(lines) == 0assert Reservation.objects.count() == 0manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout_prices.call_count == 1@@ -87,7 +87,7 @@ def test_checkout_lines_delete_with_not_applicable_voucher():manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)subtotal = base_calculations.base_checkout_subtotal(lines,checkout_info.channel,@@ -96,7 +96,7 @@ def test_checkout_lines_delete_with_not_applicable_voucher(voucher.channel_listings.filter(channel=channel_USD).update(min_spent_amount=subtotal.amount)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)assert checkout_with_item.voucher_code == voucher.code@@ -123,7 +123,7 @@ def test_checkout_line_delete_remove_shipping_if_removed_product_with_shipping(checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.save()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, digital_variant, 1)line = checkout.lines.first()diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.pyindex 37d9a33ece..fda38c3938 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_add.py@@ -94,7 +94,7 @@ def test_checkout_lines_add(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout_prices.call_count == 1@@ -238,7 +238,7 @@ def test_checkout_lines_add_only_stock_in_cc_warehouse(assert not Reservation.objects.exists()manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.pyindex 0e297cb9bd..efa1226ace 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_delete.py@@ -73,7 +73,7 @@ def test_checkout_lines_delete(lines_ids = [line["id"] for line in remaining_lines]assert lines_list not in lines_idsmanager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout_prices.call_count == 1diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.pyindex fbd749a559..3882831629 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_lines_update.py@@ -104,7 +104,7 @@ def test_checkout_lines_update(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout_prices.call_count == 1@@ -148,7 +148,7 @@ def test_checkout_lines_update_using_line_id(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_change@@ -195,7 +195,7 @@ def test_checkout_lines_update_using_line_id_and_variant_id(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_change@@ -310,7 +310,7 @@ def test_checkout_lines_update_only_stock_in_cc_warehouse(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_change@@ -509,7 +509,7 @@ def test_checkout_lines_update_other_lines_reservations_expirations(checkout = checkout_line_with_one_reservation.checkoutline = checkout_line_with_one_reservationreservation = line.reservations.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())lines, _ = fetch_checkout_lines(checkout)assert calculate_checkout_quantity(lines) == 2@@ -949,7 +949,7 @@ def test_checkout_line_delete_by_zero_quantity(assert checkout.lines.count() == 0manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_change@@ -985,7 +985,7 @@ def test_checkout_line_delete_by_zero_quantity_when_variant_unavailable_for_purcassert checkout.lines.count() == 0manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)@@ -1021,7 +1021,7 @@ def test_checkout_line_update_by_zero_quantity_dont_create_new_lines(assert checkout.lines.count() == 0manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_change@@ -1112,7 +1112,7 @@ def test_checkout_lines_update_remove_shipping_if_removed_product_with_shipping(checkout.shipping_address = addresscheckout.shipping_method = shipping_methodcheckout.save()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, digital_variant, 1)line = checkout.lines.first()variant = line.variantdiff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.pyindex 4b92793a76..23eb4173c9 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_remove_promo_code.py@@ -276,7 +276,7 @@ def test_checkout_remove_voucher_code_invalidates_price(checkout_with_item.save(update_fields=["voucher_code", "price_expiration"])manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)subtotal = base_calculations.base_checkout_subtotal(lines,checkout_info.channel,diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.pyindex caa4175642..983c9c1cbc 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_address_update.py@@ -96,7 +96,7 @@ def test_checkout_shipping_address_update(assert checkout.shipping_address.city == shipping_address["city"].upper()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.last_change != previous_last_changeassert mocked_invalidate_checkout_prices.call_count == 1@@ -118,7 +118,7 @@ def test_checkout_shipping_address_update_changes_checkout_country(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)assert checkout.shipping_address is Noneprevious_last_change = checkout.last_change@@ -153,7 +153,7 @@ def test_checkout_shipping_address_update_changes_checkout_country(assert checkout.shipping_address.city == shipping_address["city"].upper()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)mocked_update_shipping_method.assert_called_once_with(checkout_info, lines)assert checkout.country == shipping_address["country"]assert checkout.last_change != previous_last_change@@ -175,7 +175,7 @@ def test_checkout_shipping_address_update_insufficient_stocks(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)Stock.objects.filter(warehouse__shipping_zones__countries__contains="US", product_variant=variant@@ -223,7 +223,7 @@ def test_checkout_shipping_address_update_doesnt_raise_error(Stock.objects.filter(product_variant=variant_b).update(quantity=1)checkout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant_b, 1)add_variant_to_checkout(checkout_info, variant_a, 4)assert checkout.shipping_address is None@@ -262,7 +262,7 @@ def test_checkout_shipping_address_update_with_reserved_stocks(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 2)assert checkout.shipping_address is None@@ -313,7 +313,7 @@ def test_checkout_shipping_address_update_against_reserved_stocks(variant = variant_with_many_stocks_different_shipping_zonescheckout = Checkout.objects.create(channel=channel_USD, currency="USD")checkout.set_country("PL", commit=True)- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 2)Stock.objects.filter(warehouse__shipping_zones__countries__contains="US", product_variant=variant@@ -893,7 +893,7 @@ def test_checkout_shipping_address_update_with_not_applicable_voucher(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)assert checkout_with_item.voucher_code == voucher.codediff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.pyindex 318f6275a7..8f36fb1cbf 100644--- a/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_shipping_method_update.py@@ -72,7 +72,7 @@ def test_checkout_shipping_method_update(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_info.delivery_method_info = get_delivery_method_info(convert_to_shipping_method_data(old_shipping_method, old_shipping_method.channel_listings.first()diff --git a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.pyindex bc347149a1..541028c173 100644--- a/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py+++ b/saleor/graphql/checkout/tests/mutations/test_order_create_from_checkout.py@@ -14,7 +14,7 @@ from .....checkout.error_codes import OrderCreateFromCheckoutErrorCodefrom .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....checkout.models import Checkoutfrom .....core.taxes import TaxError, zero_money, zero_taxed_money-from .....discount import OrderDiscountType+from .....discount import DiscountTypefrom .....giftcard import GiftCardEventsfrom .....giftcard.models import GiftCard, GiftCardEventfrom .....order import OrderOrigin, OrderStatus@@ -141,7 +141,7 @@ def test_order_from_checkout(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -324,7 +324,7 @@ def test_order_from_checkout_with_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -394,7 +394,7 @@ def test_order_from_checkout_with_metadata_checkout_without_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -496,7 +496,7 @@ def test_order_from_checkout_gift_card_bought(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)amount = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address@@ -761,7 +761,7 @@ def test_order_from_checkout_with_voucher(assert checkout_line_variant == order_line.variantassert order.shipping_address == addressassert order.shipping_method == checkout.shipping_method- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -837,7 +837,7 @@ def test_order_from_checkout_with_voucher_apply_once_per_order(assert checkout_line_variant == order_line.variantassert order.shipping_address == addressassert order.shipping_method == checkout.shipping_method- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -900,7 +900,7 @@ def test_order_from_checkout_with_specific_product_voucher(assert checkout_line_variant == order_line.variantassert order.shipping_address == addressassert order.shipping_method == checkout.shipping_method- order_discount = order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ order_discount = order.discounts.filter(type=DiscountType.VOUCHER).first()assert order_discountassert (order_discount.amount_value@@ -974,7 +974,7 @@ def test_order_from_checkout_without_inventory_tracking(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1249,7 +1249,7 @@ def test_order_from_checkout_0_total_value(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1462,7 +1462,7 @@ def test_order_from_checkout_raises_invalid_shipping_method_when_warehouse_disabmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)assert not checkout_info.valid_pick_up_pointsassert not checkout_info.delivery_method_info.is_method_in_valid_methods(@@ -1504,7 +1504,7 @@ def test_order_from_draft_create_with_preorder_variant(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1592,7 +1592,7 @@ def test_order_from_draft_create_click_collect_preorder_fails_for_disabled_warehmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)assert not checkout_info.valid_pick_up_pointsassert not checkout_info.delivery_method_info.is_method_in_valid_methods(@@ -1864,7 +1864,7 @@ def test_order_from_draft_create_0_total_value_from_voucher(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -1925,7 +1925,7 @@ def test_order_from_draft_create_0_total_value_from_giftcard(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager=manager, checkout_info=checkout_info, lines=lines, address=address)diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex a2b1ec0b92..af2f2a7142 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -22,6 +22,7 @@ from ....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ....checkout.utils import add_voucher_to_checkoutfrom ....core.prices import quantize_pricefrom ....discount import DiscountValueType, VoucherType+from ....discount.utils import generate_sale_discount_objects_for_checkoutfrom ....payment import TransactionActionfrom ....plugins.manager import get_plugins_managerfrom ....plugins.tests.sample_plugins import ActiveDummyPaymentGateway@@ -53,7 +54,7 @@ def test_clean_delivery_method_after_shipping_address_changes_stay_the_same(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)delivery_method = convert_to_shipping_method_data(shipping_method, shipping_method.channel_listings.first())@@ -69,7 +70,7 @@ def test_clean_delivery_method_with_preorder_is_valid_for_enabled_warehouse(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)is_valid_method = clean_delivery_method(checkout_info, lines, warehouses_for_cc[1])assert is_valid_method is True@@ -84,7 +85,7 @@ def test_clean_delivery_method_does_nothing_if_no_shipping_method(checkout.shipping_address = addressmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)is_valid_method = clean_delivery_method(checkout_info, lines, None)assert is_valid_method is True@@ -107,7 +108,7 @@ def test_update_checkout_shipping_method_if_invalid(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)update_checkout_shipping_method_if_invalid(checkout_info, lines)assert checkout.shipping_method is None@@ -138,7 +139,7 @@ def test_update_checkout_shipping_method_if_invalid_no_checkout_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenupdate_checkout_shipping_method_if_invalid(checkout_info, lines)@@ -553,7 +554,7 @@ def test_checkout_shipping_methods_with_price_based_shipping_method_and_discountcheckout_with_item.shipping_address = addressmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -596,7 +597,7 @@ def test_checkout_shipping_methods_with_price_based_shipping_and_shipping_discoucheckout_with_item.shipping_address = addressmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)subtotal = calculations.checkout_subtotal(manager=manager,@@ -656,7 +657,7 @@ def test_checkout_shipping_methods_with_price_based_method_and_product_voucher(checkout_with_item.save(update_fields=["shipping_address"])- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher)subtotal = calculations.checkout_subtotal(@@ -1493,7 +1494,7 @@ def test_checkout_prices(user_api_client, checkout_with_item):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = calculations.checkout_total(manager=manager,@@ -1518,7 +1519,6 @@ def test_checkout_prices(user_api_client, checkout_with_item):checkout_info=checkout_info,lines=lines,checkout_line_info=line_info,- discounts=[],)assert (data["lines"][0]["unitPrice"]["gross"]["amount"]@@ -1569,7 +1569,7 @@ def test_checkout_prices_checkout_with_custom_prices(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)shipping_price = base_calculations.base_checkout_delivery_price(checkout_info, lines@@ -1601,6 +1601,12 @@ def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discounquery = QUERY_CHECKOUT_PRICESvariables = {"id": to_global_id_or_none(checkout_with_item)}+ manager = get_plugins_manager()+ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ # To properly apply a sale at checkout, we need to generate discount objects.+ generate_sale_discount_objects_for_checkout(checkout_info, lines)+# whenresponse = user_api_client.post_graphql(query, variables)content = get_graphql_content(response)@@ -1610,16 +1616,15 @@ def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discounassert data["token"] == str(checkout_with_item.token)assert len(data["lines"]) == checkout_with_item.lines.count()- manager = get_plugins_manager()+ checkout_with_item.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ 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(@@ -1627,7 +1632,6 @@ def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discouncheckout_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]@@ -1637,7 +1641,6 @@ def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discouncheckout_info=checkout_info,lines=lines,checkout_line_info=line_info,- discounts=[discount_info],)assert data["lines"][0]["unitPrice"]["gross"]["amount"] == round(line_total_price.gross.amount / line_info.line.quantity, 2@@ -1654,14 +1657,15 @@ def test_checkout_prices_with_sales(user_api_client, checkout_with_item, discoun[],line_info.line.price_override,)+ undiscounted_total_price = undiscounted_unit_price.amount * line_info.line.quantityassert (data["lines"][0]["undiscountedUnitPrice"]["amount"]== undiscounted_unit_price.amount)assert (- data["lines"][0]["undiscountedTotalPrice"]["amount"]- == undiscounted_unit_price.amount * line_info.line.quantity+ data["lines"][0]["undiscountedTotalPrice"]["amount"] == undiscounted_total_price)+ assert line_total_price.gross.amount < undiscounted_total_pricedef test_checkout_display_gross_prices_use_default(user_api_client, checkout_with_item):@@ -1719,7 +1723,7 @@ def test_checkout_prices_with_specific_voucher(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,@@ -1786,7 +1790,7 @@ def test_checkout_prices_with_voucher_once_per_order(assert len(data["lines"]) == checkout.lines.count()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -1852,7 +1856,7 @@ def test_checkout_prices_with_voucher(user_api_client, checkout_with_item_and_voassert len(data["lines"]) == checkout.lines.count()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,@@ -2055,7 +2059,7 @@ def test_clean_checkout(checkout_with_item, payment_dummy, address, shipping_metmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)manager = get_plugins_manager()total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address@@ -2072,7 +2076,7 @@ def test_clean_checkout(checkout_with_item, payment_dummy, address, shipping_metclean_checkout_shipping(checkout_info, lines, CheckoutErrorCode)clean_checkout_payment(- manager, checkout_info, lines, None, CheckoutErrorCode, last_payment=payment+ manager, checkout_info, lines, CheckoutErrorCode, last_payment=payment)@@ -2083,7 +2087,7 @@ def test_clean_checkout_no_shipping_method(checkout_with_item, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)with pytest.raises(ValidationError) as e:clean_checkout_shipping(checkout_info, lines, CheckoutErrorCode)@@ -2098,7 +2102,7 @@ def test_clean_checkout_no_shipping_address(checkout_with_item, shipping_method)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)with pytest.raises(ValidationError) as e:clean_checkout_shipping(checkout_info, lines, CheckoutErrorCode)msg = "Shipping address is not set"@@ -2116,7 +2120,7 @@ def test_clean_checkout_invalid_shipping_method(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)with pytest.raises(ValidationError) as e:clean_checkout_shipping(checkout_info, lines, CheckoutErrorCode)@@ -2135,11 +2139,11 @@ def test_clean_checkout_no_billing_address(payment = checkout.get_last_active_payment()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)with pytest.raises(ValidationError) as e:clean_checkout_payment(- manager, checkout_info, lines, None, CheckoutErrorCode, last_payment=payment+ manager, checkout_info, lines, CheckoutErrorCode, last_payment=payment)msg = "Billing address is not set"assert e.value.error_dict["billing_address"][0].message == msg@@ -2154,11 +2158,11 @@ def test_clean_checkout_no_payment(checkout_with_item, shipping_method, address)payment = checkout.get_last_active_payment()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)with pytest.raises(ValidationError) as e:clean_checkout_payment(- manager, checkout_info, lines, None, CheckoutErrorCode, last_payment=payment+ manager, checkout_info, lines, CheckoutErrorCode, last_payment=payment)msg = "Provided payment methods can not cover the checkout's total amount"diff --git a/saleor/graphql/checkout/tests/test_checkout_digital.py b/saleor/graphql/checkout/tests/test_checkout_digital.pyindex 2c1a0ec315..3044f60c23 100644--- a/saleor/graphql/checkout/tests/test_checkout_digital.py+++ b/saleor/graphql/checkout/tests/test_checkout_digital.py@@ -50,7 +50,7 @@ def test_remove_shipping_method_if_only_digital_in_checkout(assert checkout.shipping_methodmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)update_checkout_shipping_method_if_invalid(checkout_info, lines)checkout.refresh_from_db()diff --git a/saleor/graphql/checkout/tests/test_checkout_price_expiration.py b/saleor/graphql/checkout/tests/test_checkout_price_expiration.pyindex 5b342b6f19..8cab31750f 100644--- a/saleor/graphql/checkout/tests/test_checkout_price_expiration.py+++ b/saleor/graphql/checkout/tests/test_checkout_price_expiration.py@@ -52,10 +52,8 @@ def test_checkout_lines_add_invalidate_prices(assert not response["data"]["checkoutLinesAdd"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)- mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], save=True- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)+ mocked_function.assert_called_once_with(checkout_info, lines, mock.ANY, save=True)UPDATE_CHECKOUT_LINES = """@@ -99,10 +97,8 @@ def test_checkout_lines_update_invalidate_prices(assert not response["data"]["checkoutLinesUpdate"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)- mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], save=True- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)+ mocked_function.assert_called_once_with(checkout_info, lines, mock.ANY, save=True)DELETE_CHECKOUT_LINES = """@@ -142,10 +138,8 @@ def test_checkout_lines_delete_invalidate_prices(assert not response["data"]["checkoutLinesDelete"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)- mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], save=True- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)+ mocked_function.assert_called_once_with(checkout_info, lines, mock.ANY, save=True)DELETE_CHECKOUT_LINE = """@@ -185,10 +179,8 @@ def test_checkout_line_delete_invalidate_prices(assert not response["data"]["checkoutLineDelete"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)- mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], save=True- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)+ mocked_function.assert_called_once_with(checkout_info, lines, mock.ANY, save=True)UPDATE_CHECKOUT_SHIPPING_ADDRESS = """@@ -230,10 +222,8 @@ def test_checkout_shipping_address_update_invalidate_prices(assert not response["data"]["checkoutShippingAddressUpdate"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)- mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], save=False- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)+ mocked_function.assert_called_once_with(checkout_info, lines, mock.ANY, save=False)UPDATE_CHECKOUT_BILLING_ADDRESS = """@@ -274,9 +264,9 @@ def test_checkout_billing_address_update_invalidate_prices(assert not response["data"]["checkoutBillingAddressUpdate"]["errors"]checkout_with_items.refresh_from_db()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)mocked_function.assert_called_once_with(- checkout_info, lines, mock.ANY, [], recalculate_discount=False, save=False+ checkout_info, lines, mock.ANY, recalculate_discount=False, save=False)@@ -373,11 +363,11 @@ def test_invalidate_checkout_prices_with_save(checkout, plugins_manager):checkout.price_expiration = timezone.now() + timedelta(minutes=5)checkout.save(update_fields=["price_expiration"])lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)# whenupdated_fields = invalidate_checkout_prices(- checkout_info, lines, plugins_manager, [], save=True+ checkout_info, lines, plugins_manager, save=True)# then@@ -394,11 +384,11 @@ def test_invalidate_checkout_prices_without_save(checkout, plugins_manager):)checkout.save(update_fields=["price_expiration"])lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)# whenupdated_fields = invalidate_checkout_prices(- checkout_info, lines, plugins_manager, [], save=False+ checkout_info, lines, plugins_manager, save=False)# thendiff --git a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/test_checkout_promo_codes.pyindex b50443e71e..9e1a74f544 100644--- a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py+++ b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py@@ -1,6 +1,5 @@from ....checkout import calculationsfrom ....checkout.fetch import fetch_checkout_info, fetch_checkout_lines-from ....discount import DiscountInfofrom ....plugins.manager import get_plugins_managerfrom ...core.utils import to_global_id_or_nonefrom ...tests.utils import get_graphql_content@@ -47,40 +46,27 @@ def test_checkout_totals_use_discounts(response = api_client.post_graphql(query, variables)content = get_graphql_content(response)data = content["data"]["checkout"]- sale_channel_listing = sale.channel_listings.get(channel=channel_USD)- discounts = [- DiscountInfo(- sale=sale,- channel_listings={channel_USD.slug: sale_channel_listing},- product_ids={product.id},- category_ids=set(),- collection_ids=set(),- variants_ids=set(),- )- ]manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)taxed_total = calculations.checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address,- discounts=discounts,)assert data["totalPrice"]["gross"]["amount"] == taxed_total.gross.amountassert data["subtotalPrice"]["gross"]["amount"] == taxed_total.gross.amountlines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]line_total = calculations.checkout_line_total(manager=manager,checkout_info=checkout_info,lines=lines,checkout_line_info=checkout_line_info,- discounts=discounts,)assert data["lines"][0]["totalPrice"]["gross"]["amount"] == line_total.gross.amountdiff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex 068c9a5432..0794245a70 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -24,8 +24,8 @@ from ...warehouse.reservations import is_reservation_enabledfrom ..account.dataloaders import AddressByIdLoaderfrom ..account.utils import check_is_owner_or_has_one_of_permsfrom ..channel import ChannelContext-from ..channel.dataloaders import ChannelByCheckoutLineIDLoaderfrom ..channel.types import Channel+from ..checkout.dataloaders import ChannelByCheckoutLineIDLoaderfrom ..core import ResolveInfofrom ..core.connection import CountableConnectionfrom ..core.descriptions import (@@ -45,7 +45,6 @@ from ..core.tracing import traced_resolverfrom ..core.types import BaseObjectType, ModelObjectType, Money, NonNullList, TaxedMoneyfrom ..core.utils import str_to_enumfrom ..decorators import one_of_permissions_required-from ..discount.dataloaders import DiscountsByDateTimeLoaderfrom ..giftcard.types import GiftCardfrom ..meta import resolvers as MetaResolversfrom ..meta.types import ObjectWithMetadata, _filter_metadata@@ -82,7 +81,6 @@ from .utils import prevent_sync_event_circular_queryif TYPE_CHECKING:from ...account.models import Addressfrom ...checkout.fetch import CheckoutInfo, CheckoutLineInfo- from ...discount import DiscountInfofrom ...plugins.manager import PluginsManager@@ -92,16 +90,14 @@ def get_dataloaders_for_fetching_checkout_data(Optional[Promise["Address"]],Promise[list["CheckoutLineInfo"]],Promise["CheckoutInfo"],- Promise[list["DiscountInfo"]],Promise["PluginsManager"],]:address_id = root.shipping_address_id or root.billing_address_idaddress = AddressByIdLoader(info.context).load(address_id) if address_id else Nonelines = CheckoutLinesInfoByCheckoutTokenLoader(info.context).load(root.token)checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(root.token)- discounts = DiscountsByDateTimeLoader(info.context).load(info.context.request_time)manager = get_plugin_manager_promise(info.context)- return address, lines, checkout_info, discounts, manager+ return address, lines, checkout_info, managerclass GatewayConfigLine(BaseObjectType):@@ -186,9 +182,6 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):def resolve_unit_price(root, info: ResolveInfo):def with_checkout(data):checkout, manager = data- discounts = DiscountsByDateTimeLoader(info.context).load(- info.context.request_time- )checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(checkout.token)@@ -198,7 +191,6 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):def calculate_line_unit_price(data):(- discounts,checkout_info,lines,) = data@@ -209,13 +201,11 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):checkout_info=checkout_info,lines=lines,checkout_line_info=line_info,- discounts=discounts,)return Nonereturn Promise.all([- discounts,checkout_info,lines,]@@ -270,9 +260,6 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):def resolve_total_price(root, info: ResolveInfo):def with_checkout(data):checkout, manager = data- discounts = DiscountsByDateTimeLoader(info.context).load(- info.context.request_time- )checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(checkout.token)@@ -281,7 +268,7 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):)def calculate_line_total_price(data):- (discounts, checkout_info, lines) = data+ (checkout_info, lines) = datafor line_info in lines:if line_info.line.pk == root.pk:return calculations.checkout_line_total(@@ -289,13 +276,10 @@ class CheckoutLine(ModelObjectType[models.CheckoutLine]):checkout_info=checkout_info,lines=lines,checkout_line_info=line_info,- discounts=discounts,)return None- return Promise.all([discounts, checkout_info, lines]).then(- calculate_line_total_price- )+ return Promise.all([checkout_info, lines]).then(calculate_line_total_price)return Promise.all([@@ -611,13 +595,12 @@ class Checkout(ModelObjectType[models.Checkout]):@prevent_sync_event_circular_querydef resolve_total_price(root: models.Checkout, info: ResolveInfo):def calculate_total_price(data):- address, lines, checkout_info, discounts, manager = data+ address, lines, checkout_info, manager = datataxed_total = calculations.calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)return max(taxed_total, zero_taxed_money(root.currency))@@ -629,13 +612,12 @@ class Checkout(ModelObjectType[models.Checkout]):@prevent_sync_event_circular_querydef resolve_subtotal_price(root: models.Checkout, info: ResolveInfo):def calculate_subtotal_price(data):- address, lines, checkout_info, discounts, manager = data+ address, lines, checkout_info, manager = datareturn calculations.checkout_subtotal(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)dataloaders = list(get_dataloaders_for_fetching_checkout_data(root, info))@@ -646,13 +628,12 @@ class Checkout(ModelObjectType[models.Checkout]):@prevent_sync_event_circular_querydef resolve_shipping_price(root: models.Checkout, info: ResolveInfo):def calculate_shipping_price(data):- address, lines, checkout_info, discounts, manager = data+ address, lines, checkout_info, manager = datareturn calculations.checkout_shipping_price(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)dataloaders = list(get_dataloaders_for_fetching_checkout_data(root, info))@@ -881,13 +862,12 @@ class Checkout(ModelObjectType[models.Checkout]):@classmethoddef resolve_authorize_status(cls, root: models.Checkout, info):def _resolve_authorize_status(data):- address, lines, checkout_info, discounts, manager, transactions = data+ address, lines, checkout_info, manager, transactions = datafetch_checkout_data(checkout_info=checkout_info,manager=manager,lines=lines,address=address,- discounts=discounts,checkout_transactions=transactions,)return checkout_info.checkout.authorize_status@@ -901,13 +881,12 @@ class Checkout(ModelObjectType[models.Checkout]):@classmethoddef resolve_charge_status(cls, root: models.Checkout, info):def _resolve_charge_status(data):- address, lines, checkout_info, discounts, manager, transactions = data+ address, lines, checkout_info, manager, transactions = datafetch_checkout_data(checkout_info=checkout_info,manager=manager,lines=lines,address=address,- discounts=discounts,checkout_transactions=transactions,)return checkout_info.checkout.charge_status@@ -921,13 +900,12 @@ class Checkout(ModelObjectType[models.Checkout]):@classmethoddef resolve_total_balance(cls, root: models.Checkout, info):def _calculate_total_balance_for_transactions(data):- address, lines, checkout_info, discounts, manager, transactions = data+ address, lines, checkout_info, manager, transactions = datataxed_total = calculations.calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)checkout_total = max(taxed_total, zero_taxed_money(root.currency))total_charged = zero_money(root.currency)diff --git a/saleor/graphql/core/types/taxes.py b/saleor/graphql/core/types/taxes.pyindex 09003f202d..293e8f2286 100644--- a/saleor/graphql/core/types/taxes.py+++ b/saleor/graphql/core/types/taxes.py@@ -23,10 +23,7 @@ from ...checkout.dataloaders import ()from ...core.doc_category import DOC_CATEGORY_TAXESfrom ...core.types import BaseObjectType-from ...discount.dataloaders import (- DiscountsByDateTimeLoader,- OrderDiscountsByOrderIDLoader,-)+from ...discount.dataloaders import OrderDiscountsByOrderIDLoaderfrom ...order import types as order_typesfrom ...order.dataloaders import OrderByIdLoader, OrderLinesByOrderIdLoaderfrom ...product.dataloaders.products import (@@ -201,9 +198,6 @@ class TaxableObjectLine(BaseObjectType):if isinstance(root, CheckoutLine):def with_checkout(checkout):- discounts = DiscountsByDateTimeLoader(info.context).load(- info.context.request_time- )checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(checkout.token)@@ -213,7 +207,6 @@ class TaxableObjectLine(BaseObjectType):def calculate_line_unit_price(data):(- discounts,checkout_info,lines,) = data@@ -222,13 +215,11 @@ class TaxableObjectLine(BaseObjectType):return base_calculations.calculate_base_line_unit_price(line_info=line_info,channel=checkout_info.channel,- discounts=discounts,)return Nonereturn Promise.all([- discounts,checkout_info,lines,]@@ -246,9 +237,6 @@ class TaxableObjectLine(BaseObjectType):if isinstance(root, CheckoutLine):def with_checkout(checkout):- discounts = DiscountsByDateTimeLoader(info.context).load(- info.context.request_time- )checkout_info = CheckoutInfoByCheckoutTokenLoader(info.context).load(checkout.token)@@ -258,7 +246,6 @@ class TaxableObjectLine(BaseObjectType):def calculate_line_total_price(data):(- discounts,checkout_info,lines,) = data@@ -267,13 +254,11 @@ class TaxableObjectLine(BaseObjectType):return base_calculations.calculate_base_line_total_price(line_info=line_info,channel=checkout_info.channel,- discounts=discounts,)return Nonereturn Promise.all([- discounts,checkout_info,lines,]diff --git a/saleor/graphql/discount/dataloaders.py b/saleor/graphql/discount/dataloaders.pyindex aa3c984611..dbbea75a3f 100644--- a/saleor/graphql/discount/dataloaders.py+++ b/saleor/graphql/discount/dataloaders.py@@ -6,6 +6,7 @@ from django.db.models import Ffrom ...discount import DiscountInfofrom ...discount.interface import VoucherInfofrom ...discount.models import (+ CheckoutLineDiscount,OrderDiscount,Sale,SaleChannelListing,@@ -35,13 +36,21 @@ class DiscountsByDateTimeLoader(DataLoader):for datetime in keys}pks = {s.pk for d, ss in sales_map.items() for s in ss}- collections = fetch_collections(pks, self.database_connection_name)+ collections = fetch_collections(+ pks, database_connection_name=self.database_connection_name+ )channel_listings = fetch_sale_channel_listings(pks, self.database_connection_name)- products = fetch_products(pks, self.database_connection_name)- categories = fetch_categories(pks, self.database_connection_name)- variants = fetch_variants(pks, self.database_connection_name)+ products = fetch_products(+ pks, database_connection_name=self.database_connection_name+ )+ categories = fetch_categories(+ pks, database_connection_name=self.database_connection_name+ )+ variants = fetch_variants(+ pks, database_connection_name=self.database_connection_name+ )return [[@@ -234,3 +243,16 @@ class OrderDiscountsByOrderIDLoader(DataLoader):def load_discounts(request):return DiscountsByDateTimeLoader(request).load(request.request_time).get()+++class CheckoutLineDiscountsByCheckoutLineIdLoader(DataLoader):+ context_key = "checkout_line_discounts_by_checkout_line_id"++ def batch_load(self, keys):+ discounts = CheckoutLineDiscount.objects.using(+ self.database_connection_name+ ).filter(line_id__in=keys)+ discount_map = defaultdict(list)+ for discount in discounts:+ discount_map[discount.line_id].append(discount)+ return [discount_map.get(checkout_line_id, []) for checkout_line_id in keys]diff --git a/saleor/graphql/discount/enums.py b/saleor/graphql/discount/enums.pyindex d7db3eebb1..3b0d621551 100644--- a/saleor/graphql/discount/enums.py+++ b/saleor/graphql/discount/enums.py@@ -1,9 +1,9 @@-from ...discount import DiscountValueType, OrderDiscountType, VoucherType+from ...discount import DiscountType, DiscountValueType, VoucherTypefrom ..core.doc_category import DOC_CATEGORY_DISCOUNTSfrom ..core.enums import to_enumfrom ..core.types import BaseEnum-OrderDiscountTypeEnum = to_enum(OrderDiscountType, type_name="OrderDiscountType")+OrderDiscountTypeEnum = to_enum(DiscountType, type_name="OrderDiscountType")OrderDiscountTypeEnum.doc_category = DOC_CATEGORY_DISCOUNTSdiff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex c7705eb239..d3fdc56725 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -15,7 +15,7 @@ from ...checkout.utils import get_external_shipping_idfrom ...core.anonymize import obfuscate_address, obfuscate_emailfrom ...core.prices import quantize_pricefrom ...core.taxes import zero_money-from ...discount import OrderDiscountType+from ...discount import DiscountTypefrom ...graphql.checkout.types import DeliveryMethodfrom ...graphql.core.federation.entities import federated_entityfrom ...graphql.core.federation.resolvers import resolve_federation_references@@ -1331,7 +1331,7 @@ class Order(ModelObjectType[models.Order]):if not discounts:return Nonefor discount in discounts:- if discount.type == OrderDiscountType.VOUCHER:+ if discount.type == DiscountType.VOUCHER:return Money(amount=discount.value, currency=discount.currency)return None@@ -1348,7 +1348,7 @@ class Order(ModelObjectType[models.Order]):if not discounts:return Nonefor discount in discounts:- if discount.type == OrderDiscountType.VOUCHER:+ if discount.type == DiscountType.VOUCHER:return discount.namereturn None@@ -1365,7 +1365,7 @@ class Order(ModelObjectType[models.Order]):if not discounts:return Nonefor discount in discounts:- if discount.type == OrderDiscountType.VOUCHER:+ if discount.type == DiscountType.VOUCHER:return discount.translated_namereturn Nonediff --git a/saleor/graphql/payment/mutations.py b/saleor/graphql/payment/mutations.pyindex a1c3cbcf38..75957d292c 100644--- a/saleor/graphql/payment/mutations.py+++ b/saleor/graphql/payment/mutations.py@@ -1,6 +1,6 @@import uuidfrom decimal import Decimal-from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Union, cast+from typing import TYPE_CHECKING, Dict, List, Optional, Union, castimport graphenefrom django.core.exceptions import ValidationError@@ -101,7 +101,6 @@ from ..core.scalars import JSON, UUID, PositiveDecimalfrom ..core.types import BaseInputObjectType, BaseObjectTypefrom ..core.types import common as common_typesfrom ..core.utils import from_global_id_or_error-from ..discount.dataloaders import load_discountsfrom ..meta.mutations import MetadataInputfrom ..plugins.dataloaders import get_plugin_manager_promisefrom ..utils import get_user_or_app_from_context@@ -116,7 +115,6 @@ from .utils import check_if_requestor_has_access, metadata_contains_empty_keyif TYPE_CHECKING:from ...account.models import User- from ...discount import DiscountInfofrom ...plugins.manager import PluginsManager@@ -294,7 +292,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):checkout_id=None,id=None,input,- token=None+ token=None,):checkout = get_checkout(cls, info, checkout_id=checkout_id, token=token, id=id)@@ -330,8 +328,7 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):)})- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)cls.validate_token(manager, gateway, input, channel_slug=checkout_info.channel.slug@@ -345,7 +342,6 @@ class CheckoutPaymentCreate(BaseMutation, I18nMixin):checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)amount = input.get("amount", checkout_total.gross.amount)clean_checkout_shipping(checkout_info, lines, PaymentErrorCode)@@ -1054,7 +1050,7 @@ class TransactionCreate(BaseMutation):*,id: str,transaction: Dict,- transaction_event=None+ transaction_event=None,):order_or_checkout_instance = cls.get_node_or_error(info, id)@@ -1105,10 +1101,7 @@ class TransactionCreate(BaseMutation):previous_refunded_value=Decimal(0),)if transaction_data.get("checkout_id") and money_data:- discounts = load_discounts(info.context)- transaction_amounts_for_checkout_updated(- new_transaction, discounts, manager- )+ transaction_amounts_for_checkout_updated(new_transaction, manager)if transaction_event:cls.create_transaction_event(transaction_event, new_transaction, user, app)@@ -1260,7 +1253,7 @@ class TransactionUpdate(TransactionCreate):*,id: str,transaction=None,- transaction_event=None+ transaction_event=None,):app = get_app_promise(info.context).get()user = info.context.user@@ -1319,9 +1312,8 @@ class TransactionUpdate(TransactionCreate):previous_refunded_value=previous_refunded_value,)if instance.checkout_id and money_data:- discounts = load_discounts(info.context)manager = get_plugin_manager_promise(info.context).get()- transaction_amounts_for_checkout_updated(instance, discounts, manager)+ transaction_amounts_for_checkout_updated(instance, manager)return TransactionUpdate(transaction=instance)@@ -1540,7 +1532,7 @@ class TransactionEventReport(ModelMutation):time=None,external_url=None,message=None,- available_actions=None+ available_actions=None,):user = info.context.userapp = get_app_promise(info.context).get()@@ -1654,11 +1646,8 @@ class TransactionEventReport(ModelMutation):previous_refunded_value=previous_refunded_value,)if transaction.checkout_id:- discounts = load_discounts(info.context)manager = get_plugin_manager_promise(info.context).get()- transaction_amounts_for_checkout_updated(- transaction, discounts, manager- )+ transaction_amounts_for_checkout_updated(transaction, manager)return cls(already_processed=already_processed,@@ -1704,7 +1693,6 @@ class TransactionSessionBase(BaseMutation):incorrect_type_error_code: str,not_found_error: str,manager: "PluginsManager",- discounts: Optional[Iterable["DiscountInfo"]],) -> Union[checkout_models.Checkout, order_models.Order]:source_object_type, source_object_id = from_global_id_or_error(id, raise_error=False@@ -1731,13 +1719,8 @@ class TransactionSessionBase(BaseMutation):)if source_object:lines, _ = fetch_checkout_lines(source_object)- discounts = discounts or []- checkout_info = fetch_checkout_info(- source_object, lines, discounts, manager- )- checkout_info, _ = fetch_checkout_data(- checkout_info, manager, lines, discounts=discounts- )+ checkout_info = fetch_checkout_info(source_object, lines, manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, manager, lines)source_object = checkout_info.checkoutelse:source_object = (@@ -1867,14 +1850,12 @@ class PaymentGatewayInitialize(TransactionSessionBase):@classmethoddef perform_mutation(cls, root, info, *, id, amount=None, payment_gateways=None):- discounts = load_discounts(info.context)manager = get_plugin_manager_promise(info.context).get()source_object = cls.clean_source_object(info,id,PaymentGatewayInitializeErrorCode.INVALID.value,PaymentGatewayInitializeErrorCode.NOT_FOUND.value,- discounts=discounts,manager=manager,)payment_gateways_data = []@@ -1971,7 +1952,6 @@ class TransactionInitialize(TransactionSessionBase):def perform_mutation(cls, root, info, *, id, payment_gateway, amount=None, action=None):- discounts = load_discounts(info.context)manager = get_plugin_manager_promise(info.context).get()payment_gateway_data = PaymentGatewayData(app_identifier=payment_gateway["id"], data=payment_gateway.get("data")@@ -1981,7 +1961,6 @@ class TransactionInitialize(TransactionSessionBase):id,TransactionInitializeErrorCode.INVALID.value,TransactionInitializeErrorCode.NOT_FOUND.value,- discounts=discounts,manager=manager,)action = cls.clean_action(info, action, source_object.channel)@@ -1998,7 +1977,6 @@ class TransactionInitialize(TransactionSessionBase):action=action,app=app,manager=manager,- discounts=discounts,)return cls(transaction=transaction, transaction_event=event, data=data)@@ -2143,7 +2121,6 @@ class TransactionProcess(BaseMutation):app_identifier = cast(str, app_identifier)action = cls.get_action(request_event, source_object.channel)manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)event, data = handle_transaction_process_session(transaction_item=transaction_item,source_object=source_object,@@ -2154,7 +2131,6 @@ class TransactionProcess(BaseMutation):action=action,manager=manager,request_event=request_event,- discounts=discounts,)transaction_item.refresh_from_db()diff --git a/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py b/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.pyindex 53672ce503..39bca5fa28 100644--- a/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py+++ b/saleor/graphql/payment/tests/deprecated/test_checkout_payment_create.py@@ -36,7 +36,7 @@ def test_checkout_add_payment_by_checkout_id(checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -73,7 +73,7 @@ def test_checkout_add_payment_neither_token_and_id_given(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -102,7 +102,7 @@ def test_checkout_add_payment_both_token_and_id_given(checkout_id = graphene.Node.to_global_id("Checkout", checkout.pk)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)diff --git a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.pyindex 4217b45a02..b9b2523259 100644--- a/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py+++ b/saleor/graphql/payment/tests/mutations/test_checkout_payment_create.py@@ -50,7 +50,7 @@ def test_checkout_add_payment_without_shipping_method_and_not_shipping_required(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -88,7 +88,7 @@ def test_checkout_add_payment_without_shipping_method_with_shipping_required(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -119,7 +119,7 @@ def test_checkout_add_payment_with_shipping_method_and_shipping_required(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -159,7 +159,7 @@ def test_checkout_add_payment(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -201,7 +201,7 @@ def test_checkout_add_payment_default_amount(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -232,7 +232,7 @@ def test_checkout_add_payment_bad_amount(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -262,7 +262,7 @@ def test_checkout_add_payment_no_checkout_email(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -350,7 +350,7 @@ def test_use_checkout_billing_address_as_payment_billing(checkout = checkout_without_shipping_requiredmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -394,12 +394,12 @@ def test_create_payment_for_checkout_with_active_payments(checkout.billing_address = addressmanager = get_plugins_manager()variant = product_without_shipping.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, 1)checkout.save()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -452,7 +452,7 @@ def test_create_payment_with_store(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -486,7 +486,7 @@ def test_create_payment_with_store_as_none(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -522,7 +522,7 @@ def test_create_payment_with_metadata(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -559,7 +559,7 @@ def test_checkout_add_payment_no_variant_channel_listings(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -600,7 +600,7 @@ def test_checkout_add_payment_no_product_channel_listings(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -640,7 +640,7 @@ def test_checkout_add_payment_checkout_without_lines(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -674,7 +674,7 @@ def test_checkout_add_payment_run_multiple_times(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)diff --git a/saleor/graphql/payment/tests/mutations/test_payment_gateway_initialize.py b/saleor/graphql/payment/tests/mutations/test_payment_gateway_initialize.pyindex 271edf5a31..2c976fa21c 100644--- a/saleor/graphql/payment/tests/mutations/test_payment_gateway_initialize.py+++ b/saleor/graphql/payment/tests/mutations/test_payment_gateway_initialize.py@@ -46,10 +46,8 @@ def test_for_checkout_without_payment_gateways(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)checkout = checkout_info.checkoutexpected_app_identifier = "app.id"expected_data = {"json": "data"}@@ -125,10 +123,8 @@ def test_for_checkout_with_payment_gateways(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)checkout = checkout_info.checkoutexpected_app_identifier = "app.id"diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_create.py b/saleor/graphql/payment/tests/mutations/test_transaction_create.pyindex 7fafbaf296..454fd646ee 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_create.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_create.py@@ -1075,10 +1075,8 @@ def test_transaction_create_for_checkout_fully_paid(checkout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)variables = {"id": graphene.Node.to_global_id("Checkout", checkout.pk),diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.pyindex 50bd19c8b4..5ea3ab227b 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_event_report.py@@ -892,10 +892,8 @@ def test_transaction_event_updates_checkout_full_paid_with_charged_amount(checkout = checkout_with_itemslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)psp_reference = "111-abc"transaction = transaction_item_generator(app=app_api_client.app, checkout_id=checkout.pk@@ -958,10 +956,8 @@ def test_transaction_event_updates_checkout_full_paid_with_pending_charge_amountcheckout = checkout_with_itemslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)psp_reference = "111-abc"transaction = transaction_item_generator(app=app_api_client.app, checkout_id=checkout.pkdiff --git a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.pyindex 51b9ae45d0..c3ecda6704 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_initialize.py@@ -592,10 +592,8 @@ def test_checkout_when_amount_is_not_provided(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)expected_app_identifier = "webhook.app.identifier"webhook_app.identifier = expected_app_identifierwebhook_app.save()@@ -764,10 +762,8 @@ def test_checkout_with_transaction_when_amount_is_not_provided(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)checkout = checkout_info.checkoutexpected_charged_amount = Decimal("10")@@ -834,10 +830,8 @@ def test_app_with_action_field_and_handle_payments(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)expected_app_identifier = "webhook.app.identifier"webhook_app.identifier = expected_app_identifier@@ -1150,10 +1144,8 @@ def test_checkout_fully_paid(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)expected_app_identifier = "webhook.app.identifier"webhook_app.identifier = expected_app_identifierwebhook_app.save()diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_process.py b/saleor/graphql/payment/tests/mutations/test_transaction_process.pyindex 41c298b712..ff339de84b 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_process.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_process.py@@ -855,10 +855,8 @@ def test_checkout_fully_paid(# givencheckout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)expected_app_identifier = "webhook.app.identifier"webhook_app.identifier = expected_app_identifierwebhook_app.save()diff --git a/saleor/graphql/payment/tests/mutations/test_transaction_update.py b/saleor/graphql/payment/tests/mutations/test_transaction_update.pyindex 2e66630ed8..3d35008172 100644--- a/saleor/graphql/payment/tests/mutations/test_transaction_update.py+++ b/saleor/graphql/payment/tests/mutations/test_transaction_update.py@@ -2549,10 +2549,8 @@ def test_transaction_update_for_checkout_fully_paid(checkout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugins_manager)- checkout_info, _ = fetch_checkout_data(- checkout_info, plugins_manager, lines, discounts=[]- )+ checkout_info = fetch_checkout_info(checkout, lines, plugins_manager)+ checkout_info, _ = fetch_checkout_data(checkout_info, plugins_manager, lines)variables = {"id": graphene.Node.to_global_id("TransactionItem", transaction.token),diff --git a/saleor/graphql/product/tests/mutations/test_product_channel_listing_update.py b/saleor/graphql/product/tests/mutations/test_product_channel_listing_update.pyindex c29da943ab..718eddee10 100644--- a/saleor/graphql/product/tests/mutations/test_product_channel_listing_update.py+++ b/saleor/graphql/product/tests/mutations/test_product_channel_listing_update.py@@ -950,7 +950,7 @@ def test_product_channel_listing_update_remove_channel_removes_checkout_lines(# givenproduct = product_available_in_many_channelsvariant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)assert checkout.lines.all().exists()@@ -1232,7 +1232,7 @@ def test_product_channel_listing_remove_variant_removes_checkout_lines():# givenvariant = product.variants.first()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)assert checkout.lines.all().exists()diff --git a/saleor/graphql/product/tests/test_bulk_delete.py b/saleor/graphql/product/tests/test_bulk_delete.pyindex 1342934cb2..10eea43e75 100644--- a/saleor/graphql/product/tests/test_bulk_delete.py+++ b/saleor/graphql/product/tests/test_bulk_delete.py@@ -1016,7 +1016,7 @@ def test_delete_product_variants_removes_checkout_lines():query = PRODUCT_VARIANT_BULK_DELETE_MUTATION- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())variant_list = [product.variants.first() for product in product_list][:2]for variant in variant_list:add_variant_to_checkout(checkout_info, variant, 1)diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex a1dec30cd3..e5ceb04436 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -11196,6 +11196,7 @@ type OrderDiscount implements Node @doc(category: "Discounts") {"""An enumeration."""enum OrderDiscountType @doc(category: "Discounts") {+ SALEVOUCHERMANUAL}diff --git a/saleor/graphql/tax/mutations/tax_exemption_manage.py b/saleor/graphql/tax/mutations/tax_exemption_manage.pyindex 8b4c4b0812..c352c7d5a7 100644--- a/saleor/graphql/tax/mutations/tax_exemption_manage.py+++ b/saleor/graphql/tax/mutations/tax_exemption_manage.py@@ -14,7 +14,6 @@ from ...core.descriptions import ADDED_IN_38from ...core.doc_category import DOC_CATEGORY_TAXESfrom ...core.types import Errorfrom ...core.types.taxes import TaxSourceObject-from ...discount.dataloaders import load_discountsfrom ...plugins.dataloaders import get_plugin_manager_promiseTaxExemptionManageErrorCode = graphene.Enum.from_enum(@@ -78,15 +77,13 @@ class TaxExemptionManage(BaseMutation):@classmethoddef _invalidate_checkout_prices(cls, info: ResolveInfo, checkout):manager = get_plugin_manager_promise(info.context).get()- discounts = load_discounts(info.context)- checkout_info = fetch_checkout_info(checkout, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)lines_info, _ = fetch_checkout_lines(checkout)invalidate_checkout_prices(checkout_info,lines_info,manager,- discounts,save=False,)diff --git a/saleor/graphql/webhook/resolvers.py b/saleor/graphql/webhook/resolvers.pyindex b2fcc2f099..73602f10df 100644--- a/saleor/graphql/webhook/resolvers.py+++ b/saleor/graphql/webhook/resolvers.py@@ -10,7 +10,6 @@ from ...webhook.deprecated_event_types import WebhookEventTypefrom ...webhook.event_types import WebhookEventAsyncType, WebhookEventSyncTypefrom ..core.tracing import traced_resolverfrom ..core.utils import from_global_id_or_error-from ..discount.dataloaders import load_discountsfrom .types import Webhook, WebhookEvent@@ -48,13 +47,11 @@ def resolve_sample_payload(info, event_name, app):def resolve_shipping_methods_for_checkout(info, checkout, manager):- discounts = load_discounts(info.context)lines, _ = fetch_checkout_lines(checkout)shipping_channel_listings = checkout.channel.shipping_method_listings.all()checkout_info = fetch_checkout_info(checkout,lines,- discounts,manager,shipping_channel_listings,fetch_delivery_methods=False,@@ -63,7 +60,6 @@ def resolve_shipping_methods_for_checkout(info, checkout, manager):checkout_info,checkout.shipping_address,lines,- discounts,shipping_channel_listings,manager,)diff --git a/saleor/order/base_calculations.py b/saleor/order/base_calculations.pyindex 8752e06472..c15d276cab 100644--- a/saleor/order/base_calculations.py+++ b/saleor/order/base_calculations.py@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Iterablefrom prices import Money, TaxedMoneyfrom ..core.taxes import zero_money-from ..discount import DiscountValueType, OrderDiscountType+from ..discount import DiscountType, DiscountValueTypefrom ..discount.models import OrderDiscountfrom ..discount.utils import apply_discount_to_valuefrom .interface import OrderTaxedPricesData@@ -34,9 +34,9 @@ def base_order_total(order: "Order", lines: Iterable["OrderLine"]) -> Money:Shipping vouchers are included in the shipping price.Specific product vouchers are included in line base prices.Entire order vouchers are recalculated and updated in this function- (OrderDiscounts with type `order_discount.type == OrderDiscountType.VOUCHER`).+ (OrderDiscounts with type `order_discount.type == DiscountType.VOUCHER`).Staff order discounts are recalculated and updated in this function- (OrderDiscounts with type `order_discount.type == OrderDiscountType.MANUAL`).+ (OrderDiscounts with type `order_discount.type == DiscountType.MANUAL`)."""currency = order.currencysubtotal = base_order_subtotal(order, lines)@@ -46,7 +46,7 @@ def base_order_total(order: "Order", lines: Iterable["OrderLine"]) -> Money:for order_discount in order_discounts:subtotal_before_discount = subtotalshipping_price_before_discount = shipping_price- if order_discount.type == OrderDiscountType.VOUCHER:+ if order_discount.type == DiscountType.VOUCHER:subtotal = apply_discount_to_value(value=order_discount.value,value_type=order_discount.value_type,diff --git a/saleor/order/notifications.py b/saleor/order/notifications.pyindex ffd93f1d9a..414825c667 100644--- a/saleor/order/notifications.py+++ b/saleor/order/notifications.py@@ -9,7 +9,7 @@ from ..core.notification.utils import get_site_contextfrom ..core.notify_events import NotifyEventTypefrom ..core.prices import quantize_price, quantize_price_fieldsfrom ..core.utils.url import build_absolute_uri, prepare_url-from ..discount import OrderDiscountType+from ..discount import DiscountTypefrom ..graphql.core.utils import to_global_id_or_nonefrom ..product import ProductMediaTypesfrom ..product.models import DigitalContentUrl, Product, ProductMedia, ProductVariant@@ -188,7 +188,7 @@ def get_discounts_payload(order):"reason": order_discount.reason,}all_discounts.append(dicount_obj)- if order_discount.type == OrderDiscountType.VOUCHER:+ if order_discount.type == DiscountType.VOUCHER:voucher_discount = dicount_objdiscount_amount += order_discount.amount_valuediff --git a/saleor/order/tests/test_base_calculations/test_base_order_total.py b/saleor/order/tests/test_base_calculations/test_base_order_total.pyindex 79d5359c13..8221e6f4dd 100644--- a/saleor/order/tests/test_base_calculations/test_base_order_total.py+++ b/saleor/order/tests/test_base_calculations/test_base_order_total.py@@ -3,7 +3,7 @@ from decimal import ROUND_HALF_UP, Decimalfrom prices import Moneyfrom ....core.taxes import zero_money-from ....discount import DiscountValueType, OrderDiscountType+from ....discount import DiscountType, DiscountValueTypefrom ... import base_calculations@@ -36,7 +36,7 @@ def test_base_order_total_with_fixed_voucher(order_with_lines):discount_amount = 10order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=discount_amount,name="Voucher",@@ -64,7 +64,7 @@ def test_base_order_total_with_fixed_voucher_more_then_total(order_with_lines):subtotal += line.base_unit_price * line.quantityorder_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=100,name="Voucher",@@ -95,7 +95,7 @@ def test_base_order_total_with_percentage_voucher(order_with_lines):discount_amount = subtotal.amount * Decimal(0.5)order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=50,name="Voucher",@@ -125,7 +125,7 @@ def test_base_order_total_with_fixed_manual_discount(order_with_lines):discount_amount = 10order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -148,7 +148,7 @@ def test_base_order_total_with_fixed_manual_discount_and_zero_order_total(order)lines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=0,name="StaffDiscount",@@ -175,7 +175,7 @@ def test_base_order_total_with_fixed_manual_discount_more_then_total(order_with_undiscounted_total = subtotal + shipping_priceorder_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=100,name="StaffDiscount",@@ -205,7 +205,7 @@ def test_base_order_total_with_percentage_manual_discount(order_with_lines):discount_amount = undiscounted_total.amount * Decimal(0.5)order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -237,7 +237,7 @@ def test_base_order_total_with_fixed_voucher_and_fixed_manual_discount(voucher_discount_amount = 10voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=voucher_discount_amount,name="StaffDiscount",@@ -247,7 +247,7 @@ def test_base_order_total_with_fixed_voucher_and_fixed_manual_discount()manual_discount_amount = 10manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=manual_discount_amount,name="StaffDiscount",@@ -283,7 +283,7 @@ def test_base_order_total_with_percentage_voucher_and_fixed_manual_discount(voucher_discount_amount = subtotal.amount * Decimal(0.5)voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -293,7 +293,7 @@ def test_base_order_total_with_percentage_voucher_and_fixed_manual_discount()manual_discount_amount = 10manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -329,7 +329,7 @@ def test_base_order_total_with_fixed_voucher_and_percentage_manual_discount(voucher_discount_amount = 10voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -342,7 +342,7 @@ def test_base_order_total_with_fixed_voucher_and_percentage_manual_discount()manual_discount_amount = temporary_total.amount * Decimal(0.5)manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -378,7 +378,7 @@ def test_base_order_total_with_percentage_voucher_and_percentage_manual_discountvoucher_discount_amount = subtotal.amount * Decimal(0.5)voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -392,7 +392,7 @@ def test_base_order_total_with_percentage_voucher_and_percentage_manual_discount)manual_discount_amount = temporary_total.amount * Decimal(0.5)manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -428,7 +428,7 @@ def test_base_order_total_with_fixed_manual_discount_and_fixed_voucher(manual_discount_amount = 10manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=manual_discount_amount,name="StaffDiscount",@@ -439,7 +439,7 @@ def test_base_order_total_with_fixed_manual_discount_and_fixed_voucher(voucher_discount_amount = 10voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=voucher_discount_amount,name="StaffDiscount",@@ -475,7 +475,7 @@ def test_base_order_total_with_fixed_manual_discount_and_percentage_voucher(manual_discount_amount = 10manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -492,7 +492,7 @@ def test_base_order_total_with_fixed_manual_discount_and_percentage_voucher(Decimal("0.01"), ROUND_HALF_UP)voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -532,7 +532,7 @@ def test_base_order_total_with_percentage_manual_discount_and_fixed_voucher(manual_discount_amount = undiscounted_total.amount * Decimal(0.5)manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -543,7 +543,7 @@ def test_base_order_total_with_percentage_manual_discount_and_fixed_voucher(voucher_discount_amount = 10voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -579,7 +579,7 @@ def test_base_order_total_with_percentage_manual_discount_and_percentage_vouchermanual_discount_amount = undiscounted_total.amount * Decimal(0.5)manual_order_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",@@ -591,7 +591,7 @@ def test_base_order_total_with_percentage_manual_discount_and_percentage_vouchertemporary_subtotal_amount = subtotal.amount * Decimal(0.5)voucher_discount_amount = temporary_subtotal_amount * Decimal(0.5)voucher_order_discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=50,name="StaffDiscount",diff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.pyindex 0a24c8688a..edbd988376 100644--- a/saleor/order/tests/test_order.py+++ b/saleor/order/tests/test_order.py@@ -6,7 +6,7 @@ import pytestfrom prices import Money, TaxedMoneyfrom ...core.weight import zero_weight-from ...discount import OrderDiscountType+from ...discount import DiscountTypefrom ...discount.models import (DiscountValueType,NotApplicable,@@ -67,7 +67,7 @@ def test_total_setter():def test_order_get_subtotal(order_with_lines):order_with_lines.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=order_with_lines.total.gross.amount * Decimal("0.5"),amount_value=order_with_lines.total.gross.amount * Decimal("0.5"),diff --git a/saleor/order/tests/test_order_utils.py b/saleor/order/tests/test_order_utils.pyindex fbb74d7a44..796f231ff9 100644--- a/saleor/order/tests/test_order_utils.py+++ b/saleor/order/tests/test_order_utils.py@@ -4,7 +4,7 @@ import pytestfrom prices import Money, TaxedMoneyfrom ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines-from ...discount import DiscountValueType, OrderDiscountType+from ...discount import DiscountType, DiscountValueTypefrom ...giftcard import GiftCardEventsfrom ...giftcard.models import GiftCardEventfrom ...graphql.order.utils import OrderLineData@@ -302,7 +302,7 @@ def test_add_gift_cards_to_order(checkout.gift_cards.add(gift_card, gift_card_expiry_date)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenadd_gift_cards_to_order(@@ -359,7 +359,7 @@ def test_add_gift_cards_to_order_no_checkout_user(checkout.gift_cards.add(gift_card, gift_card_expiry_date)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenadd_gift_cards_to_order(@@ -407,7 +407,7 @@ def test_add_gift_cards_to_order_no_checkout_user(def test_get_total_order_discount_excluding_shipping(order, voucher_shipping_type):# givenorder.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher_shipping_type.code,@@ -415,7 +415,7 @@ def test_get_total_order_discount_excluding_shipping(order, voucher_shipping_typamount_value=Decimal("10.0"),)manual_discount = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher_shipping_type.code,@@ -441,7 +441,7 @@ def test_get_total_order_discount_excluding_shipping_no_shipping_discounts():# givendiscount_1 = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,@@ -449,7 +449,7 @@ def test_get_total_order_discount_excluding_shipping_no_shipping_discounts(amount_value=Decimal("10.0"),)discount_2 = order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex a27b840ae9..d718415c16 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -12,7 +12,7 @@ from ..core.prices import quantize_pricefrom ..core.taxes import zero_moneyfrom ..core.tracing import traced_atomic_transactionfrom ..core.weight import zero_weight-from ..discount import OrderDiscountType+from ..discount import DiscountTypefrom ..discount.models import NotApplicable, OrderDiscount, Voucher, VoucherTypefrom ..discount.utils import (apply_discount_to_value,@@ -110,7 +110,7 @@ def update_voucher_discount(func):def get_voucher_discount_assigned_to_order(order: Order):- return order.discounts.filter(type=OrderDiscountType.VOUCHER).first()+ return order.discounts.filter(type=DiscountType.VOUCHER).first()def invalidate_order_prices(order: Order, *, save: bool = False) -> None:@@ -727,7 +727,7 @@ def get_total_order_discount_excluding_shipping(order: Order) -> Money:# The calculation is based on assumption that an order can have only one voucher.all_discounts = order.discounts.all()if order.voucher and order.voucher.type == VoucherType.SHIPPING:- all_discounts = all_discounts.exclude(type=OrderDiscountType.VOUCHER)+ all_discounts = all_discounts.exclude(type=DiscountType.VOUCHER)total_order_discount = Money(sum([discount.amount_value for discount in all_discounts]),currency=order.currency,@@ -738,7 +738,7 @@ def get_total_order_discount_excluding_shipping(order: Order) -> Money:def get_order_discounts(order: Order) -> List[OrderDiscount]:"""Return all discounts applied to the order by staff user."""- return list(order.discounts.filter(type=OrderDiscountType.MANUAL))+ return list(order.discounts.filter(type=DiscountType.MANUAL))def create_order_discount_for_order(diff --git a/saleor/payment/gateways/adyen/tests/conftest.py b/saleor/payment/gateways/adyen/tests/conftest.pyindex b03c383142..7ad9de1692 100644--- a/saleor/payment/gateways/adyen/tests/conftest.py+++ b/saleor/payment/gateways/adyen/tests/conftest.py@@ -76,7 +76,7 @@ def payment_adyen_for_checkout(checkout_with_items, address, shipping_method):checkout_with_items.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.pyindex 8a9b45e663..d836c6b15f 100644--- a/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py+++ b/saleor/payment/gateways/adyen/tests/webhooks/test_handle_notifications.py@@ -167,7 +167,7 @@ def test_handle_authorization_sets_psp_reference(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -213,7 +213,7 @@ def test_handle_authorization_for_checkout(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -264,7 +264,7 @@ def test_handle_authorization_for_checkout_partial_payment(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -312,7 +312,7 @@ def test_handle_authorization_for_checkout_out_of_stock_after_payment(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -374,7 +374,7 @@ def test_handle_authorization_for_checkout_that_cannot_be_finalized(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -443,7 +443,7 @@ def test_handle_authorization_calls_refund_for_inactive_payment(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -529,7 +529,7 @@ def test_handle_authorization_for_checkout_one_of_variants_deleted(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -576,7 +576,7 @@ def test_handle_authorization_with_adyen_auto_capture(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -865,7 +865,7 @@ def test_handle_capture_for_checkout(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1006,7 +1006,7 @@ def test_handle_capture_for_checkout_order_not_created_checkout_line_variant_delpayment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1916,7 +1916,7 @@ def test_handle_order_closed_success_true(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -1967,7 +1967,7 @@ def test_handle_order_closed_with_adyen_partial_payments_success_true(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -2052,7 +2052,7 @@ def test_handle_order_closed_with_adyen_partial_payments_success_true_without_ampayment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -2147,7 +2147,7 @@ def test_order_closed_with_adyen_partial_payments_unable_to_create_order(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)@@ -2221,7 +2221,7 @@ def test_order_closed_with_not_active_payment(payment = payment_adyen_for_checkoutmanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/payment/gateways/adyen/utils/common.py b/saleor/payment/gateways/adyen/utils/common.pyindex 5a1f354e7b..4bbc7ea890 100644--- a/saleor/payment/gateways/adyen/utils/common.py+++ b/saleor/payment/gateways/adyen/utils/common.py@@ -19,7 +19,6 @@ from .....checkout.calculations import (from .....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom .....checkout.models import Checkoutfrom .....checkout.utils import get_checkout_metadata, is_shipping_required-from .....discount.utils import fetch_active_discountsfrom .....payment.models import Paymentfrom .....plugins.manager import get_plugins_managerfrom .... import PaymentError@@ -217,7 +216,7 @@ def request_data_for_payment(return request_data-def get_shipping_data(manager, checkout_info, lines, discounts):+def get_shipping_data(manager, checkout_info, lines):address = checkout_info.shipping_address or checkout_info.billing_addresscurrency = checkout_info.checkout.currencyshipping_total = checkout_shipping_price(@@ -225,7 +224,6 @@ def get_shipping_data(manager, checkout_info, lines, discounts):checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)total_gross = shipping_total.gross.amounttotal_net = shipping_total.net.amount@@ -260,8 +258,7 @@ def append_checkout_details(payment_information: "PaymentData", payment_data: dimanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout)- discounts = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)currency = payment_information.currencycountry_code = checkout.get_country()@@ -275,7 +272,6 @@ def append_checkout_details(payment_information: "PaymentData", payment_data: dicheckout_info=checkout_info,lines=lines,checkout_line_info=line_info,- discounts=discounts,)unit_gross = unit_price.gross.amountunit_net = unit_price.net.amount@@ -300,7 +296,7 @@ def append_checkout_details(payment_information: "PaymentData", payment_data: diif checkout_info.delivery_method_info.delivery_method and is_shipping_required(lines):- line_items.append(get_shipping_data(manager, checkout_info, lines, discounts))+ line_items.append(get_shipping_data(manager, checkout_info, lines))payment_data["lineItems"] = line_itemsreturn payment_data@@ -336,15 +332,13 @@ def request_data_for_gateway_config() -> Dict[str, Any]:manager = get_plugins_manager()address = checkout.billing_address or checkout.shipping_address- discounts = fetch_active_discounts()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)total = checkout_total(manager=manager,checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,)country = address.country if address else Nonediff --git a/saleor/payment/gateways/adyen/webhooks.py b/saleor/payment/gateways/adyen/webhooks.pyindex 4bd7d44095..1b84a7831b 100644--- a/saleor/payment/gateways/adyen/webhooks.py+++ b/saleor/payment/gateways/adyen/webhooks.py@@ -32,7 +32,6 @@ from ....checkout.models import Checkoutfrom ....core.prices import quantize_pricefrom ....core.transactions import transaction_with_commit_on_errorsfrom ....core.utils.url import prepare_url-from ....discount.utils import fetch_active_discountsfrom ....graphql.core.utils import from_global_id_or_errorfrom ....order.actions import (cancel_order,@@ -182,20 +181,18 @@ def create_payment_notification_for_order(def create_order(payment, checkout, manager):try:- discounts = fetch_active_discounts()lines, unavailable_variant_pks = fetch_checkout_lines(checkout)if unavailable_variant_pks:payment_refund_or_void(payment, manager, checkout.channel.slug)raise ValidationError("Some of the checkout lines variants are unavailable.")- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_total = calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address or checkout.billing_address,- discounts=discounts,)# when checkout total value is different than total amount from payments# it means that some products has been removed during the payment was completed@@ -210,7 +207,6 @@ def create_order(payment, checkout, manager):lines=lines,payment_data={},store_source=False,- discounts=discounts,user=checkout.user or None,app=None,)diff --git a/saleor/payment/gateways/stripe/tests/conftest.py b/saleor/payment/gateways/stripe/tests/conftest.pyindex 067d273849..232bb9f361 100644--- a/saleor/payment/gateways/stripe/tests/conftest.py+++ b/saleor/payment/gateways/stripe/tests/conftest.py@@ -21,7 +21,7 @@ def payment_stripe_for_checkout(checkout_with_items, address, shipping_method):checkout_with_items.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(checkout_with_items, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)total = calculations.calculate_checkout_total_with_gift_cards(manager, checkout_info, lines, address)diff --git a/saleor/payment/gateways/stripe/webhooks.py b/saleor/payment/gateways/stripe/webhooks.pyindex d548315850..853c104387 100644--- a/saleor/payment/gateways/stripe/webhooks.py+++ b/saleor/payment/gateways/stripe/webhooks.py@@ -13,7 +13,6 @@ from ....checkout.complete_checkout import complete_checkoutfrom ....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ....checkout.models import Checkoutfrom ....core.transactions import transaction_with_commit_on_errors-from ....discount.utils import fetch_active_discountsfrom ....order.actions import order_charged, order_refunded, order_voidedfrom ....order.fetch import fetch_order_infofrom ....order.models import Order@@ -177,17 +176,15 @@ def _finalize_checkout(checkout.refresh_from_db()manager = get_plugins_manager()- discounts = fetch_active_discounts()lines, unavailable_variant_pks = fetch_checkout_lines(checkout)if unavailable_variant_pks:raise ValidationError("Some of the checkout lines variants are unavailable.")- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_total = calculate_checkout_total_with_gift_cards(manager=manager,checkout_info=checkout_info,lines=lines,address=checkout.shipping_address or checkout.billing_address,- discounts=discounts,)try:@@ -205,7 +202,6 @@ def _finalize_checkout(lines=lines,payment_data={},store_source=False,- discounts=discounts,user=checkout.user or None,app=None,)diff --git a/saleor/payment/tests/test_payment.py b/saleor/payment/tests/test_payment.pyindex 68901cdc7e..e8b425c836 100644--- a/saleor/payment/tests/test_payment.py+++ b/saleor/payment/tests/test_payment.py@@ -118,7 +118,7 @@ def test_create_payment(checkout_with_item, address):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -159,7 +159,7 @@ def test_create_payment_from_checkout_requires_billing_address(checkout_with_itemanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=None)@@ -201,7 +201,7 @@ def test_create_payment_information_for_checkout_payment(address, checkout_with_manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -337,7 +337,7 @@ def test_create_payment_information_store(checkout_with_item, address, store):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)@@ -372,7 +372,7 @@ def test_create_payment_information_metadata(checkout_with_item, address, metadamanager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)total = checkout_total(manager=manager, checkout_info=checkout_info, lines=lines, address=address)diff --git a/saleor/payment/tests/test_utils.py b/saleor/payment/tests/test_utils.pyindex 0eae174992..d12f4a1360 100644--- a/saleor/payment/tests/test_utils.py+++ b/saleor/payment/tests/test_utils.py@@ -79,9 +79,7 @@ def test_create_payment_lines_information_order_with_voucher(payment_dummy):assert payment_lines_data.voucher_amount == -voucher_amount-def get_expected_checkout_payment_lines(- manager, checkout_info, lines, address, discounts-):+def get_expected_checkout_payment_lines(manager, checkout_info, lines, address):expected_payment_lines = []for line_info in lines:@@ -90,7 +88,6 @@ def get_expected_checkout_payment_lines(lines,line_info,address,- discounts,).gross.amountquantity = line_info.line.quantityvariant_id = line_info.variant.id@@ -110,7 +107,6 @@ def get_expected_checkout_payment_lines(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,).gross.amountreturn PaymentLinesData(@@ -131,11 +127,10 @@ def test_create_payment_lines_information_checkout(payment_dummy, checkout_with_# thenlines, _ = fetch_checkout_lines(checkout_with_items)- discounts = []- checkout_info = fetch_checkout_info(checkout_with_items, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)address = checkout_with_items.shipping_addressexpected_payment_lines = get_expected_checkout_payment_lines(- manager, checkout_info, lines, address, discounts+ manager, checkout_info, lines, address)assert payment_lines == expected_payment_lines@@ -156,11 +151,10 @@ def test_create_payment_lines_information_checkout_with_voucher(# thenlines, _ = fetch_checkout_lines(checkout_with_items)- discounts = []- checkout_info = fetch_checkout_info(checkout_with_items, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)address = checkout_with_items.shipping_addressexpected_payment_lines_data = get_expected_checkout_payment_lines(- manager, checkout_info, lines, address, discounts+ manager, checkout_info, lines, address)expected_payment_lines_data.voucher_amount = -voucher_amount@@ -1177,7 +1171,6 @@ def test_create_transaction_event_for_transaction_session_success_response(request_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1219,7 +1212,6 @@ def test_create_transaction_event_for_transaction_session_success_response_with_request_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1265,7 +1257,6 @@ def test_create_transaction_event_for_transaction_session_not_success_events(request_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1315,7 +1306,6 @@ def test_create_transaction_event_for_transaction_session_missing_psp_reference(request_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1361,7 +1351,6 @@ def test_create_transaction_event_for_transaction_session_missing_reference_withrequest_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1408,7 +1397,6 @@ def test_create_transaction_event_for_transaction_session_call_webhook_order_updrequest_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)@@ -1444,7 +1432,6 @@ def test_create_transaction_event_for_transaction_session_call_webhook_for_fullyrequest_event,webhook_app,manager=plugins_manager,- discounts=[],transaction_webhook_response=response,)diff --git a/saleor/payment/utils.py b/saleor/payment/utils.pyindex 3b86c8d41f..50f750e659 100644--- a/saleor/payment/utils.py+++ b/saleor/payment/utils.py@@ -3,7 +3,7 @@ import jsonimport loggingfrom datetime import datetimefrom decimal import Decimal-from typing import Any, Dict, Iterable, Optional, Union, cast, overload+from typing import Any, Dict, Optional, Union, cast, overloadimport graphenefrom babel.numbers import get_currency_precision@@ -20,8 +20,6 @@ from ..checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ..checkout.models import Checkoutfrom ..core.prices import quantize_pricefrom ..core.tracing import traced_atomic_transaction-from ..discount import DiscountInfo-from ..discount.utils import fetch_active_discountsfrom ..graphql.core.utils import str_to_enumfrom ..order.fetch import fetch_order_infofrom ..order.models import Order@@ -86,8 +84,7 @@ def create_checkout_payment_lines_information() -> PaymentLinesData:line_items = []lines, _ = fetch_checkout_lines(checkout)- discounts = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)address = checkout_info.shipping_address or checkout_info.billing_addressfor line_info in lines:@@ -96,7 +93,6 @@ def create_checkout_payment_lines_information(lines,line_info,address,- discounts,)unit_gross = unit_price.gross.amount@@ -116,7 +112,6 @@ def create_checkout_payment_lines_information(checkout_info=checkout_info,lines=lines,address=address,- discounts=discounts,).gross.amountvoucher_amount = -checkout.discount_amount@@ -1060,7 +1055,6 @@ def create_transaction_event_for_transaction_session(request_event: TransactionEvent,app: App,manager: "PluginsManager",- discounts: Optional[Iterable["DiscountInfo"]],transaction_webhook_response: Optional[Dict[str, Any]] = None,):request_event_type = "session-request"@@ -1165,9 +1159,7 @@ def create_transaction_event_for_transaction_session(previous_refunded_value=previous_refunded_value,)elif transaction_item.checkout_id:- transaction_amounts_for_checkout_updated(- transaction_item, discounts, manager- )+ transaction_amounts_for_checkout_updated(transaction_item, manager)return event@@ -1222,9 +1214,8 @@ def create_transaction_event_from_request_and_webhook_response(previous_refunded_value=previous_refunded_value,)elif transaction_item.checkout_id:- discounts = fetch_active_discounts()manager = get_plugins_manager()- transaction_amounts_for_checkout_updated(transaction_item, discounts, manager)+ transaction_amounts_for_checkout_updated(transaction_item, manager)return event@@ -1387,7 +1378,6 @@ def handle_transaction_initialize_session(action: str,app: App,manager: PluginsManager,- discounts: Optional[Iterable["DiscountInfo"]],):transaction_item = create_transaction_item(source_object=source_object, user=None, app=app, psp_reference=None@@ -1418,7 +1408,6 @@ def handle_transaction_initialize_session(app,transaction_webhook_response=response_data,manager=manager,- discounts=discounts,)data_to_return = response_data.get("data") if response_data else Nonereturn created_event.transaction, created_event, data_to_return@@ -1432,7 +1421,6 @@ def handle_transaction_process_session(app: App,manager: PluginsManager,request_event: TransactionEvent,- discounts: Optional[Iterable["DiscountInfo"]],):session_data = TransactionSessionData(transaction=transaction_item,@@ -1454,7 +1442,6 @@ def handle_transaction_process_session(app,transaction_webhook_response=response_data,manager=manager,- discounts=discounts,)data_to_return = response_data.get("data") if response_data else Nonereturn created_event, data_to_returndiff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.pyindex e2f65753f4..a04ebd7063 100644--- a/saleor/plugins/avatax/__init__.py+++ b/saleor/plugins/avatax/__init__.py@@ -16,7 +16,7 @@ from ...account.models import Addressfrom ...checkout import base_calculationsfrom ...checkout.utils import is_shipping_requiredfrom ...core.taxes import TaxError-from ...discount import OrderDiscountType, VoucherType+from ...discount import DiscountType, VoucherTypefrom ...order import base_calculations as base_order_calculationsfrom ...order.utils import get_total_order_discount_excluding_shippingfrom ...shipping.models import ShippingMethod@@ -274,7 +274,6 @@ def generate_request_data_from_checkout_lines(checkout_info: "CheckoutInfo",lines_info: Iterable["CheckoutLineInfo"],config: AvataxConfiguration,- discounts=None,) -> List[Dict[str, Union[str, int, bool, None]]]:data: List[Dict[str, Union[str, int, bool, None]]] = []channel = checkout_info.channel@@ -309,7 +308,6 @@ def generate_request_data_from_checkout_lines(checkout_line_total = base_calculations.calculate_base_line_total_price(line_info,channel,- discounts,)# This is a workaround for Avatax and sending a lines with amount 0. Like@@ -418,9 +416,7 @@ def get_order_lines_data()if shipping_price := order.base_shipping_price_amount:- shipping_discounted = order.discounts.filter(- type=OrderDiscountType.MANUAL- ).exists()+ shipping_discounted = order.discounts.filter(type=DiscountType.MANUAL).exists()append_shipping_to_data(data=data,@@ -501,13 +497,10 @@ def generate_request_data_from_checkout(config: AvataxConfiguration,transaction_token=None,transaction_type=TransactionType.ORDER,- discounts=None,):shipping_address = checkout_info.delivery_method_info.shipping_addressaddress = shipping_address or checkout_info.billing_address- lines = generate_request_data_from_checkout_lines(- checkout_info, lines_info, config, discounts- )+ lines = generate_request_data_from_checkout_lines(checkout_info, lines_info, config)if not lines:return {}@@ -593,12 +586,9 @@ def get_cached_response_or_fetch(def get_checkout_tax_data(checkout_info: "CheckoutInfo",lines_info: Iterable["CheckoutLineInfo"],- discounts,config: AvataxConfiguration,) -> Dict[str, Any]:- data = generate_request_data_from_checkout(- checkout_info, lines_info, config, discounts=discounts- )+ data = generate_request_data_from_checkout(checkout_info, lines_info, config)return get_cached_response_or_fetch(data, str(checkout_info.checkout.token), config)diff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.pyindex 20401629af..b42f0c75b8 100644--- a/saleor/plugins/avatax/plugin.py+++ b/saleor/plugins/avatax/plugin.py@@ -15,7 +15,6 @@ from prices import Money, TaxedMoney, TaxedMoneyRangefrom ...checkout import base_calculationsfrom ...checkout.fetch import fetch_checkout_linesfrom ...core.taxes import TaxError, TaxType, zero_taxed_money-from ...discount import DiscountInfofrom ...order.interface import OrderTaxedPricesDatafrom ...product.models import ProductTypefrom ...tax.utils import get_charge_taxes_for_checkout, get_charge_taxes_for_order@@ -194,12 +193,9 @@ class AvataxPlugin(BasePlugin):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],previous_value: TaxedMoney,) -> TaxedMoney:- response = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ response = self._get_checkout_tax_data(checkout_info, lines, previous_value)if response is None:return previous_value@@ -219,7 +215,7 @@ class AvataxPlugin(BasePlugin):# each linebase_value=SimpleLazyObject(lambda: base_calculations.calculate_base_line_total_price(- line, checkout_info.channel, discounts+ line, checkout_info.channel)),)@@ -280,14 +276,11 @@ class AvataxPlugin(BasePlugin):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],previous_value: TaxedMoney,) -> TaxedMoney:base_shipping_price = previous_value- response = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ response = self._get_checkout_tax_data(checkout_info, lines, previous_value)if response is None:return previous_value@@ -299,7 +292,6 @@ class AvataxPlugin(BasePlugin):def preprocess_order_creation(self,checkout_info: "CheckoutInfo",- discounts: Iterable[DiscountInfo],lines: Optional[Iterable["CheckoutLineInfo"]],previous_value: Any,):@@ -324,7 +316,6 @@ class AvataxPlugin(BasePlugin):self.config,transaction_token=str(checkout_info.checkout.token),transaction_type=TransactionType.ORDER,- discounts=discounts,)if not data.get("createTransactionModel", {}).get("lines"):return previous_value@@ -373,7 +364,6 @@ class AvataxPlugin(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: TaxedMoney,) -> TaxedMoney:charge_taxes = get_charge_taxes_for_checkout(checkout_info, lines)@@ -384,9 +374,7 @@ class AvataxPlugin(BasePlugin):_get_prices_entered_with_tax_for_checkout, checkout_info)- taxes_data = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ taxes_data = self._get_checkout_tax_data(checkout_info, lines, previous_value)variant = checkout_line_info.variantif not taxes_data or "error" in taxes_data:@@ -398,7 +386,7 @@ class AvataxPlugin(BasePlugin):prices_entered_with_tax,base_value=SimpleLazyObject(lambda: base_calculations.calculate_base_line_total_price(- checkout_line_info, checkout_info.channel, discounts+ checkout_line_info, checkout_info.channel)),)@@ -515,7 +503,6 @@ class AvataxPlugin(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: TaxedMoney,) -> TaxedMoney:base_total = previous_value@@ -530,9 +517,7 @@ class AvataxPlugin(BasePlugin):variant = checkout_line_info.variantquantity = checkout_line_info.line.quantity- taxes_data = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ taxes_data = self._get_checkout_tax_data(checkout_info, lines, previous_value)if not taxes_data or "error" in taxes_data:return previous_value@@ -542,7 +527,7 @@ class AvataxPlugin(BasePlugin):prices_entered_with_tax,base_value=SimpleLazyObject(lambda: base_calculations.calculate_base_line_total_price(- checkout_line_info, checkout_info.channel, discounts+ checkout_line_info, checkout_info.channel)),)@@ -663,16 +648,13 @@ class AvataxPlugin(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable[DiscountInfo],previous_value: Decimal,) -> Decimal:charge_taxes = get_charge_taxes_for_checkout(checkout_info, lines)if not charge_taxes:return previous_value- response = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ response = self._get_checkout_tax_data(checkout_info, lines, previous_value)variant = checkout_line_info.variantreturn self._get_unit_tax_rate(response,@@ -704,12 +686,9 @@ class AvataxPlugin(BasePlugin):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],previous_value: Decimal,):- response = self._get_checkout_tax_data(- checkout_info, lines, discounts, previous_value- )+ response = self._get_checkout_tax_data(checkout_info, lines, previous_value)return self._get_shipping_tax_rate(response, previous_value)def get_order_shipping_tax_rate(self, order: "Order", previous_value: Decimal):@@ -720,7 +699,6 @@ class AvataxPlugin(BasePlugin):self,checkout_info: "CheckoutInfo",lines_info: Iterable["CheckoutLineInfo"],- discounts: Iterable[DiscountInfo],base_value: Union[TaxedMoney, Decimal],):if self._skip_plugin(base_value):@@ -730,9 +708,7 @@ class AvataxPlugin(BasePlugin):if not valid:return None- response = get_checkout_tax_data(- checkout_info, lines_info, discounts, self.config- )+ response = get_checkout_tax_data(checkout_info, lines_info, self.config)if not response or "error" in response:return Nonediff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[False-24.39-30.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[24.39-30.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[False-24.39-30.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[24.39-30.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[False-30.00-36.90-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[30.00-36.90-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[False-30.00-36.90-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[30.00-36.90-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[True-12.20-15.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total_with_sale[12.20-15.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[True-12.20-15.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total_with_sale[12.20-15.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[True-15.00-18.45-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total_with_sale[15.00-18.45-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total[True-15.00-18.45-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_total_with_sale[15.00-18.45-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[False-24.39-30.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[24.39-30.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[False-24.39-30.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[24.39-30.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[False-30.00-36.90-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[30.00-36.90-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[False-30.00-36.90-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[30.00-36.90-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[True-12.20-15.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total_with_sale[12.20-15.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[True-12.20-15.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total_with_sale[12.20-15.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[True-15.00-18.45-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total_with_sale[15.00-18.45-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total[True-15.00-18.45-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_line_without_sku_total_with_sale[15.00-18.45-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[False-40.65-50.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[40.65-50.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[False-40.65-50.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[40.65-50.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[False-50.00-61.50-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[50.00-61.50-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[False-50.00-61.50-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[50.00-61.50-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[True-20.33-25.00-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal_with_sale[20.33-25.00-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[True-20.33-25.00-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal_with_sale[20.33-25.00-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[True-25.00-30.75-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal_with_sale[25.00-30.75-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal[True-25.00-30.75-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_subtotal_with_sale[25.00-30.75-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[False-32.04-38.99-3.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[32.04-38.99-3.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[False-32.04-38.99-3.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[32.04-38.99-3.0-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[False-41.99-51.19-0.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[41.99-51.19-0.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[False-41.99-51.19-0.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[41.99-51.19-0.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[False-3495-4297-3.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[3495-4297-3.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[False-3495-4297-3.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[3495-4297-3.0-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[False-4300-5289-0.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[4300-5289-0.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[False-4300-5289-0.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[4300-5289-0.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[True-3485-4285-0.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY_with_sale[3485-4285-0.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[True-3485-4285-0.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY_with_sale[3485-4285-0.0-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[True-4280-5264-5.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY_with_sale[4280-5264-5.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY[True-4280-5264-5.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_for_JPY_with_sale[4280-5264-5.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[False-32.04-38.99-3.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[32.04-38.99-3.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[False-32.04-38.99-3.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[32.04-38.99-3.0-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[False-41.99-51.19-0.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[41.99-51.19-0.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[False-41.99-51.19-0.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[41.99-51.19-0.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[True-21.99-26.73-5.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation_with_sale[21.99-26.73-5.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[True-21.99-26.73-5.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation_with_sale[21.99-26.73-5.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[True-22.32-26.99-0.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation_with_sale[22.32-26.99-0.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation[True-22.32-26.99-0.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_uses_default_calculation_with_sale[22.32-26.99-0.0-True].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[True-21.99-26.73-5.0-False].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_with_sale[21.99-26.73-5.0-False].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[True-21.99-26.73-5.0-False].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_with_sale[21.99-26.73-5.0-False].yamldiff --git a/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[True-22.32-26.99-0.0-True].yaml b/saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_with_sale[22.32-26.99-0.0-True].yamlsimilarity index 100%rename from saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total[True-22.32-26.99-0.0-True].yamlrename to saleor/plugins/avatax/tests/cassettes/test_avatax/test_calculate_checkout_total_with_sale[22.32-26.99-0.0-True].yamldiff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.pyindex 6ccf9db747..9b22edebae 100644--- a/saleor/plugins/avatax/tests/test_avatax.py+++ b/saleor/plugins/avatax/tests/test_avatax.py@@ -20,7 +20,8 @@ from ....checkout.fetch import (from ....checkout.utils import add_variant_to_checkoutfrom ....core.prices import quantize_pricefrom ....core.taxes import TaxError, TaxType, zero_money, zero_taxed_money-from ....discount import DiscountValueType, OrderDiscountType, VoucherType+from ....discount import DiscountType, DiscountValueType, VoucherType+from ....discount.utils import create_or_update_discount_objects_from_sale_for_checkoutfrom ....order import OrderStatusfrom ....product import ProductTypeKindfrom ....product.models import Product, ProductType@@ -68,17 +69,68 @@ def order_set_shipping_method(order, shipping_method):@pytest.mark.vcr()@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, prices_entered_with_tax",+ "expected_net, expected_gross, prices_entered_with_tax",[- (True, "12.20", "15.00", True),- (False, "24.39", "30.00", True),- (True, "15.00", "18.45", False),- (False, "30.00", "36.90", False),+ ("24.39", "30.00", True),+ ("30.00", "36.90", False),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_line_total(- with_discount,+ expected_net,+ expected_gross,+ prices_entered_with_tax,+ checkout_with_item,+ ship_to_pl_address,+ monkeypatch,+ shipping_zone,+ plugin_configuration,+):+ plugin_configuration()+ manager = get_plugins_manager()++ checkout_with_item.shipping_address = ship_to_pl_address+ checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()+ checkout_with_item.save()++ tax_configuration = checkout_with_item.channel.tax_configuration+ tax_configuration.charge_taxes = True+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ line = checkout_with_item.lines.first()+ product = line.variant.product+ product.metadata = {}+ product.save()+ product.product_type.save()++ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ checkout_line_info = lines[0]++ total = manager.calculate_checkout_line_total(+ checkout_info,+ lines,+ checkout_line_info,+ checkout_with_item.shipping_address,+ )+ total = quantize_price(total, total.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ "expected_net, expected_gross, prices_entered_with_tax",+ [+ ("12.20", "15.00", True),+ ("15.00", "18.45", False),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_line_total_with_sale(expected_net,expected_gross,prices_entered_with_tax,@@ -107,18 +159,19 @@ def test_calculate_checkout_line_total(product.metadata = {}product.save()product.product_type.save()- discounts = [discount_info] if with_discount else Nonelines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )total = manager.calculate_checkout_line_total(checkout_info,lines,checkout_line_info,checkout_with_item.shipping_address,- discounts,)total = quantize_price(total, total.currency)assert total == TaxedMoney(@@ -159,8 +212,11 @@ def test_calculate_checkout_line_total_with_variant_on_sale(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_total(@@ -168,7 +224,6 @@ def test_calculate_checkout_line_total_with_variant_on_sale(lines,checkout_line,checkout.shipping_address,- discounts=[discount_info],)# then@@ -223,7 +278,7 @@ def test_calculate_checkout_line_total_with_voucher(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency# when@@ -232,7 +287,6 @@ def test_calculate_checkout_line_total_with_voucher(lines,checkout_line_info,checkout.shipping_address,- discounts=[],)# then@@ -284,7 +338,7 @@ def test_calculate_checkout_line_total_with_voucher_once_per_order(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency# when@@ -293,7 +347,6 @@ def test_calculate_checkout_line_total_with_voucher_once_per_order(lines,checkout_line_info,checkout.shipping_address,- discounts=[],)# then@@ -345,8 +398,11 @@ def test_calculate_checkout_line_total_with_variant_on_sale_and_voucher(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_total(@@ -354,7 +410,6 @@ def test_calculate_checkout_line_total_with_variant_on_sale_and_voucher(lines,checkout_line_info,checkout.shipping_address,- discounts=[discount_info],)# then@@ -407,8 +462,11 @@ def test_calculate_checkout_line_total_with_variant_on_sale_and_voucher_only_onctax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_total(@@ -416,7 +474,6 @@ def test_calculate_checkout_line_total_with_variant_on_sale_and_voucher_only_onclines,checkout_line_info,checkout.shipping_address,- discounts=[discount_info],)# then@@ -427,17 +484,74 @@ def test_calculate_checkout_line_total_with_variant_on_sale_and_voucher_only_onc@pytest.mark.vcr()@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, prices_entered_with_tax",+ "expected_net, expected_gross, prices_entered_with_tax",[- (True, "12.20", "15.00", True),- (False, "24.39", "30.00", True),- (True, "15.00", "18.45", False),- (False, "30.00", "36.90", False),+ ("24.39", "30.00", True),+ ("30.00", "36.90", False),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_line_without_sku_total(- with_discount,+ expected_net,+ expected_gross,+ prices_entered_with_tax,+ checkout_with_item,+ ship_to_pl_address,+ monkeypatch,+ shipping_zone,+ plugin_configuration,+):+ monkeypatch.setattr(+ "graphene.Node.to_global_id", lambda x, y: "UHJvZHVjdFZhcmlhbnQ6Mg"+ )++ plugin_configuration()+ manager = get_plugins_manager()++ checkout_with_item.shipping_address = ship_to_pl_address+ checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()+ checkout_with_item.save()++ tax_configuration = checkout_with_item.channel.tax_configuration+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.charge_taxes = True+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ line = checkout_with_item.lines.first()+ line.variant.sku = None+ line.variant.save()+ product = line.variant.product+ product.metadata = {}+ product.save()+ product.product_type.save()++ lines, _ = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ checkout_line_info = lines[0]++ total_price = manager.calculate_checkout_line_total(+ checkout_info,+ lines,+ checkout_line_info,+ checkout_with_item.shipping_address,+ )+ total = quantize_price(total_price, total_price.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ "expected_net, expected_gross, prices_entered_with_tax",+ [+ ("12.20", "15.00", True),+ ("15.00", "18.45", False),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_line_without_sku_total_with_sale(expected_net,expected_gross,prices_entered_with_tax,@@ -472,18 +586,19 @@ def test_calculate_checkout_line_without_sku_total(product.metadata = {}product.save()product.product_type.save()- discounts = [discount_info] if with_discount else Nonelines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )total_price = manager.calculate_checkout_line_total(checkout_info,lines,checkout_line_info,checkout_with_item.shipping_address,- discounts,)total = quantize_price(total_price, total_price.currency)assert total == TaxedMoney(@@ -744,7 +859,7 @@ def test_calculate_order_line_total_entire_order_voucher(order = order_line.orderorder.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,@@ -836,7 +951,7 @@ def test_calculate_order_line_total_shipping_voucher(order = order_line.orderorder.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher_free_shipping.code,@@ -973,20 +1088,80 @@ def test_calculate_order_shipping_order_not_valid(@pytest.mark.vcr@pytest.mark.parametrize(- (- "with_discount, expected_net, expected_gross, voucher_amount, "- "prices_entered_with_tax"- ),+ ("expected_net, expected_gross, voucher_amount, prices_entered_with_tax"),[- (True, "22.32", "26.99", "0.0", True),- (True, "21.99", "26.73", "5.0", False),- (False, "41.99", "51.19", "0.0", False),- (False, "32.04", "38.99", "3.0", True),+ ("41.99", "51.19", "0.0", False),+ ("32.04", "38.99", "3.0", True),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_total_uses_default_calculation(- with_discount,+ expected_net,+ expected_gross,+ voucher_amount,+ prices_entered_with_tax,+ checkout_with_item,+ product_with_single_variant,+ voucher_percentage,+ shipping_zone,+ address,+ ship_to_pl_address,+ monkeypatch,+ plugin_configuration,+ non_default_category,+ tax_class_zero_rates,+):+ plugin_configuration()+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",+ lambda _: {"PC040156": "desc"},+ )+ manager = get_plugins_manager()+ checkout_with_item.shipping_address = ship_to_pl_address+ checkout_with_item.save()++ tax_configuration = checkout_with_item.channel.tax_configuration+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.charge_taxes = True+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ voucher_amount = Money(voucher_amount, "USD")+ checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()+ checkout_with_item.discount = voucher_amount+ if voucher_amount != "0.0":+ checkout_with_item.voucher_code = voucher_percentage.code+ checkout_with_item.save()+ line = checkout_with_item.lines.first()+ product = line.variant.product+ product.metadata = {}+ manager.assign_tax_code_to_object_meta(product.product_type.tax_class, "PC040156")+ product.save()+ product.product_type.save()+ product_with_single_variant.tax_class = tax_class_zero_rates+ product_with_single_variant.category = non_default_category+ product_with_single_variant.save()+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)+ add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())+ lines, _ = fetch_checkout_lines(checkout_with_item)++ total = manager.calculate_checkout_total(checkout_info, lines, address)+ total = quantize_price(total, total.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ ("expected_net, expected_gross, voucher_amount, prices_entered_with_tax"),+ [+ ("22.32", "26.99", "0.0", True),+ ("21.99", "26.73", "5.0", False),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_total_uses_default_calculation_with_sale(expected_net,expected_gross,voucher_amount,@@ -1033,12 +1208,14 @@ def test_calculate_checkout_total_uses_default_calculation(product_with_single_variant.tax_class = tax_class_zero_ratesproduct_with_single_variant.category = non_default_categoryproduct_with_single_variant.save()- discounts = [discount_info] if with_discount else None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())lines, _ = fetch_checkout_lines(checkout_with_item)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )- total = manager.calculate_checkout_total(checkout_info, lines, address, discounts)+ total = manager.calculate_checkout_total(checkout_info, lines, address)total = quantize_price(total, total.currency)assert total == TaxedMoney(net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")@@ -1047,20 +1224,88 @@ def test_calculate_checkout_total_uses_default_calculation(@pytest.mark.vcr@pytest.mark.parametrize(- (- "with_discount, expected_net, expected_gross, voucher_amount, "- "prices_entered_with_tax"- ),+ ("expected_net, expected_gross, voucher_amount, prices_entered_with_tax"),[- (True, "22.32", "26.99", "0.0", True),- (True, "21.99", "26.73", "5.0", False),- (False, "41.99", "51.19", "0.0", False),- (False, "32.04", "38.99", "3.0", True),+ ("41.99", "51.19", "0.0", False),+ ("32.04", "38.99", "3.0", True),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_total(- with_discount,+ expected_net,+ expected_gross,+ voucher_amount,+ prices_entered_with_tax,+ checkout_with_item,+ product_with_single_variant,+ voucher_percentage,+ shipping_zone,+ address,+ ship_to_pl_address,+ monkeypatch,+ plugin_configuration,+ non_default_category,+ tax_class_zero_rates,+):+ plugin_configuration()+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",+ lambda _: {"PS081282": "desc", TAX_CODE_NON_TAXABLE_PRODUCT: "desc"},+ )+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.AvataxPlugin._skip_plugin", lambda *_: False+ )+ manager = get_plugins_manager()+ checkout_with_item.shipping_address = ship_to_pl_address+ checkout_with_item.save()++ tax_configuration = checkout_with_item.channel.tax_configuration+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.charge_taxes = True+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ voucher_amount = Money(voucher_amount, "USD")+ checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()+ checkout_with_item.discount = voucher_amount+ if voucher_amount != "0.0":+ checkout_with_item.voucher_code = voucher_percentage.code+ checkout_with_item.save()+ line = checkout_with_item.lines.first()+ product = line.variant.product++ manager.assign_tax_code_to_object_meta(product.tax_class, "PS081282")+ product.save()+ product.tax_class.save()++ product_with_single_variant.tax_class = tax_class_zero_rates+ product_with_single_variant.category = non_default_category+ product_with_single_variant.save(+ update_fields=[+ "category",+ "tax_class",+ ]+ )+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)+ add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())+ lines, _ = fetch_checkout_lines(checkout_with_item)+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)+ total = quantize_price(total, total.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ ("expected_net, expected_gross, voucher_amount, prices_entered_with_tax"),+ [+ ("22.32", "26.99", "0.0", True),+ # ("21.99", "26.73", "5.0", False),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_total_with_sale(expected_net,expected_gross,voucher_amount,@@ -1116,13 +1361,13 @@ def test_calculate_checkout_total("tax_class",])- discounts = [discount_info] if with_discount else None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)add_variant_to_checkout(checkout_info, product_with_single_variant.variants.get())lines, _ = fetch_checkout_lines(checkout_with_item)- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)total = quantize_price(total, total.currency)assert total == TaxedMoney(net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")@@ -1131,27 +1376,20 @@ def test_calculate_checkout_total(@pytest.mark.vcr@pytest.mark.parametrize(- (- "with_discount, expected_net, expected_gross, voucher_amount, "- "prices_entered_with_tax"- ),+ ("expected_net, expected_gross, voucher_amount, " "prices_entered_with_tax"),[- (True, "3485", "4285", "0.0", True),- (True, "4280", "5264", "5.0", False),- (False, "4300", "5289", "0.0", False),- (False, "3495", "4297", "3.0", True),+ ("4300", "5289", "0.0", False),+ ("3495", "4297", "3.0", True),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_total_for_JPY(- with_discount,expected_net,expected_gross,voucher_amount,prices_entered_with_tax,channel_JPY,checkout_JPY_with_item,- discount_info_JPY,voucher_percentage,shipping_zone_JPY,ship_to_pl_address,@@ -1196,15 +1434,89 @@ def test_calculate_checkout_total_for_JPY(product.save()product.tax_class.save()- discounts = [discount_info_JPY] if with_discount else None- checkout_info = fetch_checkout_info(checkout, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)lines, _ = fetch_checkout_lines(checkout)# when- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)++ # then+ total = quantize_price(total, total.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "JPY"), gross=Money(expected_gross, "JPY")+ )+++ ("expected_net, expected_gross, voucher_amount, prices_entered_with_tax"),+ [+ ("3485", "4285", "0.0", True),+ ("4280", "5264", "5.0", False),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_total_for_JPY_with_sale(+ expected_net,+ expected_gross,+ voucher_amount,+ prices_entered_with_tax,+ channel_JPY,+ checkout_JPY_with_item,+ discount_info_JPY,+ voucher_percentage,+ shipping_zone_JPY,+ ship_to_pl_address,+ monkeypatch,+ plugin_configuration,+):+ # given+ checkout = checkout_JPY_with_item+ plugin_configuration(channel=channel_JPY)+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",+ lambda _: {"PS081282": "desc", TAX_CODE_NON_TAXABLE_PRODUCT: "desc"},+ )+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.AvataxPlugin._skip_plugin", lambda *_: False+ )+ manager = get_plugins_manager()+ checkout.shipping_address = ship_to_pl_address+ checkout.save()++ tax_configuration = checkout.channel.tax_configuration+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.charge_taxes = True+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ voucher_amount = Money(voucher_amount, "JPY")+ checkout.shipping_method = shipping_zone_JPY.shipping_methods.get()+ checkout.discount = voucher_amount+ voucher_percentage.channel_listings.create(+ channel=channel_JPY,+ discount_value=10,+ currency=channel_JPY.currency_code,+ )+ if voucher_amount != "0.0":+ checkout.voucher_code = voucher_percentage.code+ checkout.save()+ line = checkout.lines.first()+ product = line.variant.product++ manager.assign_tax_code_to_object_meta(product.tax_class, "PS081282")+ product.save()+ product.tax_class.save()++ checkout_info = fetch_checkout_info(checkout, [], manager)+ lines, _ = fetch_checkout_lines(checkout)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info_JPY])+ # when+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)+# thentotal = quantize_price(total, total.currency)assert total == TaxedMoney(@@ -1265,14 +1577,11 @@ def test_calculate_checkout_total_voucher_on_entire_order(checkout_with_item.discount_amount = net.amountcheckout_with_item.save()- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)# when- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts- )+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)# thentotal = quantize_price(total, total.currency)@@ -1334,14 +1643,11 @@ def test_calculate_checkout_total_voucher_on_entire_order_applied_once_per_ordershipping_channel_listings = shipping_method.channel_listings.get(channel=channel)shipping_price = shipping_channel_listings.price- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)# when- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts- )+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)# thenline = checkout_with_item.lines.first()@@ -1407,16 +1713,13 @@ def test_calculate_checkout_total_voucher_on_entire_order_product_without_taxes(shipping_channel_listings = shipping_method.channel_listings.get(channel=channel)shipping_price = shipping_channel_listings.price- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)currency = checkout_with_item.currency# when- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts- )+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)# thentotal = quantize_price(total, currency)@@ -1473,14 +1776,11 @@ def test_calculate_checkout_total_voucher_on_shipping(checkout_with_item.discount_amount = shipping_channel_listings.price.amountcheckout_with_item.save()- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)# when- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts- )+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)# thentotal = quantize_price(total, total.currency)@@ -1533,12 +1833,9 @@ def test_calculate_checkout_total_not_charged_product_and_shipping_with_0_price(product.save()product.product_type.save()- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)- total = manager.calculate_checkout_total(- checkout_info, lines, ship_to_pl_address, discounts- )+ total = manager.calculate_checkout_total(checkout_info, lines, ship_to_pl_address)total = quantize_price(total, total.currency)channel_listing = variant.channel_listings.get(channel=channel)@@ -1573,12 +1870,11 @@ def test_calculate_checkout_shipping(checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )- shipping_price = manager.calculate_checkout_shipping(- checkout_info, lines, address, [discount_info]+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])+ shipping_price = manager.calculate_checkout_shipping(checkout_info, lines, address)shipping_price = quantize_price(shipping_price, shipping_price.currency)assert shipping_price == TaxedMoney(net=Money("8.13", "USD"), gross=Money("10.00", "USD")@@ -1587,21 +1883,17 @@ def test_calculate_checkout_shipping(@pytest.mark.vcr@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, prices_entered_with_tax",+ "expected_net, expected_gross, prices_entered_with_tax",[- (True, "25.00", "30.75", False),- (False, "40.65", "50.00", True),- (False, "50.00", "61.50", False),- (True, "20.33", "25.00", True),+ ("40.65", "50.00", True),+ ("50.00", "61.50", False),],)@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])def test_calculate_checkout_subtotal(- with_discount,expected_net,expected_gross,prices_entered_with_tax,- discount_info,checkout_with_item,stock,monkeypatch,@@ -1628,14 +1920,64 @@ def test_calculate_checkout_subtotal(checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()- discounts = [discount_info] if with_discount else None+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)+ add_variant_to_checkout(checkout_info, variant, 2)+ lines, _ = fetch_checkout_lines(checkout_with_item)+ total = manager.calculate_checkout_subtotal(checkout_info, lines, address)+ total = quantize_price(total, total.currency)+ assert total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ "expected_net, expected_gross, prices_entered_with_tax",+ [+ ("25.00", "30.75", False),+ ("20.33", "25.00", True),+ ],+)+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])+def test_calculate_checkout_subtotal_with_sale(+ expected_net,+ expected_gross,+ prices_entered_with_tax,+ discount_info,+ checkout_with_item,+ stock,+ monkeypatch,+ ship_to_pl_address,+ shipping_zone,+ address,+ plugin_configuration,+):+ plugin_configuration()+ variant = stock.product_variant+ monkeypatch.setattr(+ "saleor.plugins.avatax.plugin.get_cached_tax_codes_or_fetch",+ lambda _: {"PC040156": "desc"},+ )+ manager = get_plugins_manager()++ tax_configuration = checkout_with_item.channel.tax_configuration+ tax_configuration.prices_entered_with_tax = prices_entered_with_tax+ tax_configuration.charge_taxes = True+ tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])+ tax_configuration.country_exceptions.all().delete()++ checkout_with_item.shipping_address = ship_to_pl_address+ checkout_with_item.shipping_method = shipping_zone.shipping_methods.get()+ checkout_with_item.save()++ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)add_variant_to_checkout(checkout_info, variant, 2)lines, _ = fetch_checkout_lines(checkout_with_item)- total = manager.calculate_checkout_subtotal(- checkout_info, lines, address, discounts+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])++ total = manager.calculate_checkout_subtotal(checkout_info, lines, address)total = quantize_price(total, total.currency)assert total == TaxedMoney(net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")@@ -1675,7 +2017,7 @@ def test_calculate_checkout_subtotal_for_product_without_tax(checkout.save()quantity = 2- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, quantity)lines, _ = fetch_checkout_lines(checkout)@@ -1686,12 +2028,11 @@ def test_calculate_checkout_subtotal_for_product_without_tax(checkout_info.checkout.collection_point,ship_to_pl_address,lines,- [],manager,checkout.channel.shipping_method_listings.all(),)- total = manager.calculate_checkout_subtotal(checkout_info, lines, address, [])+ total = manager.calculate_checkout_subtotal(checkout_info, lines, address)total = quantize_price(total, total.currency)expected_total = variant.channel_listings.first().price_amount * quantityassert total == TaxedMoney(@@ -1744,14 +2085,11 @@ def test_calculate_checkout_subtotal_voucher_on_entire_order(checkout_with_item.discount_amount = net.amountcheckout_with_item.save()- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)# when- total = manager.calculate_checkout_subtotal(- checkout_info, lines, address, discounts- )+ total = manager.calculate_checkout_subtotal(checkout_info, lines, address)# thentotal = quantize_price(total, total.currency)@@ -1805,14 +2143,11 @@ def test_calculate_checkout_subtotal_voucher_on_shipping(checkout_with_item.discount_amount = shipping_channel_listings.price.amountcheckout_with_item.save()- discounts = None- checkout_info = fetch_checkout_info(checkout_with_item, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, [], manager)lines, _ = fetch_checkout_lines(checkout_with_item)# when- total = manager.calculate_checkout_subtotal(- checkout_info, lines, address, discounts- )+ total = manager.calculate_checkout_subtotal(checkout_info, lines, address)# thentotal = quantize_price(total, total.currency)@@ -1913,7 +2248,7 @@ def test_calculate_order_shipping_entire_order_voucher(total = total_price * order.lines.count()order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,@@ -1969,7 +2304,7 @@ def test_calculate_order_shipping_free_shipping_voucher(discount_amount = Decimal("10.0")order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=discount_amount,name=voucher_free_shipping.code,@@ -2028,7 +2363,7 @@ def test_calculate_order_shipping_voucher_on_shipping(discount_amount = shipping_channel_listings.price.amount - Decimal("5")order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=discount_amount,name=voucher_shipping_type.code,@@ -2292,13 +2627,12 @@ def test_calculate_checkout_line_unit_price(tax_configuration.save(update_fields=["charge_taxes", "prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)line_price = manager.calculate_checkout_line_unit_price(checkout_info,lines,checkout_line,checkout.shipping_address,- [],)if charge_taxes:@@ -2340,13 +2674,12 @@ def test_calculate_checkout_line_unit_price_in_JPY(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)line_price = manager.calculate_checkout_line_unit_price(checkout_info,lines,checkout_line,checkout.shipping_address,- [],)assert line_price == TaxedMoney(net=Money("976", "JPY"), gross=Money("1200", "JPY"))@@ -2380,8 +2713,11 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_unit_price(@@ -2389,7 +2725,6 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale(lines,checkout_line,checkout.shipping_address,- discounts=[discount_info],)# then@@ -2440,7 +2775,7 @@ def test_calculate_checkout_line_unit_price_with_voucher(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency# when@@ -2449,7 +2784,6 @@ def test_calculate_checkout_line_unit_price_with_voucher(lines,checkout_line_info,checkout.shipping_address,- discounts=[],)# then@@ -2501,7 +2835,7 @@ def test_calculate_checkout_line_unit_price_with_voucher_once_per_order(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency# when@@ -2510,7 +2844,6 @@ def test_calculate_checkout_line_unit_price_with_voucher_once_per_order(lines,checkout_line_info,checkout.shipping_address,- discounts=[],)# then@@ -2563,8 +2896,11 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale_and_voucher(tax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_unit_price(@@ -2572,7 +2908,6 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale_and_voucher(lines,checkout_line_info,checkout.shipping_address,- discounts=[discount_info],)# then@@ -2625,8 +2960,11 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale_and_voucher_onltax_configuration.save(update_fields=["prices_entered_with_tax"])tax_configuration.country_exceptions.all().delete()- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)currency = checkout_info.checkout.currency+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenline_price = manager.calculate_checkout_line_unit_price(@@ -2634,7 +2972,6 @@ def test_calculate_checkout_line_unit_price_with_variant_on_sale_and_voucher_onllines,checkout_line_info,checkout.shipping_address,- discounts=[discount_info],)# then@@ -2667,10 +3004,12 @@ def test_preprocess_order_creation(checkout_with_item.shipping_address = ship_to_pl_addresscheckout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()- discounts = [discount_info]lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)- manager.preprocess_order_creation(checkout_info, discounts, lines)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )+ manager.preprocess_order_creation(checkout_info, lines)@pytest.mark.vcr@@ -2697,10 +3036,12 @@ def test_preprocess_order_creation_no_lines_data(checkout_with_item.shipping_address = ship_to_pl_addresscheckout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()- discounts = [discount_info]lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)- manager.preprocess_order_creation(checkout_info, discounts)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )+ manager.preprocess_order_creation(checkout_info)@pytest.mark.vcr@@ -2724,11 +3065,13 @@ def test_preprocess_order_creation_wrong_data(checkout_with_item.shipping_address = addresscheckout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()- discounts = [discount_info]lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )with pytest.raises(TaxError):- manager.preprocess_order_creation(checkout_info, discounts, lines)+ manager.preprocess_order_creation(checkout_info, lines)@pytest.mark.vcr@@ -2764,11 +3107,13 @@ def test_preprocess_order_creation_shipping_voucher_no_tax_class_on_delivery_metshipping_method.refresh_from_db()assert not shipping_method.tax_class- discounts = [discount_info]lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )- manager.preprocess_order_creation(checkout_info, discounts)+ manager.preprocess_order_creation(checkout_info)@pytest.mark.vcr@@ -2809,7 +3154,7 @@ def test_checkout_needs_new_fetch(checkout_with_item, address, shipping_method):)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_data = generate_request_data_from_checkout(checkout_info, lines, config)assert taxes_need_new_fetch(checkout_data, None)@@ -2840,7 +3185,7 @@ def test_generate_request_data_from_checkout_for_cc()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whenrequest_data = generate_request_data_from_checkout(checkout_info, lines, config)@@ -2885,7 +3230,7 @@ def test_generate_request_data_from_checkout_for_cc_and_single_location(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whenrequest_data = generate_request_data_from_checkout(@@ -2930,12 +3275,10 @@ def test_get_checkout_tax_data_with_single_point(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# when- response = get_checkout_tax_data(- checkout_info, lines, discounts=[], config=avatax_config- )+ response = get_checkout_tax_data(checkout_info, lines, config=avatax_config)# thenassert len(response.get("addresses", [])) == 1@@ -2954,7 +3297,7 @@ def test_taxes_need_new_fetch_uses_cached_data(checkout_with_item, address):)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_data = generate_request_data_from_checkout(checkout_info, lines, config)assert not taxes_need_new_fetch(checkout_data, (checkout_data, None))@@ -3011,7 +3354,6 @@ def test_get_checkout_line_tax_rate(lines,checkout_line_info,checkout_with_item.shipping_address,- [],unit_price,)@@ -3080,7 +3422,6 @@ def test_get_checkout_line_tax_rate_for_product_with_charge_taxes_set_to_false(lines,checkout_line_info,checkout_with_item.shipping_address,- [],unit_price,)@@ -3158,7 +3499,6 @@ def test_get_checkout_line_tax_rate_for_product_type_with_non_taxable_product(lines,checkout_line_info,checkout_with_item.shipping_address,- [],unit_price,)for checkout_line_info in lines@@ -3184,7 +3524,7 @@ def test_get_checkout_line_tax_rate_checkout_no_shipping_method_default_value_recheckout_with_item.save(update_fields=["shipping_address"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]# when@@ -3193,7 +3533,6 @@ def test_get_checkout_line_tax_rate_checkout_no_shipping_method_default_value_relines,checkout_line_info,checkout_with_item.shipping_address,- [],unit_price,)@@ -3220,7 +3559,7 @@ def test_get_checkout_line_tax_rate_error_in_response(checkout_with_item.save(update_fields=["shipping_address", "shipping_method"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]# when@@ -3229,7 +3568,6 @@ def test_get_checkout_line_tax_rate_error_in_response(lines,checkout_line_info,checkout_with_item.shipping_address,- [],unit_price,)@@ -3355,14 +3693,13 @@ def test_get_checkout_shipping_tax_rate(checkout_with_item.save(update_fields=["shipping_address", "shipping_method"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whentax_rate = manager.get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [],shipping_price,)@@ -3410,14 +3747,13 @@ def test_get_checkout_shipping_tax_rate_checkout_not_valid_default_value_returnecheckout_with_item.save(update_fields=["shipping_address"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whentax_rate = manager.get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [],shipping_price,)@@ -3444,14 +3780,13 @@ def test_get_checkout_shipping_tax_rate_error_in_response(checkout_with_item.save(update_fields=["shipping_address", "shipping_method"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whentax_rate = manager.get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [],shipping_price,)@@ -3478,14 +3813,13 @@ def test_get_checkout_shipping_tax_rate_skip_plugin(checkout_with_item.save(update_fields=["shipping_address", "shipping_method"])lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# whentax_rate = manager.get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [],shipping_price,)@@ -3845,10 +4179,12 @@ def test_plugin_uses_configuration_from_db(checkout_with_item.shipping_address = ship_to_pl_addresscheckout_with_item.shipping_method = shipping_zone.shipping_methods.get()checkout_with_item.save()- discounts = [discount_info]lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, discounts, manager)- manager.preprocess_order_creation(checkout_info, discounts, lines)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )+ manager.preprocess_order_creation(checkout_info, lines)field_to_update = [{"name": "Username or account", "value": "New value"},@@ -3859,7 +4195,7 @@ def test_plugin_uses_configuration_from_db(manager = get_plugins_manager()with pytest.raises(TaxError):- manager.preprocess_order_creation(checkout_info, discounts, lines)+ manager.preprocess_order_creation(checkout_info, lines)def test_skip_disabled_plugin(settings, plugin_configuration):@@ -4120,7 +4456,7 @@ def test_get_order_request_data_confirmed_order_with_voucher(line.save()order_with_lines.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,@@ -4213,7 +4549,7 @@ def test_get_order_request_data_draft_order_with_voucher(line.save()order_with_lines.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal("10.0"),name=voucher.code,@@ -4269,7 +4605,7 @@ def test_get_order_request_data_draft_order_with_shipping_voucher(line.save()order_with_lines.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=Decimal("100.0"),name=voucher_free_shipping.code,@@ -4328,7 +4664,7 @@ def test_get_order_request_data_draft_order_shipping_voucher_amount_too_high(line.save()order_with_lines.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=Decimal("100.0"),name=voucher_free_shipping.code,@@ -4611,7 +4947,7 @@ def test_validate_checkout_click_and_collect()lines_info, _ = fetch_checkout_lines(user_checkout_with_items_for_cc)checkout_info = fetch_checkout_info(- user_checkout_with_items_for_cc, lines_info, [], get_plugins_manager()+ user_checkout_with_items_for_cc, lines_info, get_plugins_manager())# when@@ -4638,7 +4974,7 @@ def test_generate_request_data_from_checkout_lines_uses_tax_code_from_product_talines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4671,7 +5007,7 @@ def test_generate_request_data_from_checkout_lines_uses_tax_code_from_product_tylines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4700,7 +5036,7 @@ def test_generate_request_data_from_checkout_lines_sets_different_tax_code_for_zlines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4733,7 +5069,7 @@ def test_generate_request_data_from_checkout_lines_sets_different_tax_code_only_lines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4775,7 +5111,7 @@ def test_generate_request_data_from_checkout_lines_with_collection_point(lines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4815,7 +5151,7 @@ def test_generate_request_data_from_checkout_lines_with_shipping_method(lines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())config = avatax_config@@ -4849,7 +5185,7 @@ def test_generate_request_data_from_checkout_lines_adds_lines_with_taxes_disablelines, _ = fetch_checkout_lines(checkout_with_item)checkout_info = fetch_checkout_info(- checkout_with_item, lines, [], get_plugins_manager()+ checkout_with_item, lines, get_plugins_manager())# when@@ -5153,14 +5489,13 @@ def test_calculate_checkout_shipping_validates_checkout(line.product_type.is_shipping_required = Trueline.product_type.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenmanager.calculate_checkout_shipping(checkout_info,lines,checkout.shipping_address,- discounts=[],)# then@@ -5185,7 +5520,7 @@ def test_calculate_checkout_line_total_validates_checkout(line.product_type.is_shipping_required = Trueline.product_type.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenmanager.calculate_checkout_line_total(@@ -5193,7 +5528,6 @@ def test_calculate_checkout_line_total_validates_checkout(lines,lines[0],checkout.shipping_address,- discounts=[],)# then@@ -5218,7 +5552,7 @@ def test_calculate_checkout_line_unit_price_validates_checkout(line.product_type.is_shipping_required = Trueline.product_type.save()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenmanager.calculate_checkout_line_unit_price(@@ -5226,7 +5560,6 @@ def test_calculate_checkout_line_unit_price_validates_checkout(lines,lines[0],checkout.shipping_address,- discounts=[],)# thendiff --git a/saleor/plugins/avatax/tests/test_avatax_caching.py b/saleor/plugins/avatax/tests/test_avatax_caching.pyindex c5036d1a6d..ef1bfd2b2d 100644--- a/saleor/plugins/avatax/tests/test_avatax_caching.py+++ b/saleor/plugins/avatax/tests/test_avatax_caching.py@@ -45,7 +45,7 @@ def test_calculate_checkout_total_use_cache(# thenresult = manager.calculate_checkout_total(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# when@@ -83,10 +83,10 @@ def test_calculate_checkout_total_save_avatax_response_in_cache(# thenresult = manager.calculate_checkout_total(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)manager.calculate_checkout_total(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# Second Avatax call to make sure that we use cached response@@ -134,7 +134,7 @@ def test_calculate_checkout_subtotal_use_cache(# thenresult = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# when@@ -172,10 +172,10 @@ def test_calculate_checkout_subtotal_save_avatax_response_in_cache(# thenresult = manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)manager.calculate_checkout_subtotal(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# Second Avatax call to make sure that we use cached response@@ -223,7 +223,7 @@ def test_calculate_checkout_shipping_use_cache(# thenresult = manager.calculate_checkout_shipping(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# when@@ -261,10 +261,10 @@ def test_calculate_checkout_shipping_save_avatax_response_in_cache(# thenresult = manager.calculate_checkout_shipping(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)manager.calculate_checkout_shipping(- checkout_info, lines, checkout_info.shipping_address, []+ checkout_info, lines, checkout_info.shipping_address)# Second Avatax call to make sure that we use cached response@@ -313,7 +313,10 @@ def test_calculate_checkout_line_total_use_cache(# thenresult = manager.calculate_checkout_line_total(- checkout_info, lines, checkout_line_info, checkout_info.shipping_address, []+ checkout_info,+ lines,+ checkout_line_info,+ checkout_info.shipping_address,)# when@@ -352,10 +355,10 @@ def test_calculate_checkout_line_save_avatax_response_in_cache(# thenresult = manager.calculate_checkout_line_total(- checkout_info, lines, checkout_line_info, checkout_info.shipping_address, []+ checkout_info, lines, checkout_line_info, checkout_info.shipping_address)manager.calculate_checkout_line_total(- checkout_info, lines, checkout_line_info, checkout_info.shipping_address, []+ checkout_info, lines, checkout_line_info, checkout_info.shipping_address)# Second Avatax call to make sure that we use cached response@@ -408,7 +411,6 @@ def test_calculate_checkout_line_unit_price_use_cache(lines,checkout_line_info,checkout_info.shipping_address,- [],)# when@@ -451,14 +453,12 @@ def test_calculate_checkout_line_unit_price_save_avatax_response_in_cache(lines,checkout_line_info,checkout_info.shipping_address,- [],)manager.calculate_checkout_line_unit_price(checkout_info,lines,checkout_line_info,checkout_info.shipping_address,- [],)# Second Avatax call to make sure that we use cached response@@ -512,7 +512,6 @@ def test_get_checkout_line_tax_rate_use_cache(lines,checkout_line_info,checkout_info.shipping_address,- [],fake_unit_price,)@@ -557,7 +556,6 @@ def test_get_checkout_line_tax_rate_save_avatax_response_in_cache(lines,checkout_line_info,checkout_info.shipping_address,- [],fake_unit_price,)manager.get_checkout_line_tax_rate(@@ -565,7 +563,6 @@ def test_get_checkout_line_tax_rate_save_avatax_response_in_cache(lines,checkout_line_info,checkout_info.shipping_address,- [],fake_unit_price,)# Second Avatax call to make sure that we use cached response@@ -615,7 +612,7 @@ def test_get_checkout_shipping_tax_rate_use_cache(# thenresult = manager.get_checkout_shipping_tax_rate(- checkout_info, lines, checkout_info.shipping_address, [], fake_shipping_price+ checkout_info, lines, checkout_info.shipping_address, fake_shipping_price)# when@@ -654,10 +651,10 @@ def test_get_checkout_shipping_tax_rate_save_avatax_response_in_cache(# thenresult = manager.get_checkout_shipping_tax_rate(- checkout_info, lines, checkout_info.shipping_address, [], fake_shipping_price+ checkout_info, lines, checkout_info.shipping_address, fake_shipping_price)manager.get_checkout_shipping_tax_rate(- checkout_info, lines, checkout_info.shipping_address, [], fake_shipping_price+ checkout_info, lines, checkout_info.shipping_address, fake_shipping_price)# Second Avatax call to make sure that we use cached responsediff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.pyindex 3eb0de83e5..9aa5c10efd 100644--- a/saleor/plugins/base_plugin.py+++ b/saleor/plugins/base_plugin.py@@ -46,7 +46,6 @@ if TYPE_CHECKING:from ..core.middleware import Requestorfrom ..core.notify_events import NotifyEventTypefrom ..core.taxes import TaxData, TaxType- from ..discount import DiscountInfofrom ..discount.models import Sale, Voucherfrom ..giftcard.models import GiftCardfrom ..invoice.models import Invoice@@ -248,7 +247,6 @@ class BasePlugin:List["CheckoutLineInfo"],"CheckoutLineInfo",Union["Address", None],- Iterable["DiscountInfo"],TaxedMoney,],TaxedMoney,@@ -261,7 +259,6 @@ class BasePlugin:List["CheckoutLineInfo"],"CheckoutLineInfo",Union["Address", None],- Iterable["DiscountInfo"],Any,],TaxedMoney,@@ -276,7 +273,6 @@ class BasePlugin:"CheckoutInfo",List["CheckoutLineInfo"],Union["Address", None],- List["DiscountInfo"],TaxedMoney,],TaxedMoney,@@ -291,7 +287,20 @@ class BasePlugin:"CheckoutInfo",List["CheckoutLineInfo"],Union["Address", None],- List["DiscountInfo"],+ TaxedMoney,+ ],+ TaxedMoney,+ ]++ # Calculate the subtotal for checkout.+ #+ # Overwrite this method if you need to apply specific logic for the calculation+ # of a checkout subtotal. Return TaxedMoney.+ calculate_checkout_subtotal: Callable[+ [+ "CheckoutInfo",+ List["CheckoutLineInfo"],+ Union["Address", None],TaxedMoney,],TaxedMoney,@@ -517,7 +526,6 @@ class BasePlugin:List["CheckoutLineInfo"],"CheckoutLineInfo",Union["Address", None],- Iterable["DiscountInfo"],Decimal,],Decimal,@@ -528,7 +536,6 @@ class BasePlugin:"CheckoutInfo",Iterable["CheckoutLineInfo"],Union["Address", None],- Iterable["DiscountInfo"],Any,],Any,@@ -790,7 +797,6 @@ class BasePlugin:preprocess_order_creation: Callable[["CheckoutInfo",- List["DiscountInfo"],Union[Iterable["CheckoutLineInfo"], None],Any,],diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.pyindex e6e6e31213..0c105c7fea 100644--- a/saleor/plugins/manager.py+++ b/saleor/plugins/manager.py@@ -29,7 +29,6 @@ from ..core.models import EventDeliveryfrom ..core.payments import PaymentInterfacefrom ..core.prices import quantize_pricefrom ..core.taxes import TaxData, TaxType, zero_money, zero_taxed_money-from ..discount import DiscountInfofrom ..graphql.core import ResolveInfo, SaleorContextfrom ..order import base_calculations as base_order_calculationsfrom ..order.interface import OrderTaxedPricesData@@ -177,7 +176,7 @@ class PluginsManager(PaymentInterface):default_value: Any,*args,channel_slug: Optional[str] = None,- **kwargs+ **kwargs,):"""Try to run a method with the given name on each declared active plugin."""value = default_value@@ -234,13 +233,11 @@ class PluginsManager(PaymentInterface):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],) -> TaxedMoney:currency = checkout_info.checkout.currencydefault_value = base_calculations.checkout_total(checkout_info,- discounts,lines,)taxed_default_value = TaxedMoney(net=default_value, gross=default_value)@@ -258,7 +255,6 @@ class PluginsManager(PaymentInterface):checkout_info,lines,address,- discounts,channel_slug=checkout_info.channel.slug,),currency,@@ -269,7 +265,6 @@ class PluginsManager(PaymentInterface):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],) -> TaxedMoney:line_totals = [self.calculate_checkout_line_total(@@ -277,7 +272,6 @@ class PluginsManager(PaymentInterface):lines,line_info,address,- discounts,)for line_info in lines]@@ -293,7 +287,6 @@ class PluginsManager(PaymentInterface):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],) -> TaxedMoney:price = base_calculations.base_checkout_delivery_price(checkout_info, lines)default_value = TaxedMoney(price, price)@@ -304,7 +297,6 @@ class PluginsManager(PaymentInterface):checkout_info,lines,address,- discounts,channel_slug=checkout_info.channel.slug,),checkout_info.checkout.currency,@@ -356,7 +348,6 @@ class PluginsManager(PaymentInterface):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable[DiscountInfo],shipping_price: TaxedMoney,):default_value = calculate_tax_rate(shipping_price)@@ -366,7 +357,6 @@ class PluginsManager(PaymentInterface):checkout_info,lines,address,- discounts,channel_slug=checkout_info.channel.slug,).quantize(Decimal(".0001"))@@ -385,19 +375,16 @@ class PluginsManager(PaymentInterface):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],) -> TaxedMoney:default_value = base_calculations.calculate_base_line_total_price(checkout_line_info,checkout_info.channel,- discounts,)# apply entire order discountdefault_value = base_calculations.apply_checkout_discount_on_checkout_line(checkout_info,lines,checkout_line_info,- discounts,default_value,)default_value = quantize_price(default_value, checkout_info.checkout.currency)@@ -409,7 +396,6 @@ class PluginsManager(PaymentInterface):lines,checkout_line_info,address,- discounts,channel_slug=checkout_info.channel.slug,)@@ -449,18 +435,16 @@ class PluginsManager(PaymentInterface):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],) -> TaxedMoney:quantity = checkout_line_info.line.quantitydefault_value = base_calculations.calculate_base_line_unit_price(- checkout_line_info, checkout_info.channel, discounts+ checkout_line_info, checkout_info.channel)# apply entire order discounttotal_value = base_calculations.apply_checkout_discount_on_checkout_line(checkout_info,lines,checkout_line_info,- discounts,default_value * quantity,)default_taxed_value = TaxedMoney(@@ -473,7 +457,6 @@ class PluginsManager(PaymentInterface):lines,checkout_line_info,address,- discounts,channel_slug=checkout_info.channel.slug,)return quantize_price(unit_price, checkout_info.checkout.currency)@@ -519,7 +502,6 @@ class PluginsManager(PaymentInterface):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable[DiscountInfo],unit_price: TaxedMoney,) -> Decimal:default_value = calculate_tax_rate(unit_price)@@ -530,7 +512,6 @@ class PluginsManager(PaymentInterface):lines,checkout_line_info,address,- discounts,channel_slug=checkout_info.channel.slug,).quantize(Decimal(".0001"))@@ -577,7 +558,6 @@ class PluginsManager(PaymentInterface):def preprocess_order_creation(self,checkout_info: "CheckoutInfo",- discounts: Iterable[DiscountInfo],lines: Optional[Iterable["CheckoutLineInfo"]] = None,):default_value = None@@ -585,7 +565,6 @@ class PluginsManager(PaymentInterface):"preprocess_order_creation",default_value,checkout_info,- discounts,lines,channel_slug=checkout_info.channel.slug,)diff --git a/saleor/plugins/tests/sample_plugins.py b/saleor/plugins/tests/sample_plugins.pyindex a146fd32cb..35b030f60d 100644--- a/saleor/plugins/tests/sample_plugins.py+++ b/saleor/plugins/tests/sample_plugins.py@@ -28,7 +28,6 @@ if TYPE_CHECKING:from ...checkout.fetch import CheckoutInfo, CheckoutLineInfofrom ...checkout.models import Checkoutfrom ...core.models import EventDelivery- from ...discount import DiscountInfofrom ...discount.models import Salefrom ...order.models import Order, OrderLinefrom ...product.models import Product, ProductVariant@@ -105,14 +104,12 @@ class PluginSample(BasePlugin):return JsonResponse(data={"received": True, "paid": False})return HttpResponseNotFound()- def calculate_checkout_total(- self, checkout_info, lines, address, discounts, previous_value- ):+ def calculate_checkout_total(self, checkout_info, lines, address, previous_value):total = Money("1.0", currency=checkout_info.checkout.currency)return TaxedMoney(total, total)def calculate_checkout_shipping(- self, checkout_info, lines, address, discounts, previous_value+ self, checkout_info, lines, address, previous_value):price = Money("1.0", currency=checkout_info.checkout.currency)return TaxedMoney(price, price)@@ -127,7 +124,6 @@ class PluginSample(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: TaxedMoney,):# See if delivery method doesn't trigger infinite recursion@@ -156,7 +152,6 @@ class PluginSample(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: TaxedMoney,):currency = checkout_info.checkout.currency@@ -256,7 +251,6 @@ class PluginSample(BasePlugin):lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: Decimal,) -> Decimal:return Decimal("0.080").quantize(Decimal(".01"))@@ -276,7 +270,6 @@ class PluginSample(BasePlugin):checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],address: Optional["Address"],- discounts: Iterable["DiscountInfo"],previous_value: Decimal,):return Decimal("0.080").quantize(Decimal(".01"))diff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.pyindex a60b35dfe8..b232e6d62f 100644--- a/saleor/plugins/tests/test_manager.py+++ b/saleor/plugins/tests/test_manager.py@@ -12,7 +12,10 @@ from ...channel import TransactionFlowStrategyfrom ...checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ...core.prices import quantize_pricefrom ...core.taxes import TaxType, zero_money, zero_taxed_money-from ...discount.utils import fetch_catalogue_info+from ...discount.utils import (+ create_or_update_discount_objects_from_sale_for_checkout,+ fetch_catalogue_info,+)from ...graphql.discount.mutations.utils import convert_catalogue_info_to_global_idsfrom ...payment.interface import (PaymentGateway,@@ -162,12 +165,11 @@ def test_manager_calculates_checkout_total(expected_total = Money(total_amount, currency)manager = PluginsManager(plugins=plugins)lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )- taxed_total = manager.calculate_checkout_total(- checkout_info, lines, None, [discount_info]+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])+ taxed_total = manager.calculate_checkout_total(checkout_info, lines, None)assert TaxedMoney(expected_total, expected_total) == taxed_total@@ -182,11 +184,12 @@ def test_manager_calculates_checkout_subtotal(expected_subtotal = Money(subtotal_amount, currency)manager = PluginsManager(plugins=plugins)lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])taxed_subtotal = PluginsManager(plugins=plugins).calculate_checkout_subtotal(- checkout_info, lines, None, [discount_info]+ checkout_info, lines, None)assert TaxedMoney(expected_subtotal, expected_subtotal) == taxed_subtotal@@ -202,11 +205,9 @@ def test_manager_calculates_checkout_shipping(expected_shipping_price = Money(shipping_amount, currency)manager = PluginsManager(plugins=plugins)lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)taxed_shipping_price = PluginsManager(plugins=plugins).calculate_checkout_shipping(- checkout_info, lines, None, [discount_info]+ checkout_info, lines, None)assert (TaxedMoney(expected_shipping_price, expected_shipping_price)@@ -242,8 +243,9 @@ def test_manager_calculates_checkout_line_total(expected_total = Money(amount, currency)manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info])checkout_line_info = lines[0]taxed_total = PluginsManager(plugins=plugins).calculate_checkout_line_total(@@ -251,7 +253,6 @@ def test_manager_calculates_checkout_line_total(lines,checkout_line_info,checkout_with_item.shipping_address,- [discount_info],)assert TaxedMoney(expected_total, expected_total) == taxed_total@@ -281,17 +282,13 @@ def test_manager_calculates_order_line_total(order_line, plugins):assert expected_total == taxed_total-def test_manager_get_checkout_line_tax_rate_sample_plugin(- checkout_with_item, discount_info-):+def test_manager_get_checkout_line_tax_rate_sample_plugin(checkout_with_item):plugins = ["saleor.plugins.tests.sample_plugins.PluginSample"]unit_price = TaxedMoney(Money(12, "USD"), Money(15, "USD"))manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]tax_rate = PluginsManager(plugins=plugins).get_checkout_line_tax_rate(@@ -299,7 +296,6 @@ def test_manager_get_checkout_line_tax_rate_sample_plugin(lines,checkout_line_info,checkout_with_item.shipping_address,- [discount_info],unit_price,)assert tax_rate == Decimal("0.08")@@ -313,20 +309,17 @@ def test_manager_get_checkout_line_tax_rate_sample_plugin(],)def test_manager_get_checkout_line_tax_rate_no_plugins(- checkout_with_item, discount_info, unit_price, expected_tax_rate+ checkout_with_item, unit_price, expected_tax_rate):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]tax_rate = PluginsManager(plugins=[]).get_checkout_line_tax_rate(checkout_info,lines,checkout_line_info,checkout_with_item.shipping_address,- [discount_info],unit_price,)assert tax_rate == expected_tax_rate@@ -371,23 +364,18 @@ def test_manager_get_order_line_tax_rate_no_plugins(assert tax_rate == expected_tax_rate-def test_manager_get_checkout_shipping_tax_rate_sample_plugin(- checkout_with_item, discount_info-):+def test_manager_get_checkout_shipping_tax_rate_sample_plugin(checkout_with_item):plugins = ["saleor.plugins.tests.sample_plugins.PluginSample"]shipping_price = TaxedMoney(Money(12, "USD"), Money(14, "USD"))manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)tax_rate = PluginsManager(plugins=plugins).get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [discount_info],shipping_price,)assert tax_rate == Decimal("0.08")@@ -401,19 +389,16 @@ def test_manager_get_checkout_shipping_tax_rate_sample_plugin(],)def test_manager_get_checkout_shipping_tax_rate_no_plugins(- checkout_with_item, discount_info, shipping_price, expected_tax_rate+ checkout_with_item, shipping_price, expected_tax_rate):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)tax_rate = PluginsManager(plugins=[]).get_checkout_shipping_tax_rate(checkout_info,lines,checkout_with_item.shipping_address,- [discount_info],shipping_price,)assert tax_rate == expected_tax_rate@@ -474,7 +459,7 @@ def test_manager_calculates_checkout_line_unit_price():manager = PluginsManager(plugins=plugins)lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)checkout_line_info = lines[0]taxed_total = PluginsManager(plugins=plugins).calculate_checkout_line_unit_price(@@ -482,7 +467,6 @@ def test_manager_calculates_checkout_line_unit_price(lines,checkout_line_info,address,- [],)currency = total_line_price.net.currencyexpected_net = Money(@@ -552,7 +536,7 @@ def test_manager_get_taxes_for_checkout():lines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)assert PluginsManager(plugins=plugins).get_taxes_for_checkout(checkout_info, lines) == expected_tax_data(checkout)@@ -1141,14 +1125,10 @@ def test_calculate_checkout_total_zero_default_value(mocked_base_checkout_total.return_value = zero_money(currency)manager = PluginsManager(plugins=plugins)lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(- checkout_with_item, lines, [discount_info], manager- )+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)# when- taxed_total = manager.calculate_checkout_total(- checkout_info, lines, None, [discount_info]- )+ taxed_total = manager.calculate_checkout_total(checkout_info, lines, None)# thenassert "calculate_checkout_total" not in mocked_run_method.call_args_listdiff --git a/saleor/plugins/webhook/tests/test_tax_webhook.py b/saleor/plugins/webhook/tests/test_tax_webhook.pyindex d77e8fb366..975a24431b 100644--- a/saleor/plugins/webhook/tests/test_tax_webhook.py+++ b/saleor/plugins/webhook/tests/test_tax_webhook.py@@ -25,7 +25,7 @@ def test_get_taxes_for_checkout_no_permission(# givenplugin = webhook_plugin()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], plugin)+ checkout_info = fetch_checkout_info(checkout, lines, plugin)# whentax_data = plugin.get_taxes_for_checkout(checkout_info, lines, None)@@ -198,7 +198,7 @@ def test_get_taxes_for_checkout_with_sync_subscription(tax_app,):# given- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())mock_request.return_value = tax_data_responseplugin = webhook_plugin()webhook = Webhook.objects.create(diff --git a/saleor/plugins/webhook/tests/test_webhook.py b/saleor/plugins/webhook/tests/test_webhook.pyindex 23f0e1a8e6..199c40a17a 100644--- a/saleor/plugins/webhook/tests/test_webhook.py+++ b/saleor/plugins/webhook/tests/test_webhook.py@@ -24,12 +24,16 @@ from ....account.notifications import (send_account_confirmation,)from ....app.models import App+from ....checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ....core import EventDeliveryStatusfrom ....core.models import EventDelivery, EventDeliveryAttempt, EventPayloadfrom ....core.notification.utils import get_site_contextfrom ....core.notify_events import NotifyEventTypefrom ....core.utils.url import prepare_url-from ....discount.utils import fetch_catalogue_info+from ....discount.utils import (+ create_or_update_discount_objects_from_sale_for_checkout,+ fetch_catalogue_info,+)from ....graphql.discount.mutations.utils import convert_catalogue_info_to_global_idsfrom ....payment import TransactionAction, TransactionEventTypefrom ....payment.interface import TransactionActionData@@ -931,7 +935,14 @@ def test_checkout_created(def test_checkout_payload_includes_sales(checkout_with_item, sale, discount_info):- data = json.loads(generate_checkout_payload(checkout_with_item))+ # given+ checkout = checkout_with_item+ checkout_lines, _ = fetch_checkout_lines(checkout, prefetch_variant_attributes=True)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines, [discount_info]+ )variant = checkout_with_item.lines.first().variantchannel_listing = variant.channel_listings.first()variant_price_with_sale = variant.get_price(@@ -948,6 +959,11 @@ def test_checkout_payload_includes_sales(checkout_with_item, sale, discount_infochannel_listing=channel_listing,discounts=[],)++ # when+ data = json.loads(generate_checkout_payload(checkout))++ # thenassert variant_price_without_sale > variant_price_with_saleassert Decimal(data[0]["lines"][0]["base_price"]) == variant_price_with_sale.amountdiff --git a/saleor/product/models.py b/saleor/product/models.pyindex c1a6032dec..0f449b636b 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -635,6 +635,17 @@ class ProductVariant(SortableModel, ModelWithMetadata, ModelWithExternalReferencdef get_global_id(self):return graphene.Node.to_global_id("ProductVariant", self.id)+ def get_base_price(+ self,+ channel_listing: "ProductVariantChannelListing",+ price_override: Optional["Decimal"] = None,+ ):+ return (+ channel_listing.price+ if price_override is None+ else Money(price_override, channel_listing.currency)+ )+def get_price(self,product: Product,@@ -644,11 +655,7 @@ class ProductVariant(SortableModel, ModelWithMetadata, ModelWithExternalReferencdiscounts: Optional[Iterable[DiscountInfo]] = None,price_override: Optional["Decimal"] = None,) -> "Money":- price = (- channel_listing.price- if price_override is None- else Money(price_override, channel_listing.currency)- )+ price = self.get_base_price(channel_listing, price_override)return calculate_discounted_price(product=product,price=price,diff --git a/saleor/tax/calculations/checkout.py b/saleor/tax/calculations/checkout.pyindex 88b200818e..3f99dfcdef 100644--- a/saleor/tax/calculations/checkout.py+++ b/saleor/tax/calculations/checkout.py@@ -6,14 +6,12 @@ from prices import TaxedMoneyfrom ...checkout import base_calculationsfrom ...core.prices import quantize_pricefrom ...core.taxes import zero_taxed_money-from ...discount import DiscountInfofrom ..models import TaxClassCountryRatefrom ..utils import get_tax_rate_for_tax_class, normalize_tax_rate_for_dbfrom . import calculate_flat_rate_taxif TYPE_CHECKING:from ...account.models import Address- from ...channel.models import Channelfrom ...checkout.fetch import CheckoutInfo, CheckoutLineInfofrom ...checkout.models import Checkout@@ -24,11 +22,7 @@ def update_checkout_prices_with_flat_rates(lines: Iterable["CheckoutLineInfo"],prices_entered_with_tax: bool,address: Optional["Address"] = None,- discounts: Optional[Iterable[DiscountInfo]] = None,):- if not discounts:- discounts = []-country_code = (address.country.code if address else checkout_info.channel.default_country.code)@@ -54,7 +48,6 @@ def update_checkout_prices_with_flat_rates(checkout_info,lines,line_info,- discounts,tax_rate,prices_entered_with_tax,)@@ -103,44 +96,20 @@ def calculate_checkout_line_total(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],checkout_line_info: "CheckoutLineInfo",- discounts: Iterable["DiscountInfo"],tax_rate: Decimal,prices_entered_with_tax: bool,) -> TaxedMoney:- unit_taxed_price = _calculate_checkout_line_unit_price(- checkout_info,- lines,+ base_total_price = base_calculations.calculate_base_line_total_price(checkout_line_info,checkout_info.channel,- discounts,- tax_rate,- prices_entered_with_tax,- )- quantity = checkout_line_info.line.quantity- return quantize_price(unit_taxed_price * quantity, unit_taxed_price.currency)---def _calculate_checkout_line_unit_price(- checkout_info: "CheckoutInfo",- lines: Iterable["CheckoutLineInfo"],- checkout_line_info: "CheckoutLineInfo",- channel: "Channel",- discounts: Iterable["DiscountInfo"],- tax_rate: Decimal,- prices_entered_with_tax: bool,-):- quantity = checkout_line_info.line.quantity- unit_price = base_calculations.calculate_base_line_unit_price(- checkout_line_info,- channel,- discounts,)total_price = base_calculations.apply_checkout_discount_on_checkout_line(checkout_info,lines,checkout_line_info,- discounts,- unit_price * quantity,+ base_total_price,+ )+ total_price = calculate_flat_rate_tax(+ total_price, tax_rate, prices_entered_with_tax)- unit_price = total_price / quantity- return calculate_flat_rate_tax(unit_price, tax_rate, prices_entered_with_tax)+ return quantize_price(total_price, total_price.currency)diff --git a/saleor/tax/calculations/order.py b/saleor/tax/calculations/order.pyindex 07993cc6b6..000f4343d4 100644--- a/saleor/tax/calculations/order.py+++ b/saleor/tax/calculations/order.py@@ -5,7 +5,7 @@ from prices import Money, TaxedMoneyfrom ...core.prices import quantize_pricefrom ...core.taxes import zero_money, zero_taxed_money-from ...discount import OrderDiscountType+from ...discount import DiscountTypefrom ...order import base_calculationsfrom ...order.utils import (get_order_country,@@ -87,7 +87,7 @@ def _calculate_order_total(undiscounted_subtotal += line.undiscounted_total_pricetotal += order.shipping_price- order_discount = order.discounts.filter(type=OrderDiscountType.MANUAL).first()+ order_discount = order.discounts.filter(type=DiscountType.MANUAL).first()if order_discount and order_discount.amount > undiscounted_subtotal.gross:remaining_amount = order_discount.amount - undiscounted_subtotal.grosstotal -= remaining_amountdiff --git a/saleor/tax/tests/test_checkout_calculations.py b/saleor/tax/tests/test_checkout_calculations.pyindex 101694ccbe..ef95b9997f 100644--- a/saleor/tax/tests/test_checkout_calculations.py+++ b/saleor/tax/tests/test_checkout_calculations.py@@ -7,11 +7,11 @@ from ...checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ...checkout.utils import add_variant_to_checkoutfrom ...core.prices import quantize_pricefrom ...core.taxes import zero_taxed_money+from ...discount.utils import create_or_update_discount_objects_from_sale_for_checkoutfrom ...plugins.manager import get_plugins_managerfrom ...tax.models import TaxClassCountryRatefrom .. import TaxCalculationStrategyfrom ..calculations.checkout import (- _calculate_checkout_line_unit_price,calculate_checkout_line_total,calculate_checkout_shipping,update_checkout_prices_with_flat_rates,@@ -27,22 +27,17 @@ def _enable_flat_rates(checkout, prices_entered_with_tax):@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, voucher_amount, "- "prices_entered_with_tax",+ "expected_net, expected_gross, voucher_amount, prices_entered_with_tax",[- (True, "20.33", "25.00", "0.0", True),- (True, "20.00", "24.60", "5.0", False),- (False, "40.00", "49.20", "0.0", False),- (False, "30.08", "37.00", "3.0", True),+ ("40.00", "49.20", "0.0", False),+ ("30.08", "37.00", "3.0", True),],)def test_calculate_checkout_total(checkout_with_item,address,shipping_zone,- discount_info,voucher,- with_discount,expected_net,expected_gross,voucher_amount,@@ -63,14 +58,69 @@ def test_calculate_checkout_total(product = line.variant.productproduct.tax_class.country_rates.update_or_create(country=address.country, rate=23)- discounts = [discount_info] if with_discount else Nonelines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, discounts+ checkout, checkout_info, lines, prices_entered_with_tax, address+ )++ # then+ assert checkout.total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ "expected_net, expected_gross, voucher_amount, prices_entered_with_tax",+ [+ ("20.33", "25.00", "0.0", True),+ ("20.00", "24.60", "5.0", False),+ ],+)+def test_calculate_checkout_total_with_sale(+ checkout_with_item,+ address,+ shipping_zone,+ voucher,+ discount_info,+ expected_net,+ expected_gross,+ voucher_amount,+ prices_entered_with_tax,+ channel_USD,+):+ # given+ checkout = checkout_with_item+ _enable_flat_rates(checkout, prices_entered_with_tax)++ checkout.shipping_address = address+ voucher_amount = Money(voucher_amount, "USD")+ checkout.shipping_method = shipping_zone.shipping_methods.get()+ checkout.voucher_code = voucher.code+ checkout.discount = voucher_amount+ checkout.save()++ line = checkout.lines.first()+ product = line.variant.product+ product.tax_class.country_rates.update_or_create(country=address.country, rate=23)++ lines, _ = fetch_checkout_lines(checkout)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )++ # when+ update_checkout_prices_with_flat_rates(+ checkout,+ checkout_info,+ lines,+ prices_entered_with_tax,+ address,)# then@@ -98,11 +148,11 @@ def test_calculate_checkout_total_no_tax_rates(lines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, []+ checkout, checkout_info, lines, prices_entered_with_tax, address)# then@@ -131,11 +181,11 @@ def test_calculate_checkout_total_default_tax_rate_for_country(lines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, []+ checkout, checkout_info, lines, prices_entered_with_tax, address)# then@@ -145,22 +195,67 @@ def test_calculate_checkout_total_default_tax_rate_for_country(@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, voucher_amount, "- "prices_entered_with_tax",+ "expected_net, expected_gross, voucher_amount, prices_entered_with_tax",[- (True, "20.33", "25.00", "0.0", True),- (True, "20.00", "24.60", "5.0", False),- (False, "40.00", "49.20", "0.0", False),- (False, "30.08", "37.00", "3.0", True),+ ("40.00", "49.20", "0.0", False),+ ("30.08", "37.00", "3.0", True),],)-def test_calculate_checkout_total_shipping_voucher(+def test_calculate_checkout_total_with_shipping_voucher(+ checkout_with_item,+ address,+ shipping_zone,+ voucher_shipping_type,+ expected_net,+ expected_gross,+ voucher_amount,+ prices_entered_with_tax,+):+ # given+ checkout = checkout_with_item+ _enable_flat_rates(checkout, prices_entered_with_tax)++ manager = get_plugins_manager()+ checkout.shipping_address = address+ checkout.save()+ voucher_amount = Money(voucher_amount, "USD")++ checkout.shipping_method = shipping_zone.shipping_methods.get()+ checkout.voucher_code = voucher_shipping_type.code+ checkout.discount = voucher_amount+ checkout.save()++ line = checkout.lines.first()+ product = line.variant.product+ product.tax_class.country_rates.update_or_create(country=address.country, rate=23)++ lines, _ = fetch_checkout_lines(checkout)+ checkout_info = fetch_checkout_info(checkout, lines, manager)++ # when+ update_checkout_prices_with_flat_rates(+ checkout, checkout_info, lines, prices_entered_with_tax, address+ )++ # then+ assert checkout.total == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ "expected_net, expected_gross, voucher_amount, prices_entered_with_tax",+ [+ ("20.33", "25.00", "0.0", True),+ ("20.00", "24.60", "5.0", False),+ ],+)+def test_calculate_checkout_total_with_shipping_voucher_and_sale(checkout_with_item,address,shipping_zone,discount_info,voucher_shipping_type,- with_discount,expected_net,expected_gross,voucher_amount,@@ -184,13 +279,19 @@ def test_calculate_checkout_total_shipping_voucher(product = line.variant.productproduct.tax_class.country_rates.update_or_create(country=address.country, rate=23)- discounts = [discount_info] if with_discount else Nonelines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, discounts+ checkout,+ checkout_info,+ lines,+ prices_entered_with_tax,+ address,)# then@@ -200,20 +301,65 @@ def test_calculate_checkout_total_shipping_voucher(@pytest.mark.parametrize(- "with_discount, expected_net, expected_gross, prices_entered_with_tax",+ "expected_net, expected_gross, prices_entered_with_tax",[- (True, "20.33", "25.00", True),- (False, "40.65", "50.00", True),- (True, "25.00", "30.75", False),- (False, "50.00", "61.50", False),+ ("40.65", "50.00", True),+ ("50.00", "61.50", False),],)def test_calculate_checkout_subtotal(+ checkout_with_item,+ address,+ shipping_zone,+ expected_net,+ expected_gross,+ prices_entered_with_tax,+ stock,+):+ # given+ checkout = checkout_with_item+ _enable_flat_rates(checkout, prices_entered_with_tax)++ variant = stock.product_variant+ product = variant.product+ product.tax_class.country_rates.update_or_create(country=address.country, rate=23)++ checkout.shipping_address = address+ checkout.shipping_method = shipping_zone.shipping_methods.get()+ checkout.save()++ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, [], manager)+ add_variant_to_checkout(checkout_info, variant, 2)+ lines, _ = fetch_checkout_lines(checkout)++ # when+ update_checkout_prices_with_flat_rates(+ checkout,+ checkout_info,+ lines,+ prices_entered_with_tax,+ address,+ )++ # then+ assert checkout.subtotal == TaxedMoney(+ net=Money(expected_net, "USD"), gross=Money(expected_gross, "USD")+ )+++ "expected_net, expected_gross, prices_entered_with_tax",+ [+ ("20.33", "25.00", True),+ ("25.00", "30.75", False),+ ],+)+def test_calculate_checkout_subtotal_with_sale(checkout_with_item,address,shipping_zone,discount_info,- with_discount,expected_net,expected_gross,prices_entered_with_tax,@@ -231,15 +377,21 @@ def test_calculate_checkout_subtotal(checkout.shipping_method = shipping_zone.shipping_methods.get()checkout.save()- discounts = [discount_info] if with_discount else Nonemanager = get_plugins_manager()- checkout_info = fetch_checkout_info(checkout, [], discounts, manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)add_variant_to_checkout(checkout_info, variant, 2)lines, _ = fetch_checkout_lines(checkout)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )# whenupdate_checkout_prices_with_flat_rates(- checkout, checkout_info, lines, prices_entered_with_tax, address, discounts+ checkout,+ checkout_info,+ lines,+ prices_entered_with_tax,+ address,)# then@@ -270,11 +422,11 @@ def test_calculate_checkout_line_total(checkout_with_item, shipping_zone, addresproduct.tax_class.country_rates.update_or_create(country=address.country, rate=rate)lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]line_price = calculate_checkout_line_total(- checkout_info, lines, checkout_line_info, [], rate, prices_entered_with_tax+ checkout_info, lines, checkout_line_info, rate, prices_entered_with_tax)assert line_price == TaxedMoney(@@ -315,12 +467,12 @@ def test_calculate_checkout_line_total_voucher_on_entire_order(total_price = channel_listing.price * line.quantitylines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]# whenline_price = calculate_checkout_line_total(- checkout_info, lines, checkout_line_info, [], rate, prices_entered_with_tax+ checkout_info, lines, checkout_line_info, rate, prices_entered_with_tax)# then@@ -333,49 +485,7 @@ def test_calculate_checkout_line_total_voucher_on_entire_order()-def test_calculate_checkout_line_unit_price(checkout_with_item, shipping_zone, address):- # given- manager = get_plugins_manager()- checkout = checkout_with_item- channel = checkout.channel- line = checkout_with_item.lines.first()-- rate = Decimal(23)- prices_entered_with_tax = True- _enable_flat_rates(checkout, prices_entered_with_tax)-- method = shipping_zone.shipping_methods.get()- checkout.shipping_address = address- checkout.shipping_method_name = method.name- checkout.shipping_method = method- checkout.save()-- variant = line.variant- product = variant.product- product.tax_class.country_rates.update_or_create(country=address.country, rate=rate)-- lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)- checkout_line_info = lines[0]-- # when- line_price = _calculate_checkout_line_unit_price(- checkout_info,- lines,- checkout_line_info,- channel,- [],- rate,- prices_entered_with_tax,- )-- # then- assert quantize_price(line_price, line_price.currency) == TaxedMoney(- net=Money("8.13", "USD"), gross=Money("10.00", "USD")- )---def test_calculate_checkout_line_unit_price_with_voucher_one_line(+def test_calculate_checkout_line_total_with_voucher_one_line(checkout_with_item, shipping_zone, address, voucher):# given@@ -405,30 +515,30 @@ def test_calculate_checkout_line_unit_price_with_voucher_one_line(total_price = channel_listing.price * line.quantitylines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]# when- line_price = _calculate_checkout_line_unit_price(+ line_price = calculate_checkout_line_total(checkout_info,lines,checkout_line_info,- channel,- [],rate,prices_entered_with_tax,)# thencurrency = checkout_with_item.currency- unit_gross = Money(total_price.amount - discount_amount, currency) / line.quantity- assert quantize_price(line_price, line_price.currency) == TaxedMoney(- net=quantize_price(unit_gross / Decimal(1.23), currency),- gross=quantize_price(unit_gross, currency),+ expected_total_price = quantize_price(+ total_price - Money(discount_amount, currency), currency+ )+ assert line_price == TaxedMoney(+ net=quantize_price(expected_total_price / Decimal("1.23"), currency),+ gross=expected_total_price,)-def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines(+def test_calculate_checkout_line_total_with_voucher_multiple_lines(checkout_with_item, shipping_zone, address, voucher, product_list):# given@@ -439,7 +549,7 @@ def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines(prices_entered_with_tax = True_enable_flat_rates(checkout, prices_entered_with_tax)- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)variant_1 = product_list[0].variants.last()variant_2 = product_list[1].variants.last()qty_1 = 2@@ -472,33 +582,33 @@ def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]# when- line_price = _calculate_checkout_line_unit_price(+ line_total_price = calculate_checkout_line_total(checkout_info,lines,checkout_line_info,- channel,- [],rate,prices_entered_with_tax,)# thencurrency = checkout.currency- discount_amount = quantize_price(+ discount_amount_for_first_line = quantize_price(total_line_price / total_unit_prices * discount_amount, currency)- unit_gross = (total_line_price - Money(discount_amount, currency)) / line.quantity- assert quantize_price(line_price, currency) == TaxedMoney(- net=quantize_price(unit_gross / Decimal("1.23"), currency),- gross=quantize_price(unit_gross, currency),+ expected_total_line_price = total_line_price - Money(+ discount_amount_for_first_line, currency+ )+ assert line_total_price == TaxedMoney(+ net=quantize_price(expected_total_line_price / Decimal("1.23"), currency),+ gross=quantize_price(expected_total_line_price, currency),)-def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines_last_line(+def test_calculate_checkout_line_total_with_voucher_multiple_lines_last_line(checkout_with_item, shipping_zone, address, voucher, product_list):# given@@ -511,7 +621,7 @@ def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines_last_lincurrency = checkout.currency- checkout_info = fetch_checkout_info(checkout, [], [], manager)+ checkout_info = fetch_checkout_info(checkout, [], manager)variant_1 = product_list[0].variants.last()variant_2 = product_list[1].variants.last()qty_1 = 2@@ -549,33 +659,33 @@ def test_calculate_checkout_line_unit_price_with_voucher_multiple_lines_last_lin)lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[-1]# when- line_price = _calculate_checkout_line_unit_price(+ line_total_price = calculate_checkout_line_total(checkout_info,lines,checkout_line_info,- channel,- [],rate,prices_entered_with_tax,)# then- discount_amount = (+ discount_amount_for_last_line = (discount_amount- (total_unit_prices - total_line_price) / total_unit_prices * discount_amount)- unit_gross = (total_line_price - Money(discount_amount, currency)) / line.quantity- assert quantize_price(line_price, currency) == TaxedMoney(- net=quantize_price(unit_gross / Decimal("1.23"), currency),- gross=quantize_price(unit_gross, currency),+ expected_total_line_price = total_line_price - Money(+ discount_amount_for_last_line, currency+ )+ assert line_total_price == TaxedMoney(+ net=quantize_price(expected_total_line_price / Decimal("1.23"), currency),+ gross=quantize_price(expected_total_line_price, currency),)-def test_calculate_checkout_line_unit_price_with_shipping_voucher(+def test_calculate_checkout_line_total_with_shipping_voucher(checkout_with_item,shipping_zone,address,@@ -606,26 +716,26 @@ def test_calculate_checkout_line_unit_price_with_shipping_voucher(channel = checkout.channelchannel_listing = variant.channel_listings.get(channel=channel)unit_gross = channel_listing.price+ expected_total_line_price = unit_gross * line.quantitylines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)checkout_line_info = lines[0]# when- line_price = _calculate_checkout_line_unit_price(+ line_total_price = calculate_checkout_line_total(checkout_info,lines,checkout_line_info,- channel,- [],rate,prices_entered_with_tax,)# then- assert quantize_price(line_price, checkout.currency) == TaxedMoney(- net=quantize_price(unit_gross / Decimal("1.23"), checkout.currency),- gross=unit_gross,+ currency = checkout_with_item.currency+ assert line_total_price == TaxedMoney(+ net=quantize_price(expected_total_line_price / Decimal("1.23"), currency),+ gross=expected_total_line_price,)@@ -649,7 +759,7 @@ def test_calculate_checkout_shipping()checkout.save()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenshipping_price = calculate_checkout_shipping(@@ -681,7 +791,7 @@ def test_calculate_checkout_shipping_no_shipping_price(checkout.save(update_fields=["shipping_address", "collection_point"])lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenshipping_price = calculate_checkout_shipping(@@ -720,7 +830,7 @@ def test_calculate_checkout_shipping_voucher_on_shipping(checkout.discount_amount = discount_amountcheckout.save()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)channel = checkout.channelshipping_channel_listings = shipping_method.channel_listings.get(channel=channel)price = shipping_channel_listings.price@@ -767,7 +877,7 @@ def test_calculate_checkout_shipping_free_shipping_voucher(checkout.discount_amount = price.amountcheckout.save()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenshipping_price = calculate_checkout_shipping(@@ -806,7 +916,7 @@ def test_calculate_checkout_shipping_free_entire_order_voucher(checkout.discount_amount = discount_amountcheckout.save()lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [discount_info], manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenshipping_price = calculate_checkout_shipping(diff --git a/saleor/tax/tests/test_order_calculations.py b/saleor/tax/tests/test_order_calculations.pyindex 1478145232..aa0e0f53d1 100644--- a/saleor/tax/tests/test_order_calculations.py+++ b/saleor/tax/tests/test_order_calculations.py@@ -6,7 +6,7 @@ from saleor.tax.models import TaxClassCountryRatefrom ...core.prices import quantize_pricefrom ...core.taxes import zero_money, zero_taxed_money-from ...discount import DiscountValueType, OrderDiscountType+from ...discount import DiscountType, DiscountValueTypefrom ...order.utils import get_order_countryfrom .. import TaxCalculationStrategyfrom ..calculations.order import (@@ -49,7 +49,7 @@ def test_calculations_calculate_order_undiscounted_total(lines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -58,7 +58,7 @@ def test_calculations_calculate_order_undiscounted_total(amount_value=10,)order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=Decimal(5.0),name=voucher_shipping_type.code,@@ -146,7 +146,7 @@ def test_calculations_calculate_order_total_voucher(order_with_lines):discount_amount = 10order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=discount_amount,name="Voucher",@@ -172,7 +172,7 @@ def test_calculations_calculate_order_total_with_manual_discount(order_with_linelines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -200,7 +200,7 @@ def test_calculations_calculate_order_total_with_discount_for_order_total(lines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=80,name="StaffDiscount",@@ -226,7 +226,7 @@ def test_calculations_calculate_order_total_with_discount_for_subtotal_and_shipplines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=75,name="StaffDiscount",@@ -254,7 +254,7 @@ def test_calculations_calculate_order_total_with_discount_for_more_than_order_tolines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=100,name="StaffDiscount",@@ -280,7 +280,7 @@ def test_calculations_calculate_order_total_with_manual_discount_and_voucher(lines = order.lines.all()order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.FIXED,value=10,name="StaffDiscount",@@ -289,7 +289,7 @@ def test_calculations_calculate_order_total_with_manual_discount_and_voucher(amount_value=10,)order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=10,name="Voucher",@@ -370,7 +370,7 @@ def test_calculate_order_shipping_voucher_on_shipping(order.save()order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=discount_amount,name=voucher_shipping_type.code,@@ -419,7 +419,7 @@ def test_calculate_order_shipping_free_shipping_voucher(shipping_price = shipping_channel_listings.priceorder.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=Decimal("100.0"),name=voucher_shipping_type.code,@@ -494,7 +494,7 @@ def test_update_taxes_for_order_lines_voucher_on_entire_order(order_discount_amount = Decimal("5.0")order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=order_discount_amount,name=voucher.code,@@ -566,7 +566,7 @@ def test_update_taxes_for_order_lines_voucher_on_shipping(order_discount_amount = Decimal("5.0")order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.FIXED,value=order_discount_amount,name=voucher_shipping_type.code,diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex b0ff4f05e4..6b0b6612d6 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -38,11 +38,7 @@ from ..attribute.models import ()from ..attribute.utils import associate_attribute_values_to_instancefrom ..checkout import base_calculations-from ..checkout.fetch import (- fetch_active_discounts,- fetch_checkout_info,- fetch_checkout_lines,-)+from ..checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ..checkout.models import Checkout, CheckoutLine, CheckoutMetadatafrom ..checkout.utils import add_variant_to_checkout, add_voucher_to_checkoutfrom ..core import EventDeliveryStatus, JobStatus@@ -311,7 +307,7 @@ def checkout_JPY(channel_JPY):@pytest.fixturedef checkout_with_item(checkout, product):variant = product.variants.first()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 3)checkout.save()return checkout@@ -341,7 +337,7 @@ def checkout_with_item_and_tax_exemption(checkout_with_item):@pytest.fixturedef checkout_with_same_items_in_multiple_lines(checkout, product):variant = product.variants.first()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)add_variant_to_checkout(checkout_info, variant, 1, force_new_line=True)checkout.save()@@ -354,7 +350,7 @@ def checkout_with_item_and_voucher_specific_products():manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, manager)add_voucher_to_checkout(manager, checkout_info, lines, voucher_specific_product_type)@@ -368,7 +364,7 @@ def checkout_with_item_and_voucher_once_per_order(checkout_with_item, voucher):voucher.save()manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ 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@@ -378,7 +374,7 @@ def checkout_with_item_and_voucher_once_per_order(checkout_with_item, voucher):def checkout_with_item_and_voucher(checkout_with_item, voucher):manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_item)- checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)+ 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@@ -392,7 +388,7 @@ def checkout_line(checkout_with_item):@pytest.fixturedef checkout_with_item_total_0(checkout, product_price_0):variant = product_price_0.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)checkout.save()return checkout@@ -401,7 +397,7 @@ def checkout_with_item_total_0(checkout, product_price_0):@pytest.fixturedef checkout_JPY_with_item(checkout_JPY, product_in_channel_JPY):variant = product_in_channel_JPY.variants.get()- checkout_info = fetch_checkout_info(checkout_JPY, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout_JPY, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 3)checkout_JPY.save()return checkout_JPY@@ -463,7 +459,7 @@ def checkout_ready_to_complete(checkout_with_item, address, shipping_method, gifdef checkout_with_digital_item(checkout, digital_content, address):"""Create a checkout with a digital line."""variant = digital_content.product_variant- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)checkout.discount_amount = Decimal(0)checkout.billing_address = address@@ -476,7 +472,7 @@ def checkout_with_digital_item(checkout, digital_content, address):def checkout_with_shipping_required(checkout_with_item, product):checkout = checkout_with_itemvariant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 3)checkout.save()return checkout@@ -509,7 +505,7 @@ def other_shipping_method(shipping_zone, channel_USD):@pytest.fixturedef checkout_without_shipping_required(checkout, product_without_shipping):variant = product_without_shipping.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)checkout.save()return checkout@@ -518,7 +514,7 @@ def checkout_without_shipping_required(checkout, product_without_shipping):@pytest.fixturedef checkout_with_single_item(checkout, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)checkout.save()return checkout@@ -529,7 +525,7 @@ def checkout_with_variant_without_inventory_tracking(checkout, variant_without_inventory_tracking, address, shipping_method):variant = variant_without_inventory_tracking- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)checkout.shipping_address = addresscheckout.shipping_method = shipping_method@@ -551,7 +547,7 @@ def checkout_with_variants(product_with_single_variant,product_with_two_variants,):- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, product_with_default_variant.variants.get(), 1@@ -620,7 +616,7 @@ def checkout_with_shipping_address_for_cc(checkout_with_variants_for_cc, address@pytest.fixturedef checkout_with_items(checkout, product_list, product):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 1)for prod in product_list:variant = prod.variants.get()@@ -642,7 +638,7 @@ def checkout_with_items_and_shipping(checkout_with_items, address, shipping_meth@pytest.fixturedef checkout_with_voucher(checkout, product, voucher):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 3)checkout.voucher_code = voucher.codecheckout.discount = Money("20.00", "USD")@@ -653,7 +649,7 @@ def checkout_with_voucher(checkout, product, voucher):@pytest.fixturedef checkout_with_voucher_percentage(checkout, product, voucher_percentage):variant = product.variants.get()- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, variant, 3)checkout.voucher_code = voucher_percentage.codecheckout.discount = Money("3.00", "USD")@@ -668,9 +664,9 @@ def checkout_with_voucher_free_shipping(manager = get_plugins_manager()lines, _ = fetch_checkout_lines(checkout_with_items_and_shipping)checkout_info = fetch_checkout_info(- checkout_with_items_and_shipping, lines, [], manager+ checkout_with_items_and_shipping, lines, manager)- add_voucher_to_checkout(manager, checkout_info, lines, voucher_free_shipping, [])+ add_voucher_to_checkout(manager, checkout_info, lines, voucher_free_shipping)return checkout_with_items_and_shipping@@ -689,7 +685,7 @@ def checkout_with_preorders_only(preorder_variant_channel_threshold,):lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, lines, get_plugins_manager())add_variant_to_checkout(checkout_info, preorder_variant_with_end_date, 2)add_variant_to_checkout(checkout_info, preorder_variant_channel_threshold, 2)@@ -702,7 +698,7 @@ def checkout_with_preorders_and_regular_variant(checkout, stocks_for_cc, preorder_variant_with_end_date, product_variant_list):lines, _ = fetch_checkout_lines(checkout)- checkout_info = fetch_checkout_info(checkout, lines, [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, lines, get_plugins_manager())add_variant_to_checkout(checkout_info, preorder_variant_with_end_date, 2)add_variant_to_checkout(checkout_info, product_variant_list[0], 2)@@ -714,7 +710,7 @@ def checkout_with_preorders_and_regular_variant(def checkout_with_gift_card_items(checkout, non_shippable_gift_card_product, shippable_gift_card_product):- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())non_shippable_variant = non_shippable_gift_card_product.variants.get()shippable_variant = shippable_gift_card_product.variants.get()add_variant_to_checkout(checkout_info, non_shippable_variant, 1)@@ -753,9 +749,7 @@ def checkout_with_payments(checkout):def checkout_with_item_and_preorder_item(checkout_with_item, product, preorder_variant_channel_threshold):- checkout_info = fetch_checkout_info(- checkout_with_item, [], [], get_plugins_manager()- )+ checkout_info = fetch_checkout_info(checkout_with_item, [], get_plugins_manager())add_variant_to_checkout(checkout_info, preorder_variant_channel_threshold, 1)return checkout_with_item@@ -930,7 +924,7 @@ def user_checkout_PLN(customer_user, channel_PLN):@pytest.fixturedef user_checkout_with_items(user_checkout, product_list):- checkout_info = fetch_checkout_info(user_checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(user_checkout, [], get_plugins_manager())for product in product_list:variant = product.variants.get()add_variant_to_checkout(checkout_info, variant, 1)@@ -940,9 +934,7 @@ def user_checkout_with_items(user_checkout, product_list):@pytest.fixturedef user_checkout_with_items_for_cc(user_checkout_for_cc, product_list):- checkout_info = fetch_checkout_info(- user_checkout_for_cc, [], [], get_plugins_manager()- )+ checkout_info = fetch_checkout_info(user_checkout_for_cc, [], get_plugins_manager())for product in product_list:variant = product.variants.get()add_variant_to_checkout(checkout_info, variant, 1)@@ -2000,6 +1992,13 @@ def category_with_image(db, image, media_root): # pylint: disable=W0613)+def categories(db):+ category1 = Category.objects.create(name="Category1", slug="cat1")+ category2 = Category.objects.create(name="Category2", slug="cat2")+ return [category1, category2]++@pytest.fixturedef categories_tree(db, product_type, channel_USD): # pylint: disable=W0613parent = Category.objects.create(name="Parent", slug="parent")@@ -3832,7 +3831,7 @@ def checkout_line_with_one_reservation(def checkout_line_with_preorder_item(checkout, product, preorder_variant_channel_threshold):- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, preorder_variant_channel_threshold, 1)return checkout.lines.last()@@ -3841,7 +3840,7 @@ def checkout_line_with_preorder_item(def checkout_line_with_reserved_preorder_item(checkout, product, preorder_variant_channel_threshold):- checkout_info = fetch_checkout_info(checkout, [], [], get_plugins_manager())+ checkout_info = fetch_checkout_info(checkout, [], get_plugins_manager())add_variant_to_checkout(checkout_info, preorder_variant_channel_threshold, 2)checkout_line = checkout.lines.last()@@ -5156,6 +5155,41 @@ def published_collection(db, channel_USD):return collection+def published_collections(db, channel_USD):+ collections = Collection.objects.bulk_create(+ [+ Collection(+ name="Collection1",+ slug="coll1",+ ),+ Collection(+ name="Collection2",+ slug="coll2",+ ),+ Collection(+ name="Collection3",+ slug="coll3",+ ),+ ]+ )+ CollectionChannelListing.objects.bulk_create(+ [+ CollectionChannelListing(+ channel=channel_USD,+ collection=collection,+ is_published=True,+ published_at=datetime.datetime(+ 2019, 4, 10, tzinfo=timezone.get_current_timezone()+ ),+ )+ for collection in collections+ ]+ )++ return collections++@pytest.fixturedef published_collection_PLN(db, channel_PLN):collection = Collection.objects.create(@@ -5536,6 +5570,13 @@ def sale_translation_fr(sale):)+def new_sale_translation_fr(new_sale):+ return SaleTranslation.objects.create(+ language_code="fr", sale=new_sale, name="French sale name"+ )++@pytest.fixturedef menu_item_translation_fr(menu_item):return MenuItemTranslation.objects.create(@@ -6427,16 +6468,13 @@ def checkout_with_prices(manager = get_plugins_manager()channel = checkout_with_items.channel- discounts_info = fetch_active_discounts()lines = checkout_with_items.lines.all()lines_info, _ = fetch_checkout_lines(checkout_with_items)- checkout_info = fetch_checkout_info(- checkout_with_items, lines, discounts_info, manager- )+ checkout_info = fetch_checkout_info(checkout_with_items, lines, manager)for line, line_info in zip(lines, lines_info):line.total_price_net_amount = base_calculations.calculate_base_line_total_price(- line_info, channel, discounts_info+ line_info, channel).amountline.total_price_gross_amount = line.total_price_net_amount * Decimal("1.230")diff --git a/saleor/warehouse/tests/test_preorder_availability.py b/saleor/warehouse/tests/test_preorder_availability.pyindex 470a2650b3..296af69270 100644--- a/saleor/warehouse/tests/test_preorder_availability.py+++ b/saleor/warehouse/tests/test_preorder_availability.py@@ -161,6 +161,8 @@ def test_check_preorder_reserved_threshold_bulk_channel_threshold(product=line.variant.product,variant=line.variant,product_type=line.variant.product.product_type,+ discounts=[],+ channel=channel_USD,)],check_reservations=True,@@ -228,6 +230,8 @@ def test_check_preorder_reserved_threshold_bulk_global_threshold(product=line.variant.product,variant=line.variant,product_type=line.variant.product.product_type,+ discounts=[],+ channel=channel_USD,)],check_reservations=True,diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.pyindex dc8ac8fd6d..2c22e22d23 100644--- a/saleor/webhook/payloads.py+++ b/saleor/webhook/payloads.py@@ -36,7 +36,6 @@ from ..core.utils.anonymization import ()from ..core.utils.json_serializer import CustomJsonEncoderfrom ..discount import VoucherType-from ..discount.utils import fetch_active_discountsfrom ..order import FulfillmentStatus, OrderStatusfrom ..order.models import Fulfillment, FulfillmentLine, Order, OrderLinefrom ..order.utils import get_order_country@@ -551,8 +550,7 @@ def generate_checkout_payload(quantize_price_fields(checkout, checkout_price_fields, checkout.currency)user_fields = ("email", "first_name", "last_name")- discounts = fetch_active_discounts()- lines_dict_data = serialize_checkout_lines(checkout, discounts)+ lines_dict_data = serialize_checkout_lines(checkout)# todo use the most appropriate warehousewarehouse = None@@ -1260,7 +1258,6 @@ def generate_checkout_payload_for_tax_calculation(checkout = checkout_info.checkouttax_configuration = checkout_info.tax_configurationprices_entered_with_tax = tax_configuration.prices_entered_with_tax- discount_infos = fetch_active_discounts()serializer = PayloadSerializer()@@ -1270,9 +1267,7 @@ def generate_checkout_payload_for_tax_calculation(address = checkout_info.shipping_address or checkout_info.billing_addresstotal_amount = quantize_price(- base_calculations.base_checkout_total(- checkout_info, discount_infos, lines- ).amount,+ base_calculations.base_checkout_total(checkout_info, lines).amount,checkout.currency,)@@ -1322,9 +1317,7 @@ def generate_checkout_payload_for_tax_calculation()# Prepare line data- lines_dict_data = serialize_checkout_lines_for_tax_calculation(- checkout_info, lines, discount_infos- )+ lines_dict_data = serialize_checkout_lines_for_tax_calculation(checkout_info, lines)checkout_data = serializer.serialize([checkout],diff --git a/saleor/webhook/serializers.py b/saleor/webhook/serializers.pyindex d1fb725625..60d7a9662d 100644--- a/saleor/webhook/serializers.py+++ b/saleor/webhook/serializers.py@@ -2,12 +2,12 @@ from datetime import date, datetimefrom typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Unionimport graphene+from prices import Moneyfrom ..attribute import AttributeEntityType, AttributeInputTypefrom ..checkout import base_calculationsfrom ..checkout.fetch import fetch_checkout_linesfrom ..core.prices import quantize_price-from ..discount import DiscountInfofrom ..product.models import Productfrom ..tax.utils import get_charge_taxes_for_checkout@@ -18,9 +18,7 @@ if TYPE_CHECKING:from ..product.models import ProductVariant-def serialize_checkout_lines(- checkout: "Checkout", discounts: Optional[Iterable[DiscountInfo]] = None-) -> List[dict]:+def serialize_checkout_lines(checkout: "Checkout") -> List[dict]:data = []channel = checkout.channelcurrency = channel.currency_code@@ -31,14 +29,23 @@ def serialize_checkout_lines(collections = line_info.collectionsproduct = variant.productprice_override = line_info.line.price_override- base_price = variant.get_price(+ undiscounted_base_price = variant.get_price(product,collections,channel,channel_listing,- discounts or [],+ [],price_override,)+ base_price = undiscounted_base_price+ if discount_object_from_sale := line_info.get_sale_discount():+ total_discount_amount_for_line = discount_object_from_sale.amount_value+ unit_discount_amount = (+ total_discount_amount_for_line / line_info.line.quantity+ )+ unit_discount = Money(unit_discount_amount, currency)+ unit_discount = quantize_price(unit_discount, currency)+ base_price -= unit_discountdata.append({"sku": variant.sku,@@ -75,7 +82,6 @@ def _get_checkout_line_payload_data(line_info: "CheckoutLineInfo") -> Dict[str,def serialize_checkout_lines_for_tax_calculation(checkout_info: "CheckoutInfo",lines: Iterable["CheckoutLineInfo"],- discounts: Optional[Iterable[DiscountInfo]] = None,) -> List[dict]:channel = checkout_info.channelcharge_taxes = get_charge_taxes_for_checkout(checkout_info, lines)@@ -85,13 +91,13 @@ def serialize_checkout_lines_for_tax_calculation("charge_taxes": charge_taxes,"unit_amount": quantize_price(base_calculations.calculate_base_line_unit_price(- line_info, channel, discounts+ line_info, channel).amount,checkout_info.checkout.currency,),"total_amount": quantize_price(base_calculations.calculate_base_line_total_price(- line_info, channel, discounts+ line_info, channel).amount,checkout_info.checkout.currency,),diff --git a/saleor/webhook/tests/conftest.py b/saleor/webhook/tests/conftest.pyindex b2f66c16d8..b5b28637bb 100644--- a/saleor/webhook/tests/conftest.py+++ b/saleor/webhook/tests/conftest.py@@ -6,7 +6,7 @@ import pytest@pytest.fixturedef mocked_fetch_checkout():def mocked_fetch_side_effect(- checkout_info, manager, lines, address, discounts, force_update=False+ checkout_info, manager, lines, address, force_update=False):return checkout_info, linesdiff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.pyindex 3220186c26..9d511853e6 100644--- a/saleor/webhook/tests/test_webhook_payloads.py+++ b/saleor/webhook/tests/test_webhook_payloads.py@@ -20,8 +20,7 @@ from ...checkout import base_calculationsfrom ...checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ...core.prices import quantize_pricefrom ...core.utils.json_serializer import CustomJsonEncoder-from ...discount import DiscountValueType, OrderDiscountType-from ...discount.utils import fetch_active_discounts+from ...discount import DiscountType, DiscountValueTypefrom ...graphql.utils import get_user_or_app_from_contextfrom ...order import FulfillmentLineData, OrderOriginfrom ...order.actions import fulfill_order_lines@@ -84,14 +83,14 @@ def order_for_payload(fulfilled_order):order.save(update_fields=["origin", "original"])order.discounts.create(- type=OrderDiscountType.MANUAL,+ type=DiscountType.MANUAL,value_type=DiscountValueType.PERCENTAGE,value=Decimal("20"),amount_value=Decimal("33.0"),reason="Discount from staff",)discount = order.discounts.create(- type=OrderDiscountType.VOUCHER,+ type=DiscountType.VOUCHER,value_type=DiscountValueType.PERCENTAGE,value=Decimal("10"),amount_value=Decimal("16.5"),@@ -1651,8 +1650,6 @@ def test_generate_checkout_payload_for_tax_calculation_entire_order_voucher(checkout.discount_name = voucher.namecheckout.save(update_fields=["voucher_code", "discount_amount", "discount_name"])- discounts_info = fetch_active_discounts()-tax_configuration = checkout.channel.tax_configurationtax_configuration.prices_entered_with_tax = prices_entered_with_taxtax_configuration.save(update_fields=["prices_entered_with_tax"])@@ -1666,8 +1663,7 @@ def test_generate_checkout_payload_for_tax_calculation_entire_order_voucher(# whenlines, _ = fetch_checkout_lines(checkout_with_prices)manager = get_plugins_manager()- discounts = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout_with_prices, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_prices, lines, manager)payload = json.loads(generate_checkout_payload_for_tax_calculation(checkout_info, lines))[0]@@ -1716,9 +1712,7 @@ def test_generate_checkout_payload_for_tax_calculation_entire_order_voucher("user_public_metadata": {"user_public_meta_key": "user_public_meta_value"},"total_amount": str(quantize_price(- base_calculations.base_checkout_total(- checkout_info, discounts_info, lines- ).amount,+ base_calculations.base_checkout_total(checkout_info, lines).amount,currency,)),@@ -1728,7 +1722,6 @@ def test_generate_checkout_payload_for_tax_calculation_entire_order_voucher(mocked_serialize_checkout_lines_for_tax_calculation.assert_called_once_with(checkout_info,lines,- discounts_info,)@@ -1754,8 +1747,6 @@ def test_generate_checkout_payload_for_tax_calculation_specific_product_voucher(checkout.discount_name = voucher.namecheckout.save(update_fields=["voucher_code", "discount_amount", "discount_name"])- discounts_info = fetch_active_discounts()-tax_configuration = checkout.channel.tax_configurationtax_configuration.prices_entered_with_tax = prices_entered_with_taxtax_configuration.save(update_fields=["prices_entered_with_tax"])@@ -1769,8 +1760,7 @@ def test_generate_checkout_payload_for_tax_calculation_specific_product_voucher(# whenlines, _ = fetch_checkout_lines(checkout_with_prices)manager = get_plugins_manager()- discounts = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout_with_prices, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout_with_prices, lines, manager)payload = json.loads(generate_checkout_payload_for_tax_calculation(checkout_info, lines))[0]@@ -1819,9 +1809,7 @@ def test_generate_checkout_payload_for_tax_calculation_specific_product_voucher("user_public_metadata": {"user_public_meta_key": "user_public_meta_value"},"total_amount": str(quantize_price(- base_calculations.base_checkout_total(- checkout_info, discounts_info, lines- ).amount,+ base_calculations.base_checkout_total(checkout_info, lines).amount,currency,)),@@ -1831,7 +1819,6 @@ def test_generate_checkout_payload_for_tax_calculation_specific_product_voucher(mocked_serialize_checkout_lines_for_tax_calculation.assert_called_once_with(checkout_info,lines,- discounts_info,)@@ -1842,7 +1829,6 @@ def test_generate_checkout_payload_for_tax_calculation_digital_checkout(checkout_with_digital_item,):prices_entered_with_tax = True- discounts_info = fetch_active_discounts()checkout = checkout_with_digital_itemcurrency = checkout.currency@@ -1857,8 +1843,7 @@ def test_generate_checkout_payload_for_tax_calculation_digital_checkout()lines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- discounts = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout, lines, discounts, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)# whenpayload = json.loads(@@ -1902,9 +1887,7 @@ def test_generate_checkout_payload_for_tax_calculation_digital_checkout("user_public_metadata": {},"total_amount": str(quantize_price(- base_calculations.base_checkout_total(- checkout_info, discounts_info, lines- ).amount,+ base_calculations.base_checkout_total(checkout_info, lines).amount,currency,)),@@ -1913,7 +1896,6 @@ def test_generate_checkout_payload_for_tax_calculation_digital_checkout(mocked_serialize_checkout_lines_for_tax_calculation.assert_called_once_with(checkout_info,lines,- discounts_info,)@@ -2011,7 +1993,7 @@ def test_generate_checkout_payload()),},- "lines": serialize_checkout_lines(checkout, []),+ "lines": serialize_checkout_lines(checkout),"collection_point": json.loads(_generate_collection_point_payload(checkout.collection_point))[0],diff --git a/saleor/webhook/tests/test_webhook_serializers.py b/saleor/webhook/tests/test_webhook_serializers.pyindex d2cbb75274..b426fbd338 100644--- a/saleor/webhook/tests/test_webhook_serializers.py+++ b/saleor/webhook/tests/test_webhook_serializers.py@@ -7,7 +7,8 @@ import pytestfrom ...checkout import base_calculationsfrom ...checkout.fetch import fetch_checkout_info, fetch_checkout_linesfrom ...core.prices import quantize_price-from ...discount.utils import fetch_active_discounts+from ...discount import DiscountType+from ...discount.utils import create_or_update_discount_objects_from_sale_for_checkoutfrom ...plugins.manager import get_plugins_managerfrom ..serializers import (serialize_checkout_lines,@@ -117,6 +118,51 @@ def test_serialize_checkout_lines(assert len(checkout_lines_data) == len(list(checkout_lines))+def test_serialize_checkout_lines_with_sale(checkout_with_item, discount_info):+ # given+ checkout = checkout_with_item+ channel = checkout.channel+ checkout_lines, _ = fetch_checkout_lines(checkout, prefetch_variant_attributes=True)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, checkout_lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, checkout_lines, [discount_info]+ )++ # when+ checkout_lines_data = serialize_checkout_lines(checkout)++ # then+ checkout.refresh_from_db()+ assert len(checkout_lines) == 1+ for data, line_info in zip(checkout_lines_data, checkout_lines):+ variant = line_info.line.variant+ product = variant.product+ collections = line_info.collections+ variant_channel_listing = line_info.channel_listing++ base_price = variant.get_price(+ product, collections, channel, variant_channel_listing, [discount_info]+ )+ undiscounted_base_price = variant.get_price(+ product, collections, channel, variant_channel_listing+ )+ currency = checkout.currency+ assert base_price < undiscounted_base_price+ assert data == {+ "sku": variant.sku,+ "quantity": line_info.line.quantity,+ "base_price": str(quantize_price(base_price.amount, currency)),+ "currency": channel.currency_code,+ "full_name": variant.display_product(),+ "product_name": product.name,+ "variant_name": variant.name,+ "attributes": serialize_product_or_variant_attributes(variant),+ "variant_id": variant.get_global_id(),+ }+ assert len(checkout_lines_data) == len(list(checkout_lines))++@pytest.mark.parametrize("charge_taxes, prices_entered_with_tax",[(False, False), (False, True), (True, False), (True, True)],@@ -134,8 +180,7 @@ def test_serialize_checkout_lines_for_tax_calculation(checkout = checkout_with_priceslines, _ = fetch_checkout_lines(checkout)manager = get_plugins_manager()- discounts_info = fetch_active_discounts()- checkout_info = fetch_checkout_info(checkout, lines, discounts_info, manager)+ checkout_info = fetch_checkout_info(checkout, lines, manager)tax_configuration = checkout_info.tax_configurationtax_configuration.charge_taxes = charge_taxes@@ -145,7 +190,7 @@ def test_serialize_checkout_lines_for_tax_calculation(# whencheckout_lines_data = serialize_checkout_lines_for_tax_calculation(- checkout_info, lines, discounts_info+ checkout_info, lines)# then@@ -155,10 +200,10 @@ def test_serialize_checkout_lines_for_tax_calculation(product = variant.producttotal_price = base_calculations.calculate_base_line_total_price(- line_info, checkout_info.channel, discounts_info+ line_info, checkout_info.channel).amountunit_price = base_calculations.calculate_base_line_unit_price(- line_info, checkout_info.channel, discounts_info+ line_info, checkout_info.channel).amountassert data == {@@ -176,3 +221,66 @@ def test_serialize_checkout_lines_for_tax_calculation("total_amount": total_price,}assert len(checkout_lines_data) == len(list(lines))+++def test_serialize_checkout_lines_for_tax_calculation_with_sale(+ checkout_with_prices, discount_info+):+ # given+ checkout = checkout_with_prices+ lines, _ = fetch_checkout_lines(checkout)+ manager = get_plugins_manager()+ checkout_info = fetch_checkout_info(checkout, lines, manager)+ create_or_update_discount_objects_from_sale_for_checkout(+ checkout_info, lines, [discount_info]+ )++ tax_configuration = checkout_info.tax_configuration+ tax_configuration.country_exceptions.all().delete()++ # when+ checkout_lines_data = serialize_checkout_lines_for_tax_calculation(+ checkout_info, lines+ )++ # then+ for data, line_info in zip(checkout_lines_data, lines):+ line = line_info.line+ variant = line.variant+ product = variant.product++ total_price = base_calculations.calculate_base_line_total_price(+ line_info, checkout_info.channel+ ).amount+ unit_price = base_calculations.calculate_base_line_unit_price(+ line_info, checkout_info.channel+ ).amount++ assert data == {+ "id": graphene.Node.to_global_id("CheckoutLine", line.pk),+ "sku": variant.sku,+ "quantity": line.quantity,+ "charge_taxes": tax_configuration.charge_taxes,+ "full_name": variant.display_product(),+ "product_name": product.name,+ "variant_name": variant.name,+ "variant_id": graphene.Node.to_global_id("ProductVariant", variant.pk),+ "product_metadata": product.metadata,+ "product_type_metadata": product.product_type.metadata,+ "unit_amount": unit_price,+ "total_amount": total_price,+ }++ discount = line_info.discounts[0]+ assert discount.type == DiscountType.SALE+ undiscounted_unit_price = variant.get_price(+ line_info.product,+ line_info.collections,+ checkout_info.channel,+ line_info.channel_listing,+ [],+ line_info.line.price_override,+ ).amount+ assert unit_price < undiscounted_unit_price++ assert len(checkout_lines_data) == len(list(lines))