Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Attach sale discount info to the line when adding variant to order (#8849)

Marcin Gębala10febec8922b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 16482aaf10..e8f7b359f7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -184,7 +184,10 @@ All notable, unreleased changes to this project will be documented in this file.
- When any sale or voucher discount was applied, `line.discount_reason` will be fulfilled.
- New interface for handling more data for prices: `PricesData` and `TaxedPricesData` used in checkout calculations
and in plugins/pluginManager.
-
+- Attach sale discount info to the line when adding variant to order - #8821 by @IKarbowiak
+ - Rename checkout interfaces: `CheckoutTaxedPricesData` instead of `TaxedPricesData`
+ and `CheckoutPricesData` instead of `PricesData`
+ - New interface for handling more data for prices: `OrderTaxedPricesData` used in plugins/pluginManager.
### Breaking
- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysocki
@@ -296,6 +299,12 @@ All notable, unreleased changes to this project will be documented in this file.
- Propagate sale and voucher discounts over specific lines - #8793 by @korycins
- Use a new interface for response received from plugins/pluginManager. Methods `calculate_checkout_line_unit_price`
and `calculate_checkout_line_total` returns `TaxedPricesData` instead of `TaxedMoney`.
+- Attach sale discount info to the line when adding variant to order - #8821 by @IKarbowiak
+ - Use a new interface for the response received from plugins/pluginManager.
+ Methods `calculate_order_line_unit` and `calculate_order_line_total` returns
+ `OrderTaxedPricesData` instead of `TaxedMoney`.
+ - Rename checkout interfaces: `CheckoutTaxedPricesData` instead of `TaxedPricesData`
+ and `CheckoutPricesData` instead of `PricesData`
### Other
diff --git a/saleor/checkout/base_calculations.py b/saleor/checkout/base_calculations.py
index a15f2464bb..82b066560a 100644
--- a/saleor/checkout/base_calculations.py
+++ b/saleor/checkout/base_calculations.py
@@ -12,8 +12,9 @@ from prices import TaxedMoney
from ..core.prices import quantize_price
from ..core.taxes import zero_money, zero_taxed_money
from ..discount import DiscountInfo
+from ..order.interface import OrderTaxedPricesData
from .fetch import CheckoutLineInfo, ShippingMethodInfo
-from .interface import PricesData, TaxedPricesData
+from .interface import CheckoutPricesData, CheckoutTaxedPricesData
if TYPE_CHECKING:
from ..channel.models import Channel
@@ -25,7 +26,7 @@ def calculate_base_line_unit_price(
line_info: CheckoutLineInfo,
channel: "Channel",
discounts: Optional[Iterable[DiscountInfo]] = None,
-) -> PricesData:
+) -> CheckoutPricesData:
"""Calculate line unit prices including discounts and vouchers.
Returns a three money values. Undiscounted price, price and price with voucher.
@@ -67,7 +68,7 @@ def calculate_base_line_unit_price(
else:
price_with_discounts = variant_price
- return PricesData(
+ return CheckoutPricesData(
undiscounted_price=quantize_price(
undiscounted_variant_price, undiscounted_variant_price.currency
),
@@ -82,7 +83,7 @@ def calculate_base_line_total_price(
line_info: CheckoutLineInfo,
channel: "Channel",
discounts: Optional[Iterable[DiscountInfo]] = None,
-) -> PricesData:
+) -> CheckoutPricesData:
"""Calculate line total prices including discounts and vouchers.
Returns a three money values. Undiscounted price, price and price with voucher.
@@ -107,7 +108,7 @@ def calculate_base_line_total_price(
# we add -1 as we handle a case when voucher is applied only to single line
# of the cheapest line
quantity_without_voucher = line_info.line.quantity - 1
- prices_data = PricesData(
+ prices_data = CheckoutPricesData(
price_with_discounts=(
prices_data.price_with_sale * quantity_without_voucher
+ variant_price_with_discounts
@@ -116,7 +117,7 @@ def calculate_base_line_total_price(
undiscounted_price=prices_data.undiscounted_price * line_info.line.quantity,
)
else:
- prices_data = PricesData(
+ prices_data = CheckoutPricesData(
price_with_sale=prices_data.price_with_sale * line_info.line.quantity,
price_with_discounts=prices_data.price_with_discounts
* line_info.line.quantity,
@@ -194,12 +195,12 @@ def base_checkout_line_total(
checkout_line_info: "CheckoutLineInfo",
channel: "Channel",
discounts: Optional[Iterable[DiscountInfo]] = None,
-) -> TaxedPricesData:
+) -> CheckoutTaxedPricesData:
"""Return the total price of this line."""
prices_data = calculate_base_line_total_price(
line_info=checkout_line_info, channel=channel, discounts=discounts
)
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
price_with_sale=TaxedMoney(
net=prices_data.price_with_sale, gross=prices_data.price_with_sale
),
@@ -212,9 +213,12 @@ def base_checkout_line_total(
)
-def base_order_line_total(order_line: "OrderLine"):
- unit_price = order_line.unit_price * order_line.quantity
- return quantize_price(unit_price, unit_price.currency)
+def base_order_line_total(order_line: "OrderLine") -> OrderTaxedPricesData:
+ quantity = order_line.quantity
+ return OrderTaxedPricesData(
+ undiscounted_price=order_line.undiscounted_unit_price * quantity,
+ price_with_discounts=order_line.unit_price * quantity,
+ )
def base_tax_rate(price: TaxedMoney):
@@ -233,7 +237,7 @@ def base_checkout_line_unit_price(
prices_data = calculate_base_line_unit_price(
line_info=checkout_line_info, channel=channel, discounts=discounts
)
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
price_with_sale=TaxedMoney(
net=prices_data.price_with_sale, gross=prices_data.price_with_sale
),
diff --git a/saleor/checkout/calculations.py b/saleor/checkout/calculations.py
index 0a8baed124..16a9e0b3fb 100644
--- a/saleor/checkout/calculations.py
+++ b/saleor/checkout/calculations.py
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Iterable, Optional
from ..core.prices import quantize_price
from ..core.taxes import zero_taxed_money
from ..discount import DiscountInfo
-from .interface import TaxedPricesData
+from .interface import CheckoutTaxedPricesData
if TYPE_CHECKING:
from prices import TaxedMoney
@@ -98,7 +98,7 @@ def checkout_line_total(
lines: Iterable["CheckoutLineInfo"],
checkout_line_info: "CheckoutLineInfo",
discounts: Iterable[DiscountInfo] = [],
-) -> "TaxedPricesData":
+) -> "CheckoutTaxedPricesData":
"""Return the total price of provided line, taxes included.
It takes in account all plugins.
diff --git a/saleor/checkout/interface.py b/saleor/checkout/interface.py
index 0f0293a849..a09fb4a935 100644
--- a/saleor/checkout/interface.py
+++ b/saleor/checkout/interface.py
@@ -4,10 +4,10 @@ from prices import Money, TaxedMoney
@dataclass
-class TaxedPricesData:
- """Store a prices data with applied taxes.
+class CheckoutTaxedPricesData:
+ """Store a checkout prices data with applied taxes.
- 'price' includes discount from sale if any valid exists.
+ 'price_with_sale' includes discount from sale if any valid exists.
'price_with_discounts' includes voucher discount and sale discount if any valid
exists.
'undiscounted_price' is a price without any sale and voucher.
@@ -19,10 +19,10 @@ class TaxedPricesData:
@dataclass
-class PricesData:
- """Store a prices data without applied taxes.
+class CheckoutPricesData:
+ """Store a checkout prices data without applied taxes.
- 'price' includes discount from sale if any valid exists.
+ 'price_with_sale' includes discount from sale if any valid exists.
'price_with_discounts' includes voucher discount and sale discount if any valid
exists.
'undiscounted_price' is a price without any sale and voucher.
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 4a6515c15b..f10ba712cc 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -602,17 +602,20 @@ def create_order_lines(order, discounts, how_many=10):
warehouse_iter = itertools.cycle(warehouses)
for line in lines:
variant = line.variant
- unit_price = manager.calculate_order_line_unit(
+ unit_price_data = manager.calculate_order_line_unit(
order, line, variant, variant.product
)
- total_price = manager.calculate_order_line_total(
+ total_price_data = manager.calculate_order_line_total(
order, line, variant, variant.product
)
- line.unit_price = unit_price
- line.total_price = total_price
- line.undiscounted_unit_price = unit_price
- line.undiscounted_total_price = total_price
- line.tax_rate = unit_price.tax / unit_price.net
+ line.unit_price = unit_price_data.price_with_discounts
+ line.total_price = total_price_data.price_with_discounts
+ line.undiscounted_unit_price = unit_price_data.undiscounted_price
+ line.undiscounted_total_price = total_price_data.undiscounted_price
+ line.tax_rate = (
+ unit_price_data.price_with_discounts.tax
+ / unit_price_data.price_with_discounts.net
+ )
warehouse = next(warehouse_iter)
increase_stock(line, warehouse, line.quantity, allocate=True)
OrderLine.objects.bulk_update(
@@ -653,17 +656,20 @@ def create_order_lines_with_preorder(order, discounts, how_many=1):
preorder_allocations = []
for line in lines:
variant = line.variant
- unit_price = manager.calculate_order_line_unit(
+ unit_price_data = manager.calculate_order_line_unit(
order, line, variant, variant.product
)
- total_price = manager.calculate_order_line_total(
+ total_price_data = manager.calculate_order_line_total(
order, line, variant, variant.product
)
- line.unit_price = unit_price
- line.total_price = total_price
- line.undiscounted_unit_price = unit_price
- line.undiscounted_total_price = total_price
- line.tax_rate = unit_price.tax / unit_price.net
+ line.unit_price = unit_price_data.price_with_discounts
+ line.total_price = total_price_data.price_with_discounts
+ line.undiscounted_unit_price = unit_price_data.undiscounted_price
+ line.undiscounted_total_price = total_price_data.undiscounted_price
+ line.tax_rate = (
+ unit_price_data.price_with_discounts.tax
+ / unit_price_data.price_with_discounts.net
+ )
variant_channel_listing = variant.channel_listings.get(channel=channel)
preorder_allocations.append(
PreorderAllocation(
diff --git a/saleor/graphql/channel/tests/fixtures.py b/saleor/graphql/channel/tests/fixtures.py
index f16bc61c6a..2f6bf9d253 100644
--- a/saleor/graphql/channel/tests/fixtures.py
+++ b/saleor/graphql/channel/tests/fixtures.py
@@ -36,3 +36,14 @@ def channel_PLN(db):
default_country="PL",
is_active=True,
)
+
+
+def channel_JPY(db):
+ return Channel.objects.create(
+ name="Channel=JPY",
+ slug="c-jpy",
+ currency_code="JPY",
+ default_country="JP",
+ is_active=True,
+ )
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.py
index 46597b9d47..efa1352845 100644
--- a/saleor/graphql/order/mutations/draft_orders.py
+++ b/saleor/graphql/order/mutations/draft_orders.py
@@ -255,6 +255,7 @@ class DraftOrderCreate(ModelMutation, I18nMixin):
info.context.user,
info.context.app,
info.context.plugins,
+ info.context.site.settings,
)
# New event
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
index 87ae7de2e5..adc94e8731 100644
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -804,7 +804,9 @@ class OrderLinesCreate(EditableOrderValidationMixin, BaseMutation):
raise ValidationError(error)
@staticmethod
- def add_lines_to_order(order, lines_to_add, user, app, manager, discounts):
+ def add_lines_to_order(
+ order, lines_to_add, user, app, manager, settings, discounts
+ ):
try:
return [
add_variant_to_order(
@@ -814,6 +816,7 @@ class OrderLinesCreate(EditableOrderValidationMixin, BaseMutation):
user,
app,
manager,
+ settings,
discounts=discounts,
allocate_stock=order.is_unconfirmed(),
)
@@ -840,6 +843,7 @@ class OrderLinesCreate(EditableOrderValidationMixin, BaseMutation):
info.context.user,
info.context.app,
info.context.plugins,
+ info.context.site.settings,
info.context.discounts,
)
diff --git a/saleor/graphql/order/tests/test_discount_order.py b/saleor/graphql/order/tests/test_discount_order.py
index 82a2d4f6cc..813218a794 100644
--- a/saleor/graphql/order/tests/test_discount_order.py
+++ b/saleor/graphql/order/tests/test_discount_order.py
@@ -10,6 +10,7 @@ from ....core.prices import quantize_price
from ....discount import DiscountValueType
from ....order import OrderEvents, OrderStatus
from ....order.error_codes import OrderErrorCode
+from ....order.interface import OrderTaxedPricesData
from ...discount.enums import DiscountValueTypeEnum
from ...tests.utils import get_graphql_content
@@ -719,8 +720,14 @@ def test_delete_discount_from_order_line(
line_undiscounted_price = line.undiscounted_unit_price
line_undiscounted_total_price = line.undiscounted_total_price
- mocked_calculate_order_line_unit.return_value = line_undiscounted_price
- mocked_calculate_order_line_total.return_value = line_undiscounted_total_price
+ mocked_calculate_order_line_unit.return_value = OrderTaxedPricesData(
+ undiscounted_price=line_undiscounted_price,
+ price_with_discounts=line_undiscounted_price,
+ )
+ mocked_calculate_order_line_total.return_value = OrderTaxedPricesData(
+ undiscounted_price=line_undiscounted_total_price,
+ price_with_discounts=line_undiscounted_total_price,
+ )
line.unit_discount_amount = Decimal("2.5")
line.unit_discount_type = DiscountValueType.FIXED
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.py
index c407a22097..6f19added1 100644
--- a/saleor/graphql/order/tests/test_order.py
+++ b/saleor/graphql/order/tests/test_order.py
@@ -4084,6 +4084,15 @@ def test_order_lines_create_variant_on_sale(
== variant_channel_listing.price_amount - sale_channel_listing.discount_value
)
+ line = order.lines.get(product_sku=variant.sku)
+ assert line.sale_id == graphene.Node.to_global_id("Sale", sale.id)
+ assert line.unit_discount_amount == sale_channel_listing.discount_value
+ assert line.unit_discount_value == sale_channel_listing.discount_value
+ assert (
+ line.unit_discount_reason
+ == f"Sale: {graphene.Node.to_global_id('Sale', sale.id)}"
+ )
+
@pytest.mark.parametrize("status", (OrderStatus.DRAFT, OrderStatus.UNCONFIRMED))
@patch("saleor.plugins.manager.PluginsManager.draft_order_updated")
diff --git a/saleor/order/interface.py b/saleor/order/interface.py
new file mode 100644
index 0000000000..c1c86805fb
--- /dev/null
+++ b/saleor/order/interface.py
@@ -0,0 +1,16 @@
+from dataclasses import dataclass
+
+from prices import TaxedMoney
+
+
+@dataclass
+class OrderTaxedPricesData:
+ """Store an order prices data with applied taxes.
+
+ 'price_with_discounts' includes voucher discount and sale discount if any valid
+ exists.
+ 'undiscounted_price' is a price without any sale and voucher.
+ """
+
+ undiscounted_price: TaxedMoney
+ price_with_discounts: TaxedMoney
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index 9b97f2f30e..7a3ac6a70d 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -389,6 +389,7 @@ def test_send_confirmation_emails_without_addresses_for_payment(
user=info.context.user,
app=info.context.app,
manager=info.context.plugins,
+ site_settings=site_settings,
)
DigitalContentUrl.objects.create(content=digital_content, line=line)
@@ -434,6 +435,7 @@ def test_send_confirmation_emails_without_addresses_for_order(
user=info.context.user,
app=info.context.app,
manager=info.context.plugins,
+ site_settings=site_settings,
)
DigitalContentUrl.objects.create(content=digital_content, line=line)
diff --git a/saleor/order/tests/test_order.py b/saleor/order/tests/test_order.py
index a898c2c272..80935b9eeb 100644
--- a/saleor/order/tests/test_order.py
+++ b/saleor/order/tests/test_order.py
@@ -16,6 +16,7 @@ from ...discount.models import (
)
from ...discount.utils import validate_voucher_in_order
from ...graphql.tests.utils import get_graphql_content
+from ...order.interface import OrderTaxedPricesData
from ...payment import ChargeStatus
from ...payment.models import Payment
from ...plugins.manager import get_plugins_manager
@@ -78,14 +79,20 @@ def test_order_get_subtotal(order_with_lines):
def test_add_variant_to_order_adds_line_for_new_variant(
- order_with_lines, product, product_translation_fr, settings, info
+ order_with_lines, product, product_translation_fr, settings, info, site_settings
):
order = order_with_lines
variant = product.variants.get()
lines_before = order.lines.count()
settings.LANGUAGE_CODE = "fr"
add_variant_to_order(
- order, variant, 1, info.context.user, info.context.app, info.context.plugins
+ order,
+ variant,
+ 1,
+ info.context.user,
+ info.context.app,
+ info.context.plugins,
+ site_settings,
)
line = order.lines.last()
@@ -97,10 +104,62 @@ def test_add_variant_to_order_adds_line_for_new_variant(
assert line.translated_product_name == str(variant.product.translated)
assert line.variant_name == str(variant)
assert line.product_name == str(variant.product)
+ assert not line.unit_discount_amount
+ assert not line.unit_discount_value
+ assert not line.unit_discount_reason
+
+
+def test_add_variant_to_order_adds_line_for_new_variant_on_sale(
+ order_with_lines,
+ product,
+ product_translation_fr,
+ sale,
+ discount_info,
+ settings,
+ info,
+ site_settings,
+):
+ order = order_with_lines
+ variant = product.variants.first()
+ discount_info.variants_ids.add(variant.id)
+ sale.variants.add(variant)
+ lines_before = order.lines.count()
+ settings.LANGUAGE_CODE = "fr"
+
+ add_variant_to_order(
+ order,
+ variant,
+ 1,
+ info.context.user,
+ info.context.app,
+ info.context.plugins,
+ site_settings,
+ [discount_info],
+ )
+
+ line = order.lines.last()
+ variant_channel_listing = variant.channel_listings.get(channel=order.channel)
+ sale_channel_listing = sale.channel_listings.first()
+ assert order.lines.count() == lines_before + 1
+ assert line.product_sku == variant.sku
+ assert line.quantity == 1
+ unit_amount = (
+ variant_channel_listing.price_amount - sale_channel_listing.discount_value
+ )
+ assert line.unit_price == TaxedMoney(
+ net=Money(unit_amount, "USD"), gross=Money(unit_amount, "USD")
+ )
+ assert line.translated_product_name == str(variant.product.translated)
+ assert line.variant_name == str(variant)
+ assert line.product_name == str(variant.product)
+
+ assert line.unit_discount_amount == sale_channel_listing.discount_value
+ assert line.unit_discount_value == sale_channel_listing.discount_value
+ assert line.unit_discount_reason
def test_add_variant_to_draft_order_adds_line_for_new_variant_with_tax(
- order_with_lines, product, product_translation_fr, settings, info
+ order_with_lines, product, product_translation_fr, settings, info, site_settings
):
order = order_with_lines
variant = product.variants.get()
@@ -108,14 +167,22 @@ def test_add_variant_to_draft_order_adds_line_for_new_variant_with_tax(
settings.LANGUAGE_CODE = "fr"
unit_price = TaxedMoney(net=Money(8, "USD"), gross=Money(10, "USD"))
total_price = TaxedMoney(net=Money("30.34", "USD"), gross=Money("36.49", "USD"))
+ unit_price_data = OrderTaxedPricesData(
+ undiscounted_price=unit_price,
+ price_with_discounts=unit_price,
+ )
+ total_price_data = OrderTaxedPricesData(
+ undiscounted_price=total_price,
+ price_with_discounts=total_price,
+ )
manager = Mock(
- calculate_order_line_unit=Mock(return_value=unit_price),
- calculate_order_line_total=Mock(return_value=total_price),
+ calculate_order_line_unit=Mock(return_value=unit_price_data),
+ calculate_order_line_total=Mock(return_value=total_price_data),
get_order_line_tax_rate=Mock(return_value=0.25),
)
add_variant_to_order(
- order, variant, 1, info.context.user, info.context.app, manager
+ order, variant, 1, info.context.user, info.context.app, manager, site_settings
)
line = order.lines.last()
@@ -131,7 +198,7 @@ def test_add_variant_to_draft_order_adds_line_for_new_variant_with_tax(
def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(
- order_with_lines, product, product_translation_fr, settings, info
+ order_with_lines, product, product_translation_fr, settings, info, site_settings
):
order = order_with_lines
variant = product.variants.get()
@@ -142,7 +209,13 @@ def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(
lines_before = order.lines.count()
settings.LANGUAGE_CODE = "fr"
add_variant_to_order(
- order, variant, 1, info.context.user, info.context.app, info.context.plugins
+ order,
+ variant,
+ 1,
+ info.context.user,
+ info.context.app,
+ info.context.plugins,
+ site_settings,
)
line = order.lines.last()
@@ -156,7 +229,7 @@ def test_add_variant_to_draft_order_adds_line_for_variant_with_price_0(
def test_add_variant_to_order_not_allocates_stock_for_new_variant(
- order_with_lines, product, info
+ order_with_lines, product, info, site_settings
):
variant = product.variants.get()
stock = Stock.objects.get(product_variant=variant)
@@ -170,13 +243,16 @@ def test_add_variant_to_order_not_allocates_stock_for_new_variant(
info.context.user,
info.context.app,
info.context.plugins,
+ site_settings,
)
stock.refresh_from_db()
assert get_quantity_allocated_for_stock(stock) == stock_before
-def test_add_variant_to_order_edits_line_for_existing_variant(order_with_lines, info):
+def test_add_variant_to_order_edits_line_for_existing_variant(
+ order_with_lines, info, site_settings
+):
existing_line = order_with_lines.lines.first()
variant = existing_line.variant
lines_before = order_with_lines.lines.count()
@@ -189,6 +265,7 @@ def test_add_variant_to_order_edits_line_for_existing_variant(order_with_lines,
info.context.user,
info.context.app,
info.context.plugins,
+ site_settings,
)
existing_line.refresh_from_db()
@@ -199,7 +276,7 @@ def test_add_variant_to_order_edits_line_for_existing_variant(order_with_lines,
def test_add_variant_to_order_not_allocates_stock_for_existing_variant(
- order_with_lines, info
+ order_with_lines, info, site_settings
):
existing_line = order_with_lines.lines.first()
variant = existing_line.variant
@@ -215,6 +292,7 @@ def test_add_variant_to_order_not_allocates_stock_for_existing_variant(
info.context.user,
info.context.app,
info.context.plugins,
+ site_settings,
)
stock.refresh_from_db()
@@ -566,7 +644,16 @@ def test_update_order_prices(
)
price_2 = TaxedMoney(net=price_2, gross=price_2)
- mocked_calculate_order_line_unit.side_effect = [price_1, price_2]
+ mocked_calculate_order_line_unit.side_effect = [
+ OrderTaxedPricesData(
+ undiscounted_price=price_1,
+ price_with_discounts=price_1,
+ ),
+ OrderTaxedPricesData(
+ undiscounted_price=price_2,
+ price_with_discounts=price_2,
+ ),
+ ]
shipping_price = order_with_lines.shipping_method.channel_listings.get(
channel_id=order_with_lines.channel_id
@@ -646,7 +733,7 @@ def test_calculate_order_weight(order_with_lines):
assert calculated_weight == order_weight
-def test_order_weight_add_more_variant(order_with_lines, info):
+def test_order_weight_add_more_variant(order_with_lines, info, site_settings):
variant = order_with_lines.lines.first().variant
add_variant_to_order(
order_with_lines,
@@ -655,6 +742,7 @@ def test_order_weight_add_more_variant(order_with_lines, info):
info.context.user,
info.context.app,
info.context.plugins,
+ site_settings,
)
order_with_lines.refresh_from_db()
@@ -663,7 +751,7 @@ def test_order_weight_add_more_variant(order_with_lines, info):
)
-def test_order_weight_add_new_variant(order_with_lines, product, info):
+def test_order_weight_add_new_variant(order_with_lines, product, info, site_settings):
variant = product.variants.first()
add_variant_to_order(
@@ -673,6 +761,7 @@ def test_order_weight_add_new_variant(order_with_lines, product, info):
info.context.user,
info.context.app,
info.context.plugins,
+ site_settings,
)
order_with_lines.refresh_from_db()
@@ -705,12 +794,20 @@ def test_order_weight_delete_line(lines_info):
assert order.weight == _calculate_order_weight_from_lines(order)
-def test_get_order_weight_non_existing_product(order_with_lines, product, info):
+def test_get_order_weight_non_existing_product(
+ order_with_lines, product, info, site_settings
+):
# Removing product should not affect order's weight
order = order_with_lines
variant = product.variants.first()
add_variant_to_order(
- order, variant, 1, info.context.user, info.context.app, info.context.plugins
+ order,
+ variant,
+ 1,
+ info.context.user,
+ info.context.app,
+ info.context.plugins,
+ site_settings,
)
old_weight = order.get_total_weight()
diff --git a/saleor/order/tests/test_order_utils.py b/saleor/order/tests/test_order_utils.py
index 6d911b4c2f..51588e58c7 100644
--- a/saleor/order/tests/test_order_utils.py
+++ b/saleor/order/tests/test_order_utils.py
@@ -7,6 +7,7 @@ from prices import Money, TaxedMoney
from ...checkout.fetch import fetch_checkout_info, fetch_checkout_lines
from ...giftcard import GiftCardEvents
from ...giftcard.models import GiftCardEvent
+from ...order.interface import OrderTaxedPricesData
from ...plugins.manager import get_plugins_manager
from .. import OrderLineData, OrderStatus
from ..events import OrderEvents
@@ -234,16 +235,58 @@ def test_get_valid_shipping_methods_for_order_shipping_not_required(
def test_update_taxes_for_order_lines(order_with_lines):
# given
- line_with_discount = order_with_lines.lines.first()
- line_with_discount.unit_discount_amount = Decimal("2.00")
- line_with_discount.save(update_fields=["unit_discount_amount"])
+ unit_price = TaxedMoney(net=Money("10.23", "USD"), gross=Money("15.80", "USD"))
+ total_price = TaxedMoney(net=Money("30.34", "USD"), gross=Money("36.49", "USD"))
+ tax_rate = Decimal("0.23")
+ unit_price_data = OrderTaxedPricesData(
+ undiscounted_price=unit_price,
+ price_with_discounts=unit_price,
+ )
+ total_price_data = OrderTaxedPricesData(
+ undiscounted_price=total_price,
+ price_with_discounts=total_price,
+ )
+ manager = Mock(
+ calculate_order_line_unit=Mock(return_value=unit_price_data),
+ calculate_order_line_total=Mock(return_value=total_price_data),
+ get_order_line_tax_rate=Mock(return_value=tax_rate),
+ )
+
+ # when
+ update_taxes_for_order_lines(
+ order_with_lines.lines.all(), order_with_lines, manager, True
+ )
+
+ # then
+ for line in order_with_lines.lines.all():
+ assert line.unit_price == unit_price
+ assert line.total_price == total_price
+ assert line.tax_rate == tax_rate
+ assert line.undiscounted_unit_price == unit_price
+ assert line.undiscounted_total_price == total_price
+
+
+def test_update_taxes_for_order_lines_discounted_price(order_with_lines):
+ # given
+ unit_discount_amount = Decimal("2.00")
unit_price = TaxedMoney(net=Money("10.23", "USD"), gross=Money("15.80", "USD"))
total_price = TaxedMoney(net=Money("30.34", "USD"), gross=Money("36.49", "USD"))
tax_rate = Decimal("0.23")
+ discount = TaxedMoney(
+ net=Money(unit_discount_amount, "USD"), gross=Money(unit_discount_amount, "USD")
+ )
+ unit_price_data = OrderTaxedPricesData(
+ undiscounted_price=unit_price + discount,
+ price_with_discounts=unit_price,
+ )
+ total_price_data = OrderTaxedPricesData(
+ undiscounted_price=total_price + discount,
+ price_with_discounts=total_price,
+ )
manager = Mock(
- calculate_order_line_unit=Mock(return_value=unit_price),
- calculate_order_line_total=Mock(return_value=total_price),
+ calculate_order_line_unit=Mock(return_value=unit_price_data),
+ calculate_order_line_total=Mock(return_value=total_price_data),
get_order_line_tax_rate=Mock(return_value=tax_rate),
)
@@ -257,31 +300,34 @@ def test_update_taxes_for_order_lines(order_with_lines):
assert line.unit_price == unit_price
assert line.total_price == total_price
assert line.tax_rate == tax_rate
- if line.pk != line_with_discount.pk:
- assert line.undiscounted_unit_price == unit_price
- assert line.undiscounted_total_price == total_price
- else:
- assert line.undiscounted_unit_price == unit_price + line.unit_discount
- assert (
- line.undiscounted_total_price
- == (unit_price + line.unit_discount) * line.quantity
- )
-
-
-def test_add_variant_to_order(order, customer_user, variant):
+ assert line.undiscounted_unit_price == unit_price + discount
+ assert line.undiscounted_total_price == total_price + discount
+
+
+def test_add_variant_to_order(order, customer_user, variant, site_settings):
# given
unit_price = TaxedMoney(net=Money("10.23", "USD"), gross=Money("15.80", "USD"))
total_price = TaxedMoney(net=Money("30.34", "USD"), gross=Money("36.49", "USD"))
tax_rate = Decimal("0.23")
+ unit_price_data = OrderTaxedPricesData(
+ undiscounted_price=unit_price,
+ price_with_discounts=unit_price,
+ )
+ total_price_data = OrderTaxedPricesData(
+ undiscounted_price=total_price,
+ price_with_discounts=total_price,
+ )
manager = Mock(
- calculate_order_line_unit=Mock(return_value=unit_price),
- calculate_order_line_total=Mock(return_value=total_price),
+ calculate_order_line_unit=Mock(return_value=unit_price_data),
+ calculate_order_line_total=Mock(return_value=total_price_data),
get_order_line_tax_rate=Mock(return_value=tax_rate),
)
app = None
# when
- line = add_variant_to_order(order, variant, 4, customer_user, app, manager)
+ line = add_variant_to_order(
+ order, variant, 4, customer_user, app, manager, site_settings
+ )
# then
assert line.unit_price == unit_price
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index da2587bb44..d153fa2dce 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -3,6 +3,7 @@ from decimal import Decimal
from functools import partial, wraps
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union
+import graphene
from django.conf import settings
from django.utils import timezone
from prices import Money, TaxedMoney, fixed_discount, percentage_discount
@@ -13,7 +14,11 @@ from ..core.tracing import traced_atomic_transaction
from ..core.weight import zero_weight
from ..discount import DiscountValueType, OrderDiscountType
from ..discount.models import NotApplicable, OrderDiscount, Voucher, VoucherType
-from ..discount.utils import get_products_voucher_discount, validate_voucher_in_order
+from ..discount.utils import (
+ get_products_voucher_discount,
+ get_sale_id_applied_as_a_discount,
+ validate_voucher_in_order,
+)
from ..giftcard import events as gift_card_events
from ..giftcard.models import GiftCard
from ..order import FulfillmentStatus, OrderLineData, OrderStatus
@@ -197,19 +202,15 @@ def update_taxes_for_order_line(
line_price = line.unit_price.gross if tax_included else line.unit_price.net
line.unit_price = TaxedMoney(line_price, line_price)
- unit_price = manager.calculate_order_line_unit(order, line, variant, product)
- total_price = manager.calculate_order_line_total(order, line, variant, product)
- line.unit_price = unit_price
- line.total_price = total_price
- line.undiscounted_unit_price = line.unit_price + line.unit_discount
- line.undiscounted_total_price = (
- line.undiscounted_unit_price * line.quantity
- if line.unit_discount
- else total_price
- )
- if unit_price.tax and unit_price.net:
+ unit_price_data = manager.calculate_order_line_unit(order, line, variant, product)
+ total_price_data = manager.calculate_order_line_total(order, line, variant, product)
+ line.unit_price = unit_price_data.price_with_discounts
+ line.total_price = total_price_data.price_with_discounts
+ line.undiscounted_unit_price = unit_price_data.undiscounted_price
+ line.undiscounted_total_price = total_price_data.undiscounted_price
+ if line.unit_price.tax and line.unit_price.net:
line.tax_rate = manager.get_order_line_tax_rate(
- order, product, variant, None, unit_price
+ order, product, variant, None, line.unit_price
)
@@ -317,7 +318,15 @@ def update_order_status(order):
@traced_atomic_transaction()
def add_variant_to_order(
- order, variant, quantity, user, app, manager, discounts=None, allocate_stock=False
+ order,
+ variant,
+ quantity,
+ user,
+ app,
+ manager,
+ site_settings,
+ discounts=None,
+ allocate_stock=False,
):
"""Add total_quantity of variant to order.
@@ -343,11 +352,24 @@ def add_variant_to_order(
product = variant.product
collections = product.collections.all()
channel_listing = variant.channel_listings.get(channel=channel)
+
+ # vouchers are not applied for new lines in unconfirmed/draft orders
unit_price = variant.get_price(
product, collections, channel, channel_listing, discounts
)
+ if not discounts:
+ undiscounted_price = unit_price
+ else:
+ undiscounted_price = variant.get_price(
+ product, collections, channel, channel_listing, []
+ )
unit_price = TaxedMoney(net=unit_price, gross=unit_price)
+ undiscounted_unit_price = TaxedMoney(
+ net=undiscounted_price, gross=undiscounted_price
+ )
total_price = unit_price * quantity
+ undiscounted_total_price = unit_price * quantity
+
product_name = str(product)
variant_name = str(variant)
translated_product_name = str(product.translated)
@@ -367,18 +389,49 @@ def add_variant_to_order(
is_gift_card=variant.is_gift_card(),
quantity=quantity,
unit_price=unit_price,
+ undiscounted_unit_price=undiscounted_unit_price,
total_price=total_price,
+ undiscounted_total_price=undiscounted_total_price,
variant=variant,
)
- unit_price = manager.calculate_order_line_unit(order, line, variant, product)
- total_price = manager.calculate_order_line_total(order, line, variant, product)
- line.unit_price = unit_price
- line.total_price = total_price
- line.undiscounted_unit_price = unit_price
- line.undiscounted_total_price = total_price
+ unit_price_data = manager.calculate_order_line_unit(
+ order, line, variant, product
+ )
+ total_line_price_data = manager.calculate_order_line_total(
+ order, line, variant, product
+ )
+ line.unit_price = unit_price_data.price_with_discounts
+ line.total_price = total_line_price_data.price_with_discounts
+ line.undiscounted_unit_price = unit_price_data.undiscounted_price
+ line.undiscounted_total_price = total_line_price_data.undiscounted_price
line.tax_rate = manager.get_order_line_tax_rate(
order, product, variant, None, unit_price
)
+
+ unit_discount = line.undiscounted_unit_price - line.unit_price
+ if unit_discount.gross:
+ sale_id = get_sale_id_applied_as_a_discount(
+ product=product,
+ price=channel_listing.price,
+ discounts=discounts,
+ collections=collections,
+ channel=channel,
+ variant_id=variant.id,
+ )
+ taxes_included_in_prices = site_settings.include_taxes_in_prices
+ if taxes_included_in_prices:
+ discount_amount = unit_discount.gross
+ else:
+ discount_amount = unit_discount.net
+ line.unit_discount = discount_amount
+ line.unit_discount_value = discount_amount.amount
+ line.unit_discount_reason = (
+ f"Sale: {graphene.Node.to_global_id('Sale', sale_id)}"
+ )
+ line.sale_id = (
+ graphene.Node.to_global_id("Sale", sale_id) if sale_id else None
+ )
+
line.save(
update_fields=[
"currency",
@@ -391,6 +444,10 @@ def add_variant_to_order(
"undiscounted_total_price_gross_amount",
"undiscounted_total_price_net_amount",
"tax_rate",
+ "unit_discount_amount",
+ "unit_discount_value",
+ "unit_discount_reason",
+ "sale_id",
]
)
diff --git a/saleor/payment/gateways/adyen/tests/utils/test_common.py b/saleor/payment/gateways/adyen/tests/utils/test_common.py
index da85f92d70..46a2fa03f5 100644
--- a/saleor/payment/gateways/adyen/tests/utils/test_common.py
+++ b/saleor/payment/gateways/adyen/tests/utils/test_common.py
@@ -19,7 +19,7 @@ from saleor.payment.gateways.adyen.utils.common import (
from saleor.payment.interface import PaymentMethodInfo
from saleor.payment.utils import price_from_minor_unit, price_to_minor_unit
-from ......checkout.interface import TaxedPricesData
+from ......checkout.interface import CheckoutTaxedPricesData
from ...utils.common import prepare_address_request_data
@@ -147,7 +147,7 @@ def test_append_checkout_details_tax_included(
country_code = checkout_ready_to_complete.get_country()
- mocked_calculate_checkout_line_unit_price.return_value = TaxedPricesData(
+ mocked_calculate_checkout_line_unit_price.return_value = CheckoutTaxedPricesData(
price_with_sale=unit_price,
undiscounted_price=unit_price,
price_with_discounts=unit_price,
diff --git a/saleor/plugins/avatax/__init__.py b/saleor/plugins/avatax/__init__.py
index 99df9724bb..fc59e55086 100644
--- a/saleor/plugins/avatax/__init__.py
+++ b/saleor/plugins/avatax/__init__.py
@@ -321,6 +321,7 @@ def get_order_lines_data(
product_type = line.variant.product.product_type
tax_code = retrieve_tax_code_from_meta(product, default=None)
tax_code = tax_code or retrieve_tax_code_from_meta(product_type)
+ prices_data = base_calculations.base_order_line_total(line)
# Confirm if line doesn't have included taxes in the price. If not then, we
# check if the current Saleor config doesn't assume that taxes are included in
@@ -329,22 +330,39 @@ def get_order_lines_data(
line.unit_price_gross_amount != line.unit_price_net_amount
)
tax_included = line_has_included_taxes or system_tax_included
- amount = line.unit_price_gross_amount * line.quantity
- append_line_to_data(
- data=data,
- quantity=line.quantity,
- amount=amount,
+
+ if tax_included:
+ undiscounted_amount = prices_data.undiscounted_price.gross.amount
+ price_with_discounts_amount = prices_data.price_with_discounts.gross.amount
+ else:
+ undiscounted_amount = prices_data.undiscounted_price.net.amount
+ price_with_discounts_amount = prices_data.price_with_discounts.net.amount
+
+ append_line_to_data_kwargs = {
+ "data": data,
+ "quantity": line.quantity,
# This is a workaround for Avatax and sending a lines with amount 0. Like
# order lines which are fully discounted for some reason. If we use a
# standard tax_code, Avatax will raise an exception: "When shipping
# cross-border into CIF countries, Tax Included is not supported with mixed
# positive and negative line amounts."
- tax_code=tax_code if amount else DEFAULT_TAX_CODE,
- item_code=line.variant.sku or line.variant.get_global_id(),
- name=line.variant.product.name,
- tax_included=tax_included,
+ "tax_code": tax_code if undiscounted_amount else DEFAULT_TAX_CODE,
+ "item_code": line.variant.sku or line.variant.get_global_id(),
+ "name": line.variant.product.name,
+ "tax_included": tax_included,
+ }
+ append_line_to_data(
+ **append_line_to_data_kwargs,
+ amount=undiscounted_amount,
)
+ if undiscounted_amount != price_with_discounts_amount:
+ append_line_to_data(
+ **append_line_to_data_kwargs,
+ amount=price_with_discounts_amount,
+ ref1=line.variant.sku,
+ )
+
discount_amount = get_total_order_discount(order)
if discount_amount:
append_line_to_data(
@@ -356,6 +374,7 @@ def get_order_lines_data(
name="Order discount",
tax_included=True, # Voucher should be always applied as a gross amount
)
+
shipping_method_channel_listing = ShippingMethodChannelListing.objects.filter(
shipping_method=order.shipping_method_id, channel=order.channel_id
).first()
diff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.py
index 8bbaa4343d..5939e32820 100644
--- a/saleor/plugins/avatax/plugin.py
+++ b/saleor/plugins/avatax/plugin.py
@@ -14,9 +14,10 @@ from prices import Money, TaxedMoney, TaxedMoneyRange
from ...checkout import base_calculations
from ...checkout.fetch import fetch_checkout_lines
-from ...checkout.interface import TaxedPricesData
+from ...checkout.interface import CheckoutTaxedPricesData
from ...core.taxes import TaxError, TaxType, charge_taxes_on_shipping, zero_taxed_money
from ...discount import DiscountInfo
+from ...order.interface import OrderTaxedPricesData
from ...product.models import ProductType
from ..base_plugin import BasePlugin, ConfigurationTypeField
from ..error_codes import PluginErrorCode
@@ -203,7 +204,7 @@ class AvataxPlugin(BasePlugin):
)
currency = checkout_info.checkout.currency
- taxed_total = TaxedPricesData(
+ taxed_total = CheckoutTaxedPricesData(
price_with_discounts=zero_taxed_money(currency),
price_with_sale=zero_taxed_money(currency),
undiscounted_price=zero_taxed_money(currency),
@@ -381,8 +382,8 @@ class AvataxPlugin(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedPricesData,
- ) -> TaxedPricesData:
+ previous_value: CheckoutTaxedPricesData,
+ ) -> CheckoutTaxedPricesData:
if self._skip_plugin(previous_value):
return previous_value
@@ -412,8 +413,8 @@ class AvataxPlugin(BasePlugin):
taxes_data: Dict[str, Any],
item_code: str,
tax_included: Callable[[], bool],
- base_value: TaxedPricesData,
- ) -> TaxedPricesData:
+ base_value: CheckoutTaxedPricesData,
+ ) -> CheckoutTaxedPricesData:
if not taxes_data or "error" in taxes_data:
return base_value
@@ -458,7 +459,7 @@ class AvataxPlugin(BasePlugin):
)
else:
price_with_discounts = line_price_with_discounts
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
undiscounted_price=undiscounted_line_price,
price_with_sale=price,
price_with_discounts=price_with_discounts,
@@ -472,8 +473,8 @@ class AvataxPlugin(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
- ) -> TaxedMoney:
+ previous_value: OrderTaxedPricesData,
+ ) -> OrderTaxedPricesData:
if self._skip_plugin(previous_value):
return previous_value
@@ -483,35 +484,65 @@ class AvataxPlugin(BasePlugin):
if not _validate_order(order):
return previous_value
+ tax_included = (
+ lambda: Site.objects.get_current().settings.include_taxes_in_prices
+ )
+
taxes_data = self._get_order_tax_data(order, previous_value)
return self._calculate_order_line_total_price(
- taxes_data, variant.sku or variant.get_global_id(), previous_value
+ taxes_data,
+ variant.sku or variant.get_global_id(),
+ tax_included,
+ previous_value,
)
@staticmethod
def _calculate_order_line_total_price(
taxes_data: Dict[str, Any],
item_code: str,
+ tax_included: Callable[[], bool],
base_value: TaxedMoney,
- ):
+ ) -> OrderTaxedPricesData:
if not taxes_data or "error" in taxes_data:
return base_value
- tax_included = (
- lambda: Site.objects.get_current().settings.include_taxes_in_prices
- )
currency = taxes_data.get("currencyCode")
+ undiscounted_line_price = None
+ line_price_with_discounts = None
+
for line in taxes_data.get("lines", []):
- if line.get("itemCode") == item_code:
- tax = Decimal(line.get("tax", 0.0))
- net = Decimal(line["lineAmount"])
- if currency == "JPY" and tax_included():
- line_gross = base_value.gross
- line_net = Money(amount=line_gross.amount - tax, currency=currency)
- else:
- line_gross = Money(amount=net + tax, currency=currency)
- line_net = Money(amount=net, currency=currency)
- return TaxedMoney(net=line_net, gross=line_gross)
+ if line.get("itemCode") != item_code:
+ continue
+ is_discount_record = line.get("ref1")
+
+ tax = Decimal(line.get("tax", 0.0))
+ net = Decimal(line["lineAmount"])
+
+ if currency == "JPY" and tax_included():
+ line_gross = base_value.undiscounted_price.gross
+ if is_discount_record:
+ line_gross = base_value.price_with_discounts.gross
+ line_net = Money(amount=line_gross.amount - tax, currency=currency)
+ else:
+ line_gross = Money(amount=net + tax, currency=currency)
+ line_net = Money(amount=net, currency=currency)
+
+ total = TaxedMoney(net=line_net, gross=line_gross)
+ if is_discount_record:
+ line_price_with_discounts = total
+ else:
+ undiscounted_line_price = total
+
+ if undiscounted_line_price is not None:
+ price_with_discounts = (
+ line_price_with_discounts
+ if line_price_with_discounts is not None
+ else undiscounted_line_price
+ )
+ return OrderTaxedPricesData(
+ undiscounted_price=undiscounted_line_price,
+ price_with_discounts=price_with_discounts,
+ )
return base_value
@@ -522,8 +553,8 @@ class AvataxPlugin(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedPricesData,
- ) -> TaxedPricesData:
+ previous_value: CheckoutTaxedPricesData,
+ ) -> CheckoutTaxedPricesData:
if self._skip_plugin(previous_value):
return previous_value
@@ -539,15 +570,20 @@ class AvataxPlugin(BasePlugin):
)
variant = checkout_line_info.variant
+ quantity = checkout_line_info.line.quantity
taxes_data = get_checkout_tax_data(checkout_info, lines, discounts, self.config)
+ default_total = CheckoutTaxedPricesData(
+ price_with_discounts=previous_value.price_with_discounts * quantity,
+ price_with_sale=previous_value.price_with_sale * quantity,
+ undiscounted_price=previous_value.undiscounted_price * quantity,
+ )
taxed_total_prices_data = self._calculate_checkout_line_total_price(
taxes_data,
variant.sku or variant.get_global_id(),
tax_included,
- previous_value,
+ default_total,
)
- quantity = checkout_line_info.line.quantity
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
undiscounted_price=taxed_total_prices_data.undiscounted_price / quantity,
price_with_sale=taxed_total_prices_data.price_with_sale / quantity,
price_with_discounts=taxed_total_prices_data.price_with_discounts
@@ -560,46 +596,32 @@ class AvataxPlugin(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
- ) -> TaxedMoney:
+ previous_value: OrderTaxedPricesData,
+ ) -> OrderTaxedPricesData:
if not variant or (variant and not product.charge_taxes):
return previous_value
- taxes_data = self._get_order_tax_data(order, previous_value)
- return self._calculate_unit_price(
- taxes_data,
- order_line,
- variant.sku or variant.get_global_id(),
- previous_value,
- )
-
- @staticmethod
- def _calculate_unit_price(
- taxes_data: Dict[str, Any],
- line: Union["CheckoutLine", "OrderLine"],
- item_code: str,
- base_value: TaxedMoney,
- ):
- if taxes_data is None:
- return base_value
tax_included = (
lambda: Site.objects.get_current().settings.include_taxes_in_prices
)
- currency = taxes_data.get("currencyCode")
- for line_data in taxes_data.get("lines", []):
- if line_data.get("itemCode") == item_code:
- tax = Decimal(line_data.get("tax", 0.0)) / line.quantity
- net = Decimal(line_data.get("lineAmount", 0.0)) / line.quantity
-
- if currency == "JPY" and tax_included():
- gross = base_value.gross
- net = Money(amount=gross.amount - tax, currency=currency)
- else:
- gross = Money(amount=net + tax, currency=currency)
- net = Money(amount=net, currency=currency)
- return TaxedMoney(net=net, gross=gross)
- return base_value
+ quantity = order_line.quantity
+ taxes_data = self._get_order_tax_data(order, previous_value)
+ default_total = OrderTaxedPricesData(
+ price_with_discounts=previous_value.price_with_discounts * quantity,
+ undiscounted_price=previous_value.undiscounted_price * quantity,
+ )
+ taxed_total_prices_data = self._calculate_order_line_total_price(
+ taxes_data,
+ variant.sku or variant.get_global_id(),
+ tax_included,
+ default_total,
+ )
+ return OrderTaxedPricesData(
+ undiscounted_price=taxed_total_prices_data.undiscounted_price / quantity,
+ price_with_discounts=taxed_total_prices_data.price_with_discounts
+ / quantity,
+ )
def calculate_order_shipping(
self, order: "Order", previous_value: TaxedMoney
@@ -720,7 +742,9 @@ class AvataxPlugin(BasePlugin):
return response
- def _get_order_tax_data(self, order: "Order", base_value: Decimal):
+ def _get_order_tax_data(
+ self, order: "Order", base_value: Union[Decimal, OrderTaxedPricesData]
+ ):
if self._skip_plugin(base_value):
return None
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_line_unit_price_in_JPY.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_line_unit_price_in_JPY.yaml
new file mode 100644
index 0000000000..9f26dc5cd4
--- /dev/null
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_checkout_line_unit_price_in_JPY.yaml
@@ -0,0 +1,90 @@
+interactions:
+- request:
+ body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesOrder",
+ "lines": [{"quantity": 3, "amount": "3600", "taxCode": "O9999999", "taxIncluded":
+ true, "itemCode": "123", "description": "Test product"}, {"quantity": 1, "amount":
+ "700.000", "taxCode": "FR000000", "taxIncluded": true, "itemCode": "Shipping",
+ "description": null}], "code": "a04119d9-fc1f-40dd-9b5f-520d2b4c5315", "date":
+ "2021-12-23", "customerCode": 0, "addresses": {"shipFrom": {"line1": "Teczowa
+ 7", "line2": null, "city": "Wroclaw", "region": "", "country": "PL", "postalCode":
+ "53-601"}, "shipTo": {"line1": "O\u0142awska 10", "line2": "", "city": "WROC\u0141AW",
+ "region": "", "country": "PL", "postalCode": "53-105"}}, "commit": false, "currencyCode":
+ "JPY", "email": ""}}'
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Authorization:
+ - Basic Og==
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '757'
+ User-Agent:
+ - python-requests/2.26.0
+ method: POST
+ uri: https://rest.avatax.com/api/v2/transactions/createoradjust
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAEA+1X227iSBD9lcjPAdkGQswbSyZSVhFEgexoZzUPjd1Az/i23e1MmFH+fU/1hUuA
+ STSrzdPyZKqrylWnqk6XfwQiCwbheZBWGQ8GAQu7UZRkSWuRRotWN8yyVjLvLVq9OMzieTftdaJe
+ QNpFzcr1DWzjbpz0e+dBxjQ5iMM4akVxK+5ArWbrgpf66siR0kw3CgYzXtSVZHINfb2uyceU5VxN
+ ZMYlZHOm09XIRkdvbqTkZbp2kt/v/oSQP6UrVi75PV40OqaQNkpXBZcPii35zL6F7Eot9PpB8V3/
+ VvMPXmaVdPLQvNge7Ij4E2LX4wohQ0HytCpTkXOAsmC54udBXqVMi6rcupccyWpRLm8PjupGIgvF
+ TeJbpwtO+e5EqAidmku161dXmuXDompKHQw63aTXTrrAk6QfTJQochtlNpIroVKruZXN2FMwuAw7
+ GyUI2DxHOfa9QTxiedrkgBqJOguWfQHCVOt7zhAYEBlXemikUDNIfN0B5hHhA5dgEO0X78NiwVMt
+ HvmxltmtMiwpUl4wkVv4iyoTC8GzA8tZFA/C3qATtZMkjsP+J4TjlVF6aZr4shMlMeBhTwf2FL0o
+ OXr1rx9+WrRkpWKItCrJHJGQyrgp5ujZQRDB5u0tl3GVSlGTM9j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cH16MLWDmHZnbx66ZZu/E/+fPz/8A3ESQGr8PAAA=
+ headers:
+ Connection:
+ - keep-alive
+ Content-Encoding:
+ - gzip
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Thu, 23 Dec 2021 12:05:31 GMT
+ Location:
+ - /api/v2/companies/242975/transactions/0
+ ServerDuration:
+ - '00:00:00.0199441'
+ Transfer-Encoding:
+ - chunked
+ Vary:
+ - Accept-Encoding
+ X-Content-Type-Options:
+ - nosniff
+ referrer-policy:
+ - same-origin
+ strict-transport-security:
+ - max-age=31536000; includeSubdomains
+ x-avalara-uid:
+ - 89bba73b-966e-4316-b910-f90430c5f444
+ x-correlation-id:
+ - 89bba73b-966e-4316-b910-f90430c5f444
+ x-frame-options:
+ - sameorigin
+ x-permitted-cross-domain-policies:
+ - none
+ x-xss-protection:
+ - 1; mode=block
+ status:
+ code: 201
+ message: Created
+version: 1
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_total_with_discount.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_total_with_discount.yaml
new file mode 100644
index 0000000000..e00aced85a
--- /dev/null
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_total_with_discount.yaml
@@ -0,0 +1,104 @@
+interactions:
+- request:
+ body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesInvoice",
+ "lines": [{"quantity": 3, "amount": "36.000", "taxCode": "O9999999", "taxIncluded":
+ true, "itemCode": "SKU_A", "description": "Test product"}, {"quantity": 3, "amount":
+ "30.000", "taxCode": "O9999999", "taxIncluded": true, "itemCode": "SKU_A", "description":
+ "Test product", "ref1": "SKU_A"}, {"quantity": 1, "amount": "10.000", "taxCode":
+ "FR000000", "taxIncluded": true, "itemCode": "Shipping", "description": null}],
+ "code": "06e18f75-c275-4495-8126-3a8b639a0d78", "date": "2021-12-17", "customerCode":
+ 0, "addresses": {"shipFrom": {"line1": "Teczowa 7", "line2": null, "city": "Wroclaw",
+ "region": "", "country": "PL", "postalCode": "53-601"}, "shipTo": {"line1":
+ "O\u0142awska 10", "line2": "", "city": "WROC\u0141AW", "region": "", "country":
+ "PL", "postalCode": "53-105"}}, "commit": false, "currencyCode": "USD", "email":
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Authorization:
+ - Basic Og==
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '928'
+ User-Agent:
+ - python-requests/2.26.0
+ method: POST
+ uri: https://rest.avatax.com/api/v2/transactions/createoradjust
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAEA+1aWW/bOBD+K4WfY0OH5etpvTkWwQZxEDst0EWxYCQ6VitLXpJK4y3y3/cbHrKs
+ pGnOIhu0D4UyHI7m4Hz8RPpbK01ao17k4Z/f73tROOzvtOIi4a1Ry+txfzDvR+04wH/d7jBqD/yg
+ 1w7Z4LwXDpmX9Act0l6uWL4+hKGgGwz70U4rYYoMBF7gt/2g7fehJhVTpYR0yi55AoFar0hpyjIu
+ D/PLIo05pOdMxYtd4wAZL4Xgeby2krPpHoT8Kl6w/IKf4jW7tynEpVTFkoszyS74zLyH5uUqVesz
+ yev2jeZ7nieFsHJPv9gM1ET8ii9X6riA01AQPC7yOM0Qy2jOMsl3WlkRM5UW+ca84KtCqDS/OLox
+ tCoFopB8IhIuNkbnnOKteSgpPysuZN2uYleTSy5Emrjwjouc0lcbGC+LMletkdfxtuSnnMGWCUIV
+ imVOsed3+kOokmxfx+omk2QvlXHdIMlm7Ko18rudwLfTIGDnGcpatwXhLsviMkO5kCyrz5LPqNIS
+ NakcOi7UWEv1+tgo7HEZi3RFqTVuI9FfankX/KIa0j6KNfROjpAPJEnqMXgoi7n6ygR/72StwO/4
+ QSfsUMELkV6k+ThJBJeSFnOvR10RdgdhGHoDLGouUUld4LqW7p2NVn1t7s/nPFbpJd+7pR/qikgK
+ FQlv2I6TL1maIRSFV//Gr9hylfEO+g3unpcyzbWntKrnqVl5bh0tiwQyntx48cyPRr438gadX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C6kOc1kComN+IHh6sXD8+JKpCuOmbWDBpN02
+ BJIpQ1coWkqYRyGmlFmdlscRnwDe/CI+TyY+3U44JHS6nfg4rvQi7Cfq9OijpwHq5JCW1hu+UrUr
+ 7C2xny6hy93s52Ft8ov9vCn2Q2v/NvbjOhcNRMBKLOcVsp+a98/Hflzor4f9GNSq+MoT2Y+Bu8pa
+ g/2Y0Z/GfvAd4tgPfVw6dlN9mjXAyY2/FPvRcGnYz2PdeS3sRxPLx7Gf8PnZDyy+uaMecOoVnb4Y
+ 2u8+dAcdH1+qdc6jzw5f+LDH7wxwMdCgO+TKDbZTaVq2c3BKXyAeHbFiOgmJRYMyGKL0vzrrAdms
+ 2M72UWcFKA9ri19s502xHVr7t7Ad17Kvm+zUnH82suMifzVcx0BWRU6eSHUM1lXWGlTHjP40qjMg
+ cLqDWzSQ6aWpjsbKp7nzU6jOwfcPenDgZgG6dt9lLss3F361A3/a2Jp36e6U54hfcrrK+5iuIruj
+ 0+XMJGNf5Rf2zqf9kU737D0NPYYYhzTGISGePpxOdo/GHyCojv3xvMKRFsvsVhuFbd8j6417AuBO
+ 86DXHWI1LzmfFs2Mx/8WX9k7uu+/OxhRxIj8B8H0PLogvEcwdDJaO5RsnIrWRnSFzHHmIBxGQR/3
+ Ha4RbqueG3uO74GmG7ofw0e78aDmkOVyiTtWfWnbyGe1mjaXO/aLfLe6brnfHRCW2dY9A1geSBLW
+ 583rnjt3QmoL1B0637nQcDcMUKzdO0B/67cHpEV3Fe5iB+PVjw/wXD+hsz9J2OxS5o7DXY/pHxDQ
+ 3cT1p+v/AGjkQVYyIwAA
+ headers:
+ Connection:
+ - keep-alive
+ Content-Encoding:
+ - gzip
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Fri, 17 Dec 2021 15:10:08 GMT
+ Location:
+ - /api/v2/companies/242975/transactions/65000017705397
+ ServerDuration:
+ - '00:00:00.1074532'
+ Transfer-Encoding:
+ - chunked
+ Vary:
+ - Accept-Encoding
+ X-Content-Type-Options:
+ - nosniff
+ referrer-policy:
+ - same-origin
+ strict-transport-security:
+ - max-age=31536000; includeSubdomains
+ x-avalara-uid:
+ - c7699403-93d0-486d-b749-30c326df71e6
+ x-correlation-id:
+ - c7699403-93d0-486d-b749-30c326df71e6
+ x-frame-options:
+ - sameorigin
+ x-permitted-cross-domain-policies:
+ - none
+ x-xss-protection:
+ - 1; mode=block
+ status:
+ code: 201
+ message: Created
+version: 1
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit.yaml
index c563ade26d..14652d1a92 100644
--- a/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit.yaml
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit.yaml
@@ -4,10 +4,10 @@ interactions:
"lines": [{"quantity": 3, "amount": "30.000", "taxCode": "O9999999", "taxIncluded":
true, "itemCode": "SKU_A", "description": "Test product"}, {"quantity": 1, "amount":
"10.000", "taxCode": "FR000000", "taxIncluded": true, "itemCode": "Shipping",
- "description": null}], "code": "7e3a27d0-5bcd-4678-b362-33d3b0834d63", "date":
- "2021-03-02", "customerCode": 0, "addresses": {"shipFrom": {"line1": "2000 Main
- Street", "line2": "", "city": "Irvine", "region": "CA", "country": "US", "postalCode":
- "92614"}, "shipTo": {"line1": "T\u0119czowa 7", "line2": "", "city": "WROC\u0141AW",
+ "description": null}], "code": "9c6f6276-3c68-49a9-996d-081cd843cf89", "date":
+ "2021-12-23", "customerCode": 0, "addresses": {"shipFrom": {"line1": "Teczowa
+ 7", "line2": null, "city": "Wroclaw", "region": "", "country": "PL", "postalCode":
+ "53-601"}, "shipTo": {"line1": "T\u0119czowa 7", "line2": "", "city": "WROC\u0141AW",
"region": "", "country": "PL", "postalCode": "53-601"}}, "commit": false, "currencyCode":
"USD", "email": "[email protected]"}}'
headers:
@@ -20,50 +20,46 @@ interactions:
Connection:
- keep-alive
Content-Length:
- - '782'
+ - '777'
User-Agent:
- - python-requests/2.25.1
+ - python-requests/2.26.0
method: POST
uri: https://rest.avatax.com/api/v2/transactions/createoradjust
response:
body:
string: !!binary |
- H4sIAAAAAAAEA+1ZW2/byBX+K4aeLWF4EUXqqVo7Loy6lmHJu0CKxWJEji1uKVIdkl67Qf57vzMX
- ckjbadIk7bZokAfxzJkz5z7fHH+Y5Nlk6THmBXESeIs48k4naZWJyXKyEAH3FxmbzndpNg2jRTzd
- BZE/DYIs2LE4CLMomBD34cjL50vI8UM/WcxPJxlvSIDPfG/KginzwVY3vGlrUDf8UWQgNM9HYtrw
- QtSX5WOVpwLUHW/S/ZlWgIS3UooyfTaUu805iOIp3fPyQdzimLPXGNK2bqqDkHc1fxBbfQ7tK5u8
- eb6rhStfc/4oyqyShs7UwXrBIYkncTg21xWUBoMUaVWmeQFblve8qMXppKhS3uRV2YuX4ljJJi8f
- rl4sHVsJK2qxlpmQvdB7QfY6Gtbkn6OQtSu34U/rRyFlnlnzrquS3OcsrA5VWzaTJZuxAf1WcMjS
- RjRVwwvLGISzIAEr0d4pW+1mopzndeoKJNqWP02W8xnljNqFb74rEFVXFIhnvEjbAtGCrzQ7z35F
- jA6ISKfOddWsFFVlR89wLupU5kdyrFYabv6r43UpHrolpaF8Bt/NFbwBF9VqDQrW1X3zG5fiR0ub
- +N7Mm8E7YKxk/pCXqyyToq4pk+eMUfaGXhzFERJa1IiiCq7DFIJp7iWBzxbMH6blu/t7kTb5ozh/
- pRTc/EXxUXxwwNBIceB5ATsanPwH8cQPx0LMUGpQdtfWean0pIS+z3XS2RQ6VBloIntx8JYtlmG4
- 9KPZIvHmYRC+hyzLjaKQqoLjwEtgC/LoFQFsyeg/bSxIhcnyLx9UAwkYC30WJQGbhyF2S17WHPZX
- JQkdtRfaet0edkLCPo8MQl5lXD7blKY98MnnV/HQe1u47OQoq6xNG0j/rNj90wQw2W9rRRVVZojU
- YYzOukcMuDTpTMhmwGPjldeXjTh0ldPIFp0krzeb7U3XWHJwmKay+dP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
- - Tue, 02 Mar 2021 07:44:26 GMT
+ - Thu, 23 Dec 2021 12:04:24 GMT
Location:
- - /api/v2/companies/242975/transactions/1001389317861
- Server:
- - Kestrel
+ - /api/v2/companies/242975/transactions/70000019400075
ServerDuration:
- - '00:00:00.0429835'
+ - '00:00:00.1001416'
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
+ X-Content-Type-Options:
+ - nosniff
+ referrer-policy:
+ - same-origin
+ strict-transport-security:
+ - max-age=31536000; includeSubdomains
+ x-avalara-uid:
+ - 04522cbc-2e72-4d92-8782-019c7b038d0c
+ x-correlation-id:
+ - 04522cbc-2e72-4d92-8782-019c7b038d0c
+ x-frame-options:
+ - sameorigin
+ x-permitted-cross-domain-policies:
+ - none
+ x-xss-protection:
+ - 1; mode=block
status:
code: 201
message: Created
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_in_JPY.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_in_JPY.yaml
new file mode 100644
index 0000000000..db5792d03c
--- /dev/null
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_in_JPY.yaml
@@ -0,0 +1,99 @@
+interactions:
+- request:
+ body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesInvoice",
+ "lines": [{"quantity": 3, "amount": "3600.000", "taxCode": "O9999999", "taxIncluded":
+ true, "itemCode": "123", "description": "Test product"}, {"quantity": 1, "amount":
+ "700.000", "taxCode": "FR000000", "taxIncluded": true, "itemCode": "Shipping",
+ "description": null}], "code": "6b66cae1-cd65-42bf-b234-ce3a3934e49b", "date":
+ "2021-12-23", "customerCode": 0, "addresses": {"shipFrom": {"line1": "Teczowa
+ 7", "line2": null, "city": "Wroclaw", "region": "", "country": "PL", "postalCode":
+ "53-601"}, "shipTo": {"line1": "T\u0119czowa 7", "line2": "", "city": "WROC\u0141AW",
+ "region": "", "country": "PL", "postalCode": "53-601"}}, "commit": false, "currencyCode":
+ "JPY", "email": "[email protected]"}}'
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Authorization:
+ - Basic Og==
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '778'
+ User-Agent:
+ - python-requests/2.26.0
+ method: POST
+ uri: https://rest.avatax.com/api/v2/transactions/createoradjust
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAEA+1Y2W7bRhT9lUDPlsBN1PJU1UvhwpAMS0nQFHkYkSOJLUWqw6FjNfC/99xZuHnJ
+ HgRB8xDId+5c3vXMmXnfS+LeNBw7+OdOAvrPP+lFecx70164DsOIcbcfxeGwH3jrTX/t+UE/4j7z
+ J37Ag8m6R9r7A8uOlzDkBd5kNDzpxUySAc/x3L7r9T0faoVksiwgXbJbHkMgjwdSWrKUF5fZbZ5E
+ HNI1k9HuVDtAxksheBYdjeT36z8g5HfRjmVbfoPPnD6mEJWFzPdcvCzYlq/0d2hfJhN5fFnwpn2t
+ +YpncS6M3FEf1gsNEb/j+4Oc53AaCoJHeRYlKWKZblha8JNemkdMJnlWmxf8kAuZZNurB0uHUiCK
+ gi9EzEVtdMMp3oaHBeXnwEXRtCvZ3eKWC5HENrx5nlH6GguzfV5msjd1Bk5LfsMZbOkgZC5ZahX9
+ YDIcTAIok/RcRWu3k+QsKaKmSZKt2F1vOnZ89Q0jYOsUhW1bg94pS6MyRcmQMLODxX+hUnvUpXJq
+ nsuZkqoeqRXOeBGJ5EDp1a4j2X83ci/4tlpSXooj9K6vkBMkqlBrLrow38h3TPBXVtbz3IHrDRAA
+ NHORbJNsFseCFwU1dBjSZPijiTdxxx4amxeopipyU2vY1mr25/lmwyOZ3PKzR2aiqdibupREfKEd
+ J9+zJEUoEp/+hd+x/SHlA8wc3F2XRZIpT6mzN4nuPttL+zyGjMcPPrxyvakznLrhYOiGnjt+A1NW
+ GcMh1CSPfXeCgNFPD/ZDPaXv9qZ/vtf4AeBwnJHjBc5wiPGXgmUFQ9R5ppLYgRfaPC/3ay4Qlktx
+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oQI9GNb2F0GE4GrtumQIpQf2MK5PqWOTRBXXuj
+ cLU557Wy6auLGzptHLp7ENoaBhSMRhMleIyhQe/HZEA43CoGBKxrXAIqBvRpw/E/A/qpGBA1/3jy
+ CAOqRxe9TYhKROcHJECtAL4aAaqj/2H4j0Wvit98If3RiXua/tj170Z/CIeeoz8dnPrW9Ieo1Be6
+ ozyu36m+Df25eJr+gIYauG6+C3W8ahwJimV23oUs97nit5xevN4kh6E55ekRY8Wjf/N37MXIyMxz
+ BrFfH8uQRmDO+PX6ZnF6NXsNQXUzxu8DeB5Lzbk79PuhQ09Pnas0AKh7D6qYXYfwfq9gRB6l7N3X
+ CoauCw2m3rkqNFZUgdRdOPCGI388wqOGnYPHimfXvsYVoeuGaqPPd6PThc34TTsQpzRXg6Lc7/EU
+ qd42O81RdVP9/mFOq9PqReLjnknQZq1rOB5ccAlHfz58EXn2SESzmxeBJ+779voNxcalHDb1U2P1
+ Rk96dJW3rx/QoEf6YODQW1b7HcCK6+NKPwLYVyT11E5X9/u39/8BRLG50mAaAAA=
+ headers:
+ Connection:
+ - keep-alive
+ Content-Encoding:
+ - gzip
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Thu, 23 Dec 2021 12:05:16 GMT
+ Location:
+ - /api/v2/companies/242975/transactions/68000019400193
+ ServerDuration:
+ - '00:00:00.1104409'
+ Transfer-Encoding:
+ - chunked
+ Vary:
+ - Accept-Encoding
+ X-Content-Type-Options:
+ - nosniff
+ referrer-policy:
+ - same-origin
+ strict-transport-security:
+ - max-age=31536000; includeSubdomains
+ x-avalara-uid:
+ - 6fd3edce-8123-4492-8104-cec91c28f68a
+ x-correlation-id:
+ - 6fd3edce-8123-4492-8104-cec91c28f68a
+ x-frame-options:
+ - sameorigin
+ x-permitted-cross-domain-policies:
+ - none
+ x-xss-protection:
+ - 1; mode=block
+ status:
+ code: 201
+ message: Created
+version: 1
diff --git a/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_with_discount.yaml b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_with_discount.yaml
new file mode 100644
index 0000000000..621a386937
--- /dev/null
+++ b/saleor/plugins/avatax/tests/cassettes/test_calculate_order_line_unit_with_discount.yaml
@@ -0,0 +1,104 @@
+interactions:
+- request:
+ body: '{"createTransactionModel": {"companyCode": "DEFAULT", "type": "SalesInvoice",
+ "lines": [{"quantity": 3, "amount": "36.900", "taxCode": "O9999999", "taxIncluded":
+ true, "itemCode": "SKU_A", "description": "Test product"}, {"quantity": 3, "amount":
+ "30.000", "taxCode": "O9999999", "taxIncluded": true, "itemCode": "SKU_A", "description":
+ "Test product", "ref1": "SKU_A"}, {"quantity": 1, "amount": "10.000", "taxCode":
+ "FR000000", "taxIncluded": true, "itemCode": "Shipping", "description": null}],
+ "code": "4e51b4fe-6f6b-48e1-851e-bf62cf898f25", "date": "2021-12-17", "customerCode":
+ 0, "addresses": {"shipFrom": {"line1": "Teczowa 7", "line2": null, "city": "Wroclaw",
+ "region": "", "country": "PL", "postalCode": "53-601"}, "shipTo": {"line1":
+ "T\u0119czowa 7", "line2": "", "city": "WROC\u0141AW", "region": "", "country":
+ "PL", "postalCode": "53-601"}}, "commit": false, "currencyCode": "USD", "email":
+ headers:
+ Accept:
+ - '*/*'
+ Accept-Encoding:
+ - gzip, deflate
+ Authorization:
+ - Basic Og==
+ Connection:
+ - keep-alive
+ Content-Length:
+ - '927'
+ User-Agent:
+ - python-requests/2.26.0
+ method: POST
+ uri: https://rest.avatax.com/api/v2/transactions/createoradjust
+ response:
+ body:
+ string: !!binary |
+ H4sIAAAAAAAEA+1a227bOBD9lULPsaGL5dvTepNmEWwQB7HTAl0UC1qiY3VlyUtRabJF/33P8CLR
+ StJb0iIomidnOBwOOTOHx0N/8LLUm44DH3/BaOTH0WR04CVlyr2pN+BxsBqseW+4Hq56gzEPeuM4
+ 4L3Vehgm6/FkvA5jj7S3O1bcnsBQOAgno/jAS5kkA6EfBr0g7AUjqFWSybqCdMGueQqBvN2R0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j
+ 53Jq5NGzzJIn/5Xv2Qt6GyeZeaChjxGGIU3QI8Sn1xfzw9PZawialj8+79DRYrm5aeOoN/TpMa3z
+ RgDY6TZ5bQ+r+7r5ozYjyiRn759qM9QYdXqSnaaoM0IBGqnvBNE4msThCG8dtg7uC54de4qvA103
+ qBHqf7sbX1UbVb3d4nFVvdZ2kqPJpvZhx9xRh81Ty5e9/yDN9t4YQPLwwoD8vPvU88mLEMlunjse
+ eMywrwtQdN4cYHPvRwekRe8U9lEH482vDvDZbdCZ3yK0l5R+36CfmNBvPdQvB+hd4uPbj/8DRnt1
+ sisjAAA=
+ headers:
+ Connection:
+ - keep-alive
+ Content-Encoding:
+ - gzip
+ Content-Type:
+ - application/json; charset=utf-8
+ Date:
+ - Fri, 17 Dec 2021 15:10:08 GMT
+ Location:
+ - /api/v2/companies/242975/transactions/81000017705397
+ ServerDuration:
+ - '00:00:00.1340435'
+ Transfer-Encoding:
+ - chunked
+ Vary:
+ - Accept-Encoding
+ X-Content-Type-Options:
+ - nosniff
+ referrer-policy:
+ - same-origin
+ strict-transport-security:
+ - max-age=31536000; includeSubdomains
+ x-avalara-uid:
+ - 89ee2bf4-9bd2-4b85-b0f1-2ad8dd62dbda
+ x-correlation-id:
+ - 89ee2bf4-9bd2-4b85-b0f1-2ad8dd62dbda
+ x-frame-options:
+ - sameorigin
+ x-permitted-cross-domain-policies:
+ - none
+ x-xss-protection:
+ - 1; mode=block
+ status:
+ code: 201
+ message: Created
+version: 1
diff --git a/saleor/plugins/avatax/tests/conftest.py b/saleor/plugins/avatax/tests/conftest.py
index cfd07cbc56..8ae37df232 100644
--- a/saleor/plugins/avatax/tests/conftest.py
+++ b/saleor/plugins/avatax/tests/conftest.py
@@ -1,3 +1,5 @@
+import os
+
import pytest
from ....account.models import Address
@@ -17,9 +19,12 @@ def vcr_config():
@pytest.fixture
def plugin_configuration(db, channel_USD):
+ default_username = os.environ.get("AVALARA_USERNAME", "test")
+ default_password = os.environ.get("AVALARA_PASSWORD", "test")
+
def set_configuration(
- username="test",
- password="test",
+ username=default_username,
+ password=default_password,
sandbox=False,
channel=None,
active=True,
diff --git a/saleor/plugins/avatax/tests/test_avatax.py b/saleor/plugins/avatax/tests/test_avatax.py
index fd86a22965..683e01f3d5 100644
--- a/saleor/plugins/avatax/tests/test_avatax.py
+++ b/saleor/plugins/avatax/tests/test_avatax.py
@@ -547,7 +547,7 @@ def test_calculate_order_line_total(
order_line,
variant,
product,
- )
+ ).price_with_discounts
total = quantize_price(total, total.currency)
assert total == TaxedMoney(net=Money("24.39", "USD"), gross=Money("30.00", "USD"))
@@ -602,11 +602,76 @@ def test_calculate_order_line_without_sku_total(
order_line,
variant,
product,
- )
+ ).price_with_discounts
total = quantize_price(total, total.currency)
assert total == TaxedMoney(net=Money("24.39", "USD"), gross=Money("30.00", "USD"))
+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
+def test_calculate_order_line_total_with_discount(
+ order_line,
+ address,
+ ship_to_pl_address,
+ shipping_zone,
+ site_settings,
+ monkeypatch,
+ plugin_configuration,
+):
+ # given
+ plugin_configuration()
+ manager = get_plugins_manager()
+
+ site_settings.company_address = address
+ site_settings.save(update_fields=["company_address"])
+
+ order = order_line.order
+ order.shipping_address = ship_to_pl_address
+ order.shipping_method = shipping_zone.shipping_methods.get()
+ order.save(update_fields=["shipping_address", "shipping_method"])
+
+ variant = order_line.variant
+ product = variant.product
+ product.metadata = {}
+ product.charge_taxes = True
+ product.save()
+ product.product_type.save()
+
+ channel = order_line.order.channel
+ channel_listing = variant.channel_listings.get(channel=channel)
+
+ discount_amount = Decimal("2.0")
+ currency = order_line.currency
+ order_line.unit_discount = Money(discount_amount, currency)
+ order_line.unit_discount_value = discount_amount
+
+ net = variant.get_price(product, [], channel, channel_listing)
+ unit_price = TaxedMoney(net=net, gross=net)
+ order_line.unit_price = unit_price
+ undiscounted_unit_price = order_line.unit_price + order_line.unit_discount
+ order_line.undiscounted_unit_price = undiscounted_unit_price
+ total_price = unit_price * order_line.quantity
+ order_line.total_price = total_price
+ order_line.undiscounted_total_price = undiscounted_unit_price * order_line.quantity
+ order_line.save()
+
+ # when
+ total_price_data = manager.calculate_order_line_total(
+ order_line.order,
+ order_line,
+ variant,
+ product,
+ )
+
+ # then
+ assert total_price_data.undiscounted_price == TaxedMoney(
+ net=Money(Decimal("29.27"), currency), gross=Money(Decimal("36.00"), currency)
+ )
+ assert total_price_data.price_with_discounts == TaxedMoney(
+ net=Money(Decimal("24.39"), currency), gross=Money(Decimal("30.00"), currency)
+ )
+
+
@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
def test_calculate_order_line_total_order_not_valid(
order_line,
@@ -644,7 +709,7 @@ def test_calculate_order_line_total_order_not_valid(
order_line,
variant,
product,
- )
+ ).price_with_discounts
total = quantize_price(total, total.currency)
assert total == expected_total_price
@@ -1066,6 +1131,93 @@ def test_calculate_order_line_unit(
order_line.unit_price = TaxedMoney(
net=Money("10.00", "USD"), gross=Money("10.00", "USD")
)
+ order_line.undiscounted_unit_price = TaxedMoney(
+ net=Money("10.00", "USD"), gross=Money("10.00", "USD")
+ )
+ order_line.save()
+
+ order = order_line.order
+ method = shipping_zone.shipping_methods.get()
+ order.shipping_address = order.billing_address.get_copy()
+ order.shipping_method_name = method.name
+ order.shipping_method = method
+ order.save()
+
+ site_settings.company_address = address_usa
+ site_settings.save()
+
+ line_price_data = manager.calculate_order_line_unit(
+ order, order_line, order_line.variant, order_line.variant.product
+ )
+
+ expected_line_price = TaxedMoney(
+ net=Money("8.13", "USD"), gross=Money("10.00", "USD")
+ )
+ assert line_price_data.undiscounted_price == expected_line_price
+ assert line_price_data.price_with_discounts == expected_line_price
+
+
+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
+def test_calculate_order_line_unit_in_JPY(
+ order_line_JPY,
+ shipping_zone_JPY,
+ site_settings,
+ address,
+ channel_JPY,
+ plugin_configuration,
+):
+ plugin_configuration(channel=channel_JPY)
+ manager = get_plugins_manager()
+
+ # Net price from `test_calculate_checkout_line_unit_price_in_JPY`
+ order_line_JPY.unit_price = TaxedMoney(
+ net=Money("976", "JPY"), gross=Money("1200", "JPY")
+ )
+ order_line_JPY.undiscounted_unit_price = TaxedMoney(
+ net=Money("976", "JPY"), gross=Money("1200", "JPY")
+ )
+ order_line_JPY.save()
+
+ order = order_line_JPY.order
+ method = shipping_zone_JPY.shipping_methods.get()
+ order.shipping_address = order.billing_address.get_copy()
+ order.shipping_method_name = method.name
+ order.shipping_method = method
+ order.save()
+
+ site_settings.company_address = address
+ site_settings.save()
+
+ line_price_data = manager.calculate_order_line_unit(
+ order, order_line_JPY, order_line_JPY.variant, order_line_JPY.variant.product
+ )
+
+ expected_line_price = TaxedMoney(
+ net=Money("976", "JPY"), gross=Money("1200", "JPY")
+ )
+ assert line_price_data.undiscounted_price == expected_line_price
+ assert line_price_data.price_with_discounts == expected_line_price
+
+
+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
+def test_calculate_order_line_unit_with_discount(
+ order_line,
+ shipping_zone,
+ site_settings,
+ address_usa,
+ plugin_configuration,
+):
+ # given
+ plugin_configuration()
+ manager = get_plugins_manager()
+ unit_price = TaxedMoney(net=Money("10.00", "USD"), gross=Money("10.00", "USD"))
+ order_line.unit_price = unit_price
+ currency = order_line.currency
+ discount_amount = Decimal("2.5")
+ order_line.unit_discount = Money(discount_amount, currency)
+ order_line.unit_discount_value = discount_amount
order_line.save()
order = order_line.order
@@ -1078,12 +1230,16 @@ def test_calculate_order_line_unit(
site_settings.company_address = address_usa
site_settings.save()
- line_price = manager.calculate_order_line_unit(
+ # when
+ line_price_data = manager.calculate_order_line_unit(
order, order_line, order_line.variant, order_line.variant.product
)
- line_price = quantize_price(line_price, line_price.currency)
- assert line_price == TaxedMoney(
+ # then
+ assert line_price_data.undiscounted_price == TaxedMoney(
+ net=Money("10.00", "USD"), gross=Money("12.30", "USD")
+ )
+ assert line_price_data.price_with_discounts == TaxedMoney(
net=Money("8.13", "USD"), gross=Money("10.00", "USD")
)
@@ -1143,6 +1299,52 @@ def test_calculate_checkout_line_unit_price(
assert line_price_data.price_with_discounts == expected_line_price
+@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
+def test_calculate_checkout_line_unit_price_in_JPY(
+ checkout_JPY_with_item,
+ shipping_zone_JPY,
+ site_settings,
+ ship_to_pl_address,
+ address,
+ channel_JPY,
+ plugin_configuration,
+):
+ checkout = checkout_JPY_with_item
+ plugin_configuration(channel=channel_JPY)
+
+ lines = fetch_checkout_lines(checkout)
+ checkout_line = lines[0]
+
+ manager = get_plugins_manager()
+
+ method = shipping_zone_JPY.shipping_methods.get()
+ checkout.shipping_address = ship_to_pl_address
+ checkout.shipping_method_name = method.name
+ checkout.shipping_method = method
+ checkout.save()
+
+ site_settings.company_address = address
+ site_settings.include_taxes_in_prices = True
+ site_settings.save()
+
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ line_price_data = manager.calculate_checkout_line_unit_price(
+ checkout_info,
+ lines,
+ checkout_line,
+ checkout.shipping_address,
+ [],
+ )
+
+ expected_line_price = TaxedMoney(
+ net=Money("976", "JPY"), gross=Money("1200", "JPY")
+ )
+ assert line_price_data.price_with_sale == expected_line_price
+ assert line_price_data.undiscounted_price == expected_line_price
+ assert line_price_data.price_with_discounts == expected_line_price
+
+
@pytest.mark.vcr
@override_settings(PLUGINS=["saleor.plugins.avatax.plugin.AvataxPlugin"])
def test_calculate_checkout_line_unit_price_with_variant_on_sale(
@@ -2830,7 +3032,13 @@ def test_get_order_lines_data_sets_different_tax_code_for_zero_amount(
line = order_with_lines.lines.first()
line.unit_price_gross_amount = Decimal("0")
- line.save()
+ line.undiscounted_unit_price_gross_amount = Decimal("0")
+ line.save(
+ update_fields=[
+ "unit_price_gross_amount",
+ "undiscounted_unit_price_gross_amount",
+ ]
+ )
variant = line.variant
variant.product.store_value_in_metadata(
{META_CODE_KEY: "taxcode", META_DESCRIPTION_KEY: "tax_description"}
@@ -2866,7 +3074,14 @@ def test_get_order_lines_data_sets_different_tax_code_only_for_zero_amount(
line = order_with_lines.lines.first()
line.quantity = 1
line.unit_price_gross_amount = Decimal("10.0")
- line.save()
+ line.undiscounted_unit_price_gross_amount = Decimal("10.0")
+ line.save(
+ update_fields=[
+ "quantity",
+ "unit_price_gross_amount",
+ "undiscounted_unit_price_gross_amount",
+ ]
+ )
variant = line.variant
variant.product.store_value_in_metadata(
{META_CODE_KEY: "taxcode", META_DESCRIPTION_KEY: "tax_description"}
diff --git a/saleor/plugins/base_plugin.py b/saleor/plugins/base_plugin.py
index adb7283fad..b5e1871bc3 100644
--- a/saleor/plugins/base_plugin.py
+++ b/saleor/plugins/base_plugin.py
@@ -9,7 +9,7 @@ from django.utils.functional import SimpleLazyObject
from django_countries.fields import Country
from prices import Money, TaxedMoney
-from ..checkout.interface import TaxedPricesData
+from ..checkout.interface import CheckoutTaxedPricesData
from ..payment.interface import (
CustomerSource,
GatewayResponse,
@@ -146,7 +146,7 @@ class BasePlugin:
Iterable["DiscountInfo"],
TaxedMoney,
],
- TaxedPricesData,
+ CheckoutTaxedPricesData,
]
# Calculate checkout line unit price.
@@ -159,7 +159,7 @@ class BasePlugin:
Iterable["DiscountInfo"],
Any,
],
- TaxedPricesData,
+ CheckoutTaxedPricesData,
]
# Calculate the shipping costs for checkout.
diff --git a/saleor/plugins/manager.py b/saleor/plugins/manager.py
index 040df41f02..cda58d2bed 100644
--- a/saleor/plugins/manager.py
+++ b/saleor/plugins/manager.py
@@ -23,11 +23,12 @@ from prices import Money, TaxedMoney
from ..channel.models import Channel
from ..checkout import base_calculations
-from ..checkout.interface import TaxedPricesData
+from ..checkout.interface import CheckoutTaxedPricesData
from ..core.payments import PaymentInterface
from ..core.prices import quantize_price
from ..core.taxes import TaxType, zero_taxed_money
from ..discount import DiscountInfo
+from ..order.interface import OrderTaxedPricesData
from .base_plugin import ExternalAccessTokens
from .models import PluginConfiguration
@@ -308,7 +309,7 @@ class PluginsManager(PaymentInterface):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- ) -> TaxedPricesData:
+ ) -> CheckoutTaxedPricesData:
default_value = base_calculations.base_checkout_line_total(
checkout_line_info,
checkout_info.channel,
@@ -342,20 +343,25 @@ class PluginsManager(PaymentInterface):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- ):
+ ) -> OrderTaxedPricesData:
default_value = base_calculations.base_order_line_total(order_line)
- return quantize_price(
- self.__run_method_on_plugins(
- "calculate_order_line_total",
- default_value,
- order,
- order_line,
- variant,
- product,
- channel_slug=order.channel.slug,
- ),
- order.currency,
+ line_total = self.__run_method_on_plugins(
+ "calculate_order_line_total",
+ default_value,
+ order,
+ order_line,
+ variant,
+ product,
+ channel_slug=order.channel.slug,
)
+ currency = order_line.currency
+ line_total.price_with_discounts = quantize_price(
+ line_total.price_with_discounts, currency
+ )
+ line_total.undiscounted_price = quantize_price(
+ line_total.undiscounted_price, currency
+ )
+ return line_total
def calculate_checkout_line_unit_price(
self,
@@ -364,7 +370,7 @@ class PluginsManager(PaymentInterface):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- ) -> TaxedPricesData:
+ ) -> CheckoutTaxedPricesData:
default_value = base_calculations.base_checkout_line_unit_price(
checkout_line_info, checkout_info.channel, discounts
)
@@ -394,21 +400,28 @@ class PluginsManager(PaymentInterface):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- ) -> TaxedMoney:
- unit_price = order_line.unit_price
- default_value = quantize_price(unit_price, unit_price.currency)
- return quantize_price(
- self.__run_method_on_plugins(
- "calculate_order_line_unit",
- default_value,
- order,
- order_line,
- variant,
- product,
- channel_slug=order.channel.slug,
- ),
- order_line.currency,
+ ) -> OrderTaxedPricesData:
+ default_value = OrderTaxedPricesData(
+ undiscounted_price=order_line.undiscounted_unit_price,
+ price_with_discounts=order_line.unit_price,
+ )
+ currency = order_line.currency
+ line_unit = self.__run_method_on_plugins(
+ "calculate_order_line_unit",
+ default_value,
+ order,
+ order_line,
+ variant,
+ product,
+ channel_slug=order.channel.slug,
)
+ line_unit.price_with_discounts = quantize_price(
+ line_unit.price_with_discounts, currency
+ )
+ line_unit.undiscounted_price = quantize_price(
+ line_unit.undiscounted_price, currency
+ )
+ return line_unit
def get_checkout_line_tax_rate(
self,
diff --git a/saleor/plugins/tests/sample_plugins.py b/saleor/plugins/tests/sample_plugins.py
index 7116f0d562..ce5ddce798 100644
--- a/saleor/plugins/tests/sample_plugins.py
+++ b/saleor/plugins/tests/sample_plugins.py
@@ -7,8 +7,9 @@ from django_countries.fields import Country
from prices import Money, TaxedMoney
from ...account.models import User
-from ...checkout.interface import TaxedPricesData
+from ...checkout.interface import CheckoutTaxedPricesData
from ...core.taxes import TaxType
+from ...order.interface import OrderTaxedPricesData
from ..base_plugin import BasePlugin, ConfigurationTypeField, ExternalAccessTokens
if TYPE_CHECKING:
@@ -95,10 +96,10 @@ class PluginSample(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedMoney,
+ previous_value: CheckoutTaxedPricesData,
):
price = Money("1.0", currency=checkout_info.checkout.currency)
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
price_with_sale=TaxedMoney(price, price),
price_with_discounts=TaxedMoney(price, price),
undiscounted_price=TaxedMoney(price, price),
@@ -110,10 +111,13 @@ class PluginSample(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
+ previous_value: OrderTaxedPricesData,
) -> TaxedMoney:
price = Money("1.0", currency=order.currency)
- return TaxedMoney(price, price)
+ return OrderTaxedPricesData(
+ price_with_discounts=TaxedMoney(price, price),
+ undiscounted_price=TaxedMoney(price, price),
+ )
def calculate_checkout_line_unit_price(
self,
@@ -122,11 +126,11 @@ class PluginSample(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedMoney,
+ previous_value: CheckoutTaxedPricesData,
):
currency = checkout_info.checkout.currency
price = Money("10.0", currency)
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
price_with_sale=TaxedMoney(price, price),
price_with_discounts=TaxedMoney(price, price),
undiscounted_price=TaxedMoney(price, price),
@@ -138,11 +142,14 @@ class PluginSample(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
+ previous_value: OrderTaxedPricesData,
):
currency = order_line.unit_price.currency
price = Money("1.0", currency)
- return TaxedMoney(price, price)
+ return OrderTaxedPricesData(
+ price_with_discounts=TaxedMoney(price, price),
+ undiscounted_price=TaxedMoney(price, price),
+ )
def get_tax_rate_type_choices(self, previous_value):
return [TaxType(code="123", description="abc")]
diff --git a/saleor/plugins/tests/test_manager.py b/saleor/plugins/tests/test_manager.py
index fa2eb98c26..2cbf5c05de 100644
--- a/saleor/plugins/tests/test_manager.py
+++ b/saleor/plugins/tests/test_manager.py
@@ -264,8 +264,12 @@ def test_manager_calculates_order_line_total(order_line, plugins):
if plugins
else quantize_price(order_line.unit_price * order_line.quantity, currency)
)
- taxed_total = PluginsManager(plugins=plugins).calculate_order_line_total(
- order_line.order, order_line, order_line.variant, order_line.variant.product
+ taxed_total = (
+ PluginsManager(plugins=plugins)
+ .calculate_order_line_total(
+ order_line.order, order_line, order_line.variant, order_line.variant.product
+ )
+ .price_with_discounts
)
assert expected_total == taxed_total
@@ -495,8 +499,12 @@ def test_manager_calculates_order_line(order_line, plugins, amount):
variant = order_line.variant
currency = order_line.unit_price.currency
expected_price = Money(amount, currency)
- unit_price = PluginsManager(plugins=plugins).calculate_order_line_unit(
- order_line.order, order_line, variant, variant.product
+ unit_price = (
+ PluginsManager(plugins=plugins)
+ .calculate_order_line_unit(
+ order_line.order, order_line, variant, variant.product
+ )
+ .price_with_discounts
)
assert expected_price == unit_price.gross
diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.py
index be9672240d..000bf4fbd2 100644
--- a/saleor/plugins/vatlayer/plugin.py
+++ b/saleor/plugins/vatlayer/plugin.py
@@ -16,9 +16,10 @@ from django_prices_vatlayer.utils import (
from prices import Money, TaxedMoney, TaxedMoneyRange
from ...checkout import base_calculations, calculations
-from ...checkout.interface import PricesData, TaxedPricesData
+from ...checkout.interface import CheckoutTaxedPricesData
from ...core.taxes import TaxType
from ...graphql.core.utils.error_codes import PluginErrorCode
+from ...order.interface import OrderTaxedPricesData
from ...product.models import ProductType
from ..base_plugin import BasePlugin, ConfigurationTypeField
from ..manager import get_plugins_manager
@@ -126,7 +127,13 @@ class VatlayerPlugin(BasePlugin):
def _skip_plugin(
self,
- previous_value: Union[TaxedMoney, TaxedMoneyRange, Decimal, TaxedPricesData],
+ previous_value: Union[
+ TaxedMoney,
+ TaxedMoneyRange,
+ Decimal,
+ CheckoutTaxedPricesData,
+ OrderTaxedPricesData,
+ ],
) -> bool:
if not self.active or not self.config.access_key:
return True
@@ -141,11 +148,18 @@ class VatlayerPlugin(BasePlugin):
if isinstance(previous_value, TaxedMoney):
return previous_value.net != previous_value.gross
- if isinstance(previous_value, TaxedPricesData):
+ if isinstance(previous_value, CheckoutTaxedPricesData):
return (
previous_value.price_with_sale.net
!= previous_value.price_with_sale.gross
)
+
+ if isinstance(previous_value, OrderTaxedPricesData):
+ return (
+ previous_value.price_with_discounts.net
+ != previous_value.price_with_discounts.gross
+ )
+
return False
def calculate_checkout_total(
@@ -263,8 +277,8 @@ class VatlayerPlugin(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedPricesData,
- ) -> TaxedPricesData:
+ previous_value: CheckoutTaxedPricesData,
+ ) -> CheckoutTaxedPricesData:
unit_taxed_prices_data = self.__calculate_checkout_line_unit_price(
checkout_line_info,
checkout_info.channel,
@@ -276,7 +290,7 @@ class VatlayerPlugin(BasePlugin):
return previous_value
quantity = checkout_line_info.line.quantity
- return TaxedPricesData(
+ return CheckoutTaxedPricesData(
price_with_discounts=unit_taxed_prices_data.price_with_discounts * quantity,
price_with_sale=unit_taxed_prices_data.price_with_sale * quantity,
undiscounted_price=unit_taxed_prices_data.undiscounted_price * quantity,
@@ -288,19 +302,21 @@ class VatlayerPlugin(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
- ) -> TaxedMoney:
- unit_price = self.__calculate_order_line_unit(
+ previous_value: OrderTaxedPricesData,
+ ) -> OrderTaxedPricesData:
+ unit_price_data = self.__calculate_order_line_unit(
order,
order_line,
variant,
product,
previous_value,
)
- return (
- unit_price * order_line.quantity
- if unit_price is not None
- else previous_value
+ if unit_price_data is None:
+ return previous_value
+ quantity = order_line.quantity
+ return OrderTaxedPricesData(
+ undiscounted_price=unit_price_data.undiscounted_price * quantity,
+ price_with_discounts=unit_price_data.price_with_discounts * quantity,
)
def calculate_checkout_line_unit_price(
@@ -310,8 +326,8 @@ class VatlayerPlugin(BasePlugin):
checkout_line_info: "CheckoutLineInfo",
address: Optional["Address"],
discounts: Iterable["DiscountInfo"],
- previous_value: TaxedPricesData,
- ) -> TaxedPricesData:
+ previous_value: CheckoutTaxedPricesData,
+ ) -> CheckoutTaxedPricesData:
unit_taxed_prices_data = self.__calculate_checkout_line_unit_price(
checkout_line_info,
checkout_info.channel,
@@ -327,7 +343,7 @@ class VatlayerPlugin(BasePlugin):
channel: "Channel",
discounts: Iterable["DiscountInfo"],
address: Optional["Address"],
- previous_value: TaxedPricesData,
+ previous_value: CheckoutTaxedPricesData,
):
if self._skip_plugin(previous_value):
return
@@ -339,7 +355,7 @@ class VatlayerPlugin(BasePlugin):
)
country = address.country if address else None
- taxed_prices_data = TaxedPricesData(
+ taxed_prices_data = CheckoutTaxedPricesData(
price_with_sale=self.__apply_taxes_to_product(
checkout_line_info.product, prices_data.price_with_sale, country
),
@@ -358,12 +374,12 @@ class VatlayerPlugin(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
- ) -> TaxedMoney:
- unit_price = self.__calculate_order_line_unit(
+ previous_value: OrderTaxedPricesData,
+ ) -> OrderTaxedPricesData:
+ unit_price_data = self.__calculate_order_line_unit(
order, order_line, variant, product, previous_value
)
- return unit_price if unit_price is not None else previous_value
+ return unit_price_data if unit_price_data is not None else previous_value
def __calculate_order_line_unit(
self,
@@ -371,7 +387,7 @@ class VatlayerPlugin(BasePlugin):
order_line: "OrderLine",
variant: "ProductVariant",
product: "Product",
- previous_value: TaxedMoney,
+ previous_value: OrderTaxedPricesData,
):
if self._skip_plugin(previous_value):
return
@@ -380,7 +396,15 @@ class VatlayerPlugin(BasePlugin):
country = address.country if address else None
if not variant:
return
- return self.__apply_taxes_to_product(product, order_line.unit_price, country)
+ taxed_prices_data = OrderTaxedPricesData(
+ undiscounted_price=self.__apply_taxes_to_product(
+ product, order_line.undiscounted_unit_price, country
+ ),
+ price_with_discounts=self.__apply_taxes_to_product(
+ product, order_line.unit_price, country
+ ),
+ )
+ return taxed_prices_data
def get_checkout_line_tax_rate(
self,
diff --git a/saleor/plugins/vatlayer/tests/test_vatlayer.py b/saleor/plugins/vatlayer/tests/test_vatlayer.py
index 5263b28738..7c30b559f3 100644
--- a/saleor/plugins/vatlayer/tests/test_vatlayer.py
+++ b/saleor/plugins/vatlayer/tests/test_vatlayer.py
@@ -537,7 +537,9 @@ def test_calculate_order_line_unit(vatlayer, order_line, shipping_zone, site_set
manager.assign_tax_code_to_object_meta(product, "standard")
product.save()
- line_price = manager.calculate_order_line_unit(order, order_line, variant, product)
+ line_price = manager.calculate_order_line_unit(
+ order, order_line, variant, product
+ ).price_with_discounts
line_price = quantize_price(line_price, line_price.currency)
assert line_price == TaxedMoney(
net=Money("8.13", "USD"), gross=Money("10.00", "USD")
@@ -569,7 +571,9 @@ def test_calculate_order_line_unit_from_origin_country(
manager.assign_tax_code_to_object_meta(product, "standard")
product.save()
- line_price = manager.calculate_order_line_unit(order, order_line, variant, product)
+ line_price = manager.calculate_order_line_unit(
+ order, order_line, variant, product
+ ).price_with_discounts
line_price = quantize_price(line_price, line_price.currency)
# make sure that we applied DE taxes (19%)
@@ -601,7 +605,9 @@ def test_calculate_order_line_unit_with_excluded_country(
manager.assign_tax_code_to_object_meta(product, "standard")
product.save()
- line_price = manager.calculate_order_line_unit(order, order_line, variant, product)
+ line_price = manager.calculate_order_line_unit(
+ order, order_line, variant, product
+ ).price_with_discounts
line_price = quantize_price(line_price, line_price.currency)
assert line_price == TaxedMoney(
@@ -751,7 +757,7 @@ def test_calculate_order_line_total(vatlayer, order_line, site_settings):
order_line,
variant,
product,
- )
+ ).price_with_discounts
total_price_amount = total_price.net.amount
currency = total_price.currency
diff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.py
index 9a32de9a8c..f18cd3fe6e 100644
--- a/saleor/tests/fixtures.py
+++ b/saleor/tests/fixtures.py
@@ -288,6 +288,15 @@ def checkout(db, channel_USD):
return checkout
+def checkout_JPY(channel_JPY):
+ checkout = Checkout.objects.create(
+ currency=channel_JPY.currency_code, channel=channel_JPY
+ )
+ checkout.set_country("JP", commit=True)
+ return checkout
+
+
@pytest.fixture
def checkout_with_item(checkout, product):
variant = product.variants.first()
@@ -302,6 +311,15 @@ def checkout_line(checkout_with_item):
return checkout_with_item.lines.first()
+def 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())
+ add_variant_to_checkout(checkout_info, variant, 3)
+ checkout_JPY.save()
+ return checkout_JPY
+
+
@pytest.fixture
def checkouts_list(channel_USD, channel_PLN):
checkouts_usd = Checkout.objects.bulk_create(
@@ -741,6 +759,20 @@ def order_with_search_document_value(order):
return order
+def order_JPY(customer_user, channel_JPY):
+ address = customer_user.default_billing_address.get_copy()
+ return Order.objects.create(
+ billing_address=address,
+ channel=channel_JPY,
+ currency=channel_JPY.currency_code,
+ shipping_address=address,
+ user_email=customer_user.email,
+ user=customer_user,
+ origin=OrderOrigin.CHECKOUT,
+ )
+
+
@pytest.fixture
def order_unconfirmed(order):
order.status = OrderStatus.UNCONFIRMED
@@ -808,6 +840,20 @@ def shipping_zone(db, channel_USD): # pylint: disable=W0613
return shipping_zone
+def shipping_zone_JPY(shipping_zone, channel_JPY):
+ shipping_zone.channels.add(channel_JPY)
+ method = shipping_zone.shipping_methods.get()
+ ShippingMethodChannelListing.objects.create(
+ channel=channel_JPY,
+ currency=channel_JPY.currency_code,
+ shipping_method=method,
+ minimum_order_price=Money(0, channel_JPY.currency_code),
+ price=Money(700, channel_JPY.currency_code),
+ )
+ return shipping_zone
+
+
@pytest.fixture
def shipping_zones(db, channel_USD, channel_PLN):
shipping_zone_poland, shipping_zone_usa = ShippingZone.objects.bulk_create(
@@ -1726,6 +1772,29 @@ def shippable_gift_card_product(
return product
+def product_in_channel_JPY(product, channel_JPY, warehouse_JPY):
+ ProductChannelListing.objects.create(
+ product=product,
+ channel=channel_JPY,
+ is_published=True,
+ discounted_price_amount="1200",
+ currency=channel_JPY.currency_code,
+ visible_in_listings=True,
+ available_for_purchase=datetime.date(1999, 1, 1),
+ )
+ variant = product.variants.get()
+ ProductVariantChannelListing.objects.create(
+ variant=variant,
+ channel=channel_JPY,
+ price_amount=Decimal(1200),
+ cost_price_amount=Decimal(300),
+ currency=channel_JPY.currency_code,
+ )
+ Stock.objects.create(warehouse=warehouse_JPY, product_variant=variant, quantity=10)
+ return product
+
+
@pytest.fixture
def non_shippable_gift_card_product(
non_shippable_gift_card_product_type, category, warehouse, channel_USD
@@ -2947,6 +3016,33 @@ def gift_card_shippable_order_line(order, gift_card_shippable_variant, warehouse
return line
+def order_line_JPY(order_JPY, product_in_channel_JPY):
+ product = product_in_channel_JPY
+ variant = product_in_channel_JPY.variants.get()
+ channel = order_JPY.channel
+ channel_listing = variant.channel_listings.get(channel=channel)
+ net = variant.get_price(product, [], channel, channel_listing)
+ currency = net.currency
+ gross = Money(amount=net.amount * Decimal(1.23), currency=currency)
+ quantity = 3
+ unit_price = TaxedMoney(net=net, gross=gross)
+ return order_JPY.lines.create(
+ product_name=str(product),
+ variant_name=str(variant),
+ product_sku=variant.sku,
+ is_shipping_required=variant.is_shipping_required(),
+ is_gift_card=variant.is_gift_card(),
+ quantity=quantity,
+ variant=variant,
+ unit_price=unit_price,
+ total_price=unit_price * quantity,
+ undiscounted_unit_price=unit_price,
+ undiscounted_total_price=unit_price * quantity,
+ tax_rate=Decimal("0.23"),
+ )
+
+
@pytest.fixture
def order_line_with_allocation_in_many_stocks(
customer_user, variant_with_many_stocks, channel_USD
@@ -4968,6 +5064,19 @@ def warehouse(address, shipping_zone):
return warehouse
+def warehouse_JPY(address, shipping_zone_JPY):
+ warehouse = Warehouse.objects.create(
+ address=address,
+ name="Example Warehouse JPY",
+ slug="example-warehouse-jpy",
+ )
+ warehouse.shipping_zones.add(shipping_zone_JPY)
+ warehouse.save()
+ return warehouse
+
+
@pytest.fixture
def warehouses(address, address_usa):
return Warehouse.objects.bulk_create(