Skip to content

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

SALEOR-4420 missing quantization in webhooks (#8463)

Paweł Kucharskif383043e4be3
diff --git a/saleor/core/prices.py b/saleor/core/prices.py
index 5739efcb06..a68bf3c256 100644
--- a/saleor/core/prices.py
+++ b/saleor/core/prices.py
@@ -1,15 +1,23 @@
from decimal import Decimal
-from typing import TYPE_CHECKING, Union
+from typing import TYPE_CHECKING, Iterable, Union
from babel.numbers import get_currency_precision
if TYPE_CHECKING:
+ from django.db.models import Model
from prices import Money, TaxedMoney, TaxedMoneyRange
+MoneyTypes = Union["TaxedMoney", "Money", Decimal, "TaxedMoneyRange"]
-def quantize_price(
- price: Union["TaxedMoney", "Money", Decimal, "TaxedMoneyRange"], currency: str
-) -> Union["TaxedMoney", "Money", Decimal, "TaxedMoneyRange"]:
+
+def quantize_price(price: MoneyTypes, currency: str) -> MoneyTypes:
precision = get_currency_precision(currency)
number_places = Decimal(10) ** -precision
return price.quantize(number_places)
+
+
+def quantize_price_fields(model: "Model", fields: Iterable[str], currency: str) -> None:
+ for field in fields:
+ setattr(
+ model, field, quantize_price(getattr(model, field) or Decimal(0), currency)
+ )
diff --git a/saleor/order/notifications.py b/saleor/order/notifications.py
index 410ad5c550..202c4c9195 100644
--- a/saleor/order/notifications.py
+++ b/saleor/order/notifications.py
@@ -1,3 +1,4 @@
+from decimal import Decimal
from typing import TYPE_CHECKING, Iterable, List, Optional
from urllib.parse import urlencode
@@ -6,6 +7,7 @@ from django.forms import model_to_dict
from ..account.models import StaffNotificationRecipient
from ..core.notification.utils import get_site_context
from ..core.notify_events import NotifyEventType
+from ..core.prices import quantize_price, quantize_price_fields
from ..core.utils.url import prepare_url
from ..discount import OrderDiscountType
from ..product import ProductMediaTypes
@@ -14,8 +16,6 @@ from ..product.product_images import AVAILABLE_PRODUCT_SIZES, get_thumbnail
from .models import FulfillmentLine, Order, OrderLine
if TYPE_CHECKING:
- from decimal import Decimal
-
from ..account.models import User # noqa: F401
from ..app.models import App
@@ -100,6 +100,8 @@ def get_order_line_payload(line: "OrderLine"):
"product": get_product_payload(line.variant.product),
"variant": get_product_variant_payload(line.variant),
}
+ currency = line.currency
+
return {
"id": line.id,
"product": variant_dependent_fields.get("product"), # type: ignore
@@ -112,13 +114,15 @@ def get_order_line_payload(line: "OrderLine"):
"product_variant_id": line.product_variant_id,
"quantity": line.quantity,
"quantity_fulfilled": line.quantity_fulfilled,
- "currency": line.currency,
- "unit_price_net_amount": line.unit_price.net.amount,
- "unit_price_gross_amount": line.unit_price.gross.amount,
- "unit_tax_amount": line.unit_price.tax.amount,
- "total_gross_amount": line.total_price.gross.amount,
- "total_net_amount": line.total_price.net.amount,
- "total_tax_amount": line.total_price.tax.amount,
+ "currency": currency,
+ "unit_price_net_amount": quantize_price(line.unit_price.net.amount, currency),
+ "unit_price_gross_amount": quantize_price(
+ line.unit_price.gross.amount, currency
+ ),
+ "unit_tax_amount": quantize_price(line.unit_price.tax.amount, currency),
+ "total_gross_amount": quantize_price(line.total_price.gross.amount, currency),
+ "total_net_amount": quantize_price(line.total_price.net.amount, currency),
+ "total_tax_amount": quantize_price(line.total_price.tax.amount, currency),
"tax_rate": line.tax_rate,
"is_shipping_required": line.is_shipping_required,
"is_digital": line.is_digital,
@@ -193,7 +197,6 @@ ORDER_MODEL_FIELDS = [
"token",
"display_gross_prices",
"currency",
- "discount_amount",
"total_gross_amount",
"total_net_amount",
"undiscounted_total_gross_amount",
@@ -205,6 +208,13 @@ ORDER_MODEL_FIELDS = [
"language_code",
]
+ORDER_PRICE_FIELDS = [
+ "total_gross_amount",
+ "total_net_amount",
+ "undiscounted_total_gross_amount",
+ "undiscounted_total_net_amount",
+]
+
def get_custom_order_payload(order: Order):
payload = {
@@ -220,7 +230,7 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
if redirect_url:
order_details_url = prepare_order_details_url(order, redirect_url)
subtotal = order.get_subtotal()
- tax = order.total_gross_amount - order.total_net_amount
+ tax = order.total_gross_amount - order.total_net_amount or Decimal(0)
lines = order.lines.prefetch_related(
"variant__product__media",
@@ -228,6 +238,8 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
"variant__product__attributes__assignment__attribute",
"variant__product__attributes__values",
).all()
+ currency = order.currency
+ quantize_price_fields(order, fields=ORDER_PRICE_FIELDS, currency=currency)
order_payload = model_to_dict(order, fields=ORDER_MODEL_FIELDS)
order_payload.update(
{
@@ -238,9 +250,9 @@ def get_default_order_payload(order: "Order", redirect_url: str = ""):
"shipping_price_gross_amount": order.shipping_price_gross_amount,
"order_details_url": order_details_url,
"email": order.get_customer_email(),
- "subtotal_gross_amount": subtotal.gross.amount,
- "subtotal_net_amount": subtotal.net.amount,
- "tax_amount": tax,
+ "subtotal_gross_amount": quantize_price(subtotal.gross.amount, currency),
+ "subtotal_net_amount": quantize_price(subtotal.net.amount, currency),
+ "tax_amount": quantize_price(tax, currency),
"lines": get_lines_payload(lines),
"billing_address": get_address_payload(order.billing_address),
"shipping_address": get_address_payload(order.shipping_address),
@@ -350,6 +362,7 @@ def send_fulfillment_update(order, fulfillment, manager):
def send_payment_confirmation(order, manager):
"""Send notification with the payment confirmation."""
payment = order.get_last_payment()
+ payment_currency = payment.currency
payload = {
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
@@ -357,9 +370,11 @@ def send_payment_confirmation(order, manager):
"created": payment.created,
"modified": payment.modified,
"charge_status": payment.charge_status,
- "total": payment.total,
- "captured_amount": payment.captured_amount,
- "currency": payment.currency,
+ "total": quantize_price(payment.total, payment_currency),
+ "captured_amount": quantize_price(
+ payment.captured_amount, payment_currency
+ ),
+ "currency": payment_currency,
},
**get_site_context(),
}
@@ -395,7 +410,7 @@ def send_order_refunded_confirmation(
payload = {
"order": get_default_order_payload(order),
"recipient_email": order.get_customer_email(),
- "amount": amount,
+ "amount": quantize_price(amount, currency),
"currency": currency,
**get_site_context(),
}
diff --git a/saleor/order/tests/test_notifications.py b/saleor/order/tests/test_notifications.py
index f455dc3b01..9b97f2f30e 100644
--- a/saleor/order/tests/test_notifications.py
+++ b/saleor/order/tests/test_notifications.py
@@ -6,6 +6,7 @@ from measurement.measures import Weight
from prices import Money, fixed_discount
from ...core.notify_events import NotifyEventType
+from ...core.prices import quantize_price
from ...discount import DiscountValueType
from ...order import notifications
from ...plugins.manager import get_plugins_manager
@@ -120,6 +121,7 @@ def test_get_order_line_payload(order_line):
total_gross = order_line.unit_price_gross * order_line.quantity
total_net = order_line.unit_price_net * order_line.quantity
total_tax = total_gross - total_net
+ currency = order_line.currency
assert payload == {
"variant": {
"id": order_line.variant_id,
@@ -150,12 +152,16 @@ def test_get_order_line_payload(order_line):
"quantity": order_line.quantity,
"quantity_fulfilled": order_line.quantity_fulfilled,
"currency": order_line.currency,
- "unit_price_net_amount": order_line.unit_price_net_amount,
- "unit_price_gross_amount": order_line.unit_price_gross_amount,
- "unit_tax_amount": unit_tax_amount,
- "total_gross_amount": total_gross.amount,
- "total_net_amount": total_net.amount,
- "total_tax_amount": total_tax.amount,
+ "unit_price_net_amount": quantize_price(
+ order_line.unit_price_net_amount, currency
+ ),
+ "unit_price_gross_amount": quantize_price(
+ order_line.unit_price_gross_amount, currency
+ ),
+ "unit_tax_amount": quantize_price(unit_tax_amount, currency),
+ "total_gross_amount": quantize_price(total_gross.amount, currency),
+ "total_net_amount": quantize_price(total_net.amount, currency),
+ "total_tax_amount": quantize_price(total_tax.amount, currency),
"tax_rate": order_line.tax_rate,
"is_digital": order_line.is_digital,
"digital_url": "",
diff --git a/saleor/webhook/payloads.py b/saleor/webhook/payloads.py
index 1a982bf1b1..6c27c67bf2 100644
--- a/saleor/webhook/payloads.py
+++ b/saleor/webhook/payloads.py
@@ -9,6 +9,7 @@ from django.db.models import F, QuerySet, Sum
from ..attribute.models import AttributeValueTranslation
from ..checkout.models import Checkout
+from ..core.prices import quantize_price, quantize_price_fields
from ..core.utils import build_absolute_uri
from ..core.utils.anonymization import (
anonymize_checkout,
@@ -70,13 +71,20 @@ ORDER_FIELDS = (
"shipping_price_net_amount",
"shipping_price_gross_amount",
"shipping_tax_rate",
+ "weight",
+ "private_metadata",
+ "metadata",
"total_net_amount",
"total_gross_amount",
+ "undiscounted_total_net_amount",
+ "undiscounted_total_gross_amount",
+)
+
+ORDER_PRICE_FIELDS = (
"shipping_price_net_amount",
"shipping_price_gross_amount",
- "weight",
- "private_metadata",
- "metadata",
+ "total_net_amount",
+ "total_gross_amount",
"undiscounted_total_net_amount",
"undiscounted_total_gross_amount",
)
@@ -118,6 +126,21 @@ def generate_order_lines_payload(lines: Iterable[OrderLine]):
"undiscounted_total_price_gross_amount",
"tax_rate",
)
+ line_price_fields = (
+ "unit_price_gross_amount",
+ "unit_price_net_amount",
+ "unit_discount_amount",
+ "total_price_net_amount",
+ "total_price_gross_amount",
+ "undiscounted_unit_price_net_amount",
+ "undiscounted_unit_price_gross_amount",
+ "undiscounted_total_price_net_amount",
+ "undiscounted_total_price_gross_amount",
+ )
+
+ for line in lines:
+ quantize_price_fields(line, line_price_fields, line.currency)
+
serializer = PayloadSerializer()
return serializer.serialize(
lines,
@@ -156,6 +179,7 @@ def generate_order_payload(order: "Order"):
"shipping_refund_amount",
"total_refund_amount",
)
+ fulfillment_price_fields = ("shipping_refund_amount", "total_refund_amount")
payment_fields = (
"gateway",
"payment_method_type",
@@ -180,7 +204,7 @@ def generate_order_payload(order: "Order"):
"billing_country_code",
"billing_country_area",
)
-
+ payment_price_fields = ("captured_amount", "total")
discount_fields = (
"type",
"value_type",
@@ -190,29 +214,45 @@ def generate_order_payload(order: "Order"):
"translated_name",
"reason",
)
+ discount_price_fields = ("amount_value",)
channel_fields = ("slug", "currency_code")
shipping_method_fields = ("name", "type", "currency", "price_amount")
lines = order.lines.all()
+ fulfillments = order.fulfillments.all()
+ payments = order.payments.all()
+ discounts = order.discounts.all()
+
+ quantize_price_fields(order, ORDER_PRICE_FIELDS, order.currency)
+
+ for fulfillment in fulfillments:
+ quantize_price_fields(fulfillment, fulfillment_price_fields, order.currency)
+
+ for payment in payments:
+ quantize_price_fields(payment, payment_price_fields, order.currency)
+
+ for discount in discounts:
+ quantize_price_fields(discount, discount_price_fields, order.currency)
fulfillments_data = serializer.serialize(
- order.fulfillments.all(),
+ fulfillments,
fields=fulfillment_fields,
extra_dict_data={
"lines": lambda f: json.loads(generate_fulfillment_lines_payload(f))
},
)
+
order_data = serializer.serialize(
[order],
fields=ORDER_FIELDS,
additional_fields={
"channel": (lambda o: o.channel, channel_fields),
"shipping_method": (lambda o: o.shipping_method, shipping_method_fields),
- "payments": (lambda o: o.payments.all(), payment_fields),
+ "payments": (lambda _: payments, payment_fields),
"shipping_address": (lambda o: o.shipping_address, ADDRESS_FIELDS),
"billing_address": (lambda o: o.billing_address, ADDRESS_FIELDS),
- "discounts": (lambda o: o.discounts.all(), discount_fields),
+ "discounts": (lambda _: discounts, discount_fields),
},
extra_dict_data={
"original": graphene.Node.to_global_id("Order", order.original_id),
@@ -292,6 +332,8 @@ def generate_sale_payload(
def generate_invoice_payload(invoice: "Invoice"):
serializer = PayloadSerializer()
invoice_fields = ("id", "number", "external_url", "created")
+ if invoice.order is not None:
+ quantize_price_fields(invoice.order, ORDER_PRICE_FIELDS, invoice.order.currency)
return serializer.serialize(
[invoice],
fields=invoice_fields,
@@ -314,6 +356,9 @@ def generate_checkout_payload(checkout: "Checkout"):
"metadata",
"channel",
)
+
+ checkout_price_fields = ("discount_amount",)
+ quantize_price_fields(checkout, checkout_price_fields, checkout.currency)
user_fields = ("email", "first_name", "last_name")
shipping_method_fields = ("name", "type", "currency", "price_amount")
lines_dict_data = serialize_checkout_lines(checkout)
@@ -564,20 +609,36 @@ def generate_fulfillment_lines_payload(fulfillment: Fulfillment):
if fl.order_line.variant
else None
),
- "unit_price_net": lambda fl: fl.order_line.unit_price_net_amount,
- "unit_price_gross": lambda fl: fl.order_line.unit_price_gross_amount,
+ "unit_price_net": lambda fl: quantize_price(
+ fl.order_line.unit_price_net_amount, fl.order_line.currency
+ ),
+ "unit_price_gross": lambda fl: quantize_price(
+ fl.order_line.unit_price_gross_amount, fl.order_line.currency
+ ),
"undiscounted_unit_price_net": (
- lambda fl: fl.order_line.undiscounted_unit_price.net.amount
+ lambda fl: quantize_price(
+ fl.order_line.undiscounted_unit_price.net.amount,
+ fl.order_line.currency,
+ )
),
"undiscounted_unit_price_gross": (
- lambda fl: fl.order_line.undiscounted_unit_price.gross.amount
+ lambda fl: quantize_price(
+ fl.order_line.undiscounted_unit_price.gross.amount,
+ fl.order_line.currency,
+ )
),
"total_price_net_amount": (
- lambda fl: fl.order_line.undiscounted_unit_price.net.amount
+ lambda fl: quantize_price(
+ fl.order_line.undiscounted_unit_price.net.amount,
+ fl.order_line.currency,
+ )
* fl.quantity
),
"total_price_gross_amount": (
- lambda fl: fl.order_line.undiscounted_unit_price.gross.amount
+ lambda fl: quantize_price(
+ fl.order_line.undiscounted_unit_price.gross.amount,
+ fl.order_line.currency,
+ )
* fl.quantity
),
"currency": lambda fl: fl.order_line.currency,
@@ -601,8 +662,15 @@ def generate_fulfillment_payload(fulfillment: Fulfillment):
"shipping_refund_amount",
"total_refund_amount",
)
+ fulfillment_price_fields = (
+ "shipping_refund_amount",
+ "total_refund_amount",
+ )
order = fulfillment.order
order_country = get_order_country(order)
+ quantize_price_fields(
+ fulfillment, fulfillment_price_fields, fulfillment.order.currency
+ )
fulfillment_line = fulfillment.lines.first()
if fulfillment_line and fulfillment_line.stock:
warehouse = fulfillment_line.stock.warehouse
@@ -642,6 +710,7 @@ def generate_page_payload(page: Page):
def generate_payment_payload(payment_data: "PaymentData"):
data = asdict(payment_data)
+ data["amount"] = quantize_price(data["amount"], data["currency"])
payment_app_data = from_payment_app_id(data["gateway"])
if payment_app_data:
data["payment_method"] = payment_app_data.name
diff --git a/saleor/webhook/serializers.py b/saleor/webhook/serializers.py
index fc012dd7b3..12f49368ac 100644
--- a/saleor/webhook/serializers.py
+++ b/saleor/webhook/serializers.py
@@ -5,6 +5,7 @@ import graphene
from ..attribute import AttributeInputType
from ..checkout.fetch import fetch_checkout_lines
+from ..core.prices import quantize_price
from ..product.models import Product
if TYPE_CHECKING:
@@ -16,6 +17,7 @@ if TYPE_CHECKING:
def serialize_checkout_lines(checkout: "Checkout") -> List[dict]:
data = []
channel = checkout.channel
+ currency = channel.currency_code
for line_info in fetch_checkout_lines(checkout):
variant = line_info.variant
channel_listing = line_info.channel_listing
@@ -27,8 +29,8 @@ def serialize_checkout_lines(checkout: "Checkout") -> List[dict]:
"sku": variant.sku,
"variant_id": variant.get_global_id(),
"quantity": line_info.line.quantity,
- "base_price": str(base_price.amount),
- "currency": channel.currency_code,
+ "base_price": str(quantize_price(base_price.amount, currency)),
+ "currency": currency,
"full_name": variant.display_product(),
"product_name": product.name,
"variant_name": variant.name,
diff --git a/saleor/webhook/tests/test_webhook_payloads.py b/saleor/webhook/tests/test_webhook_payloads.py
index 38d6ce1a67..3176808af7 100644
--- a/saleor/webhook/tests/test_webhook_payloads.py
+++ b/saleor/webhook/tests/test_webhook_payloads.py
@@ -103,9 +103,11 @@ def test_generate_order_payload(
"modified": ANY,
"charge_status": payment_txn_captured.charge_status,
"psp_reference": payment_txn_captured.psp_reference,
- "total": str(payment_txn_captured.total),
+ "total": str(payment_txn_captured.total.quantize(Decimal("0.01"))),
"type": "Payment",
- "captured_amount": str(payment_txn_captured.captured_amount),
+ "captured_amount": str(
+ payment_txn_captured.captured_amount.quantize(Decimal("0.01"))
+ ),
"currency": payment_txn_captured.currency,
"billing_email": payment_txn_captured.billing_email,
"billing_first_name": payment_txn_captured.billing_first_name,
@@ -137,6 +139,15 @@ def test_generate_fulfillment_lines_payload(order_with_lines):
)
payload = json.loads(generate_fulfillment_lines_payload(fulfillment))[0]
+ undiscounted_unit_price_gross = line.undiscounted_unit_price.gross.amount.quantize(
+ Decimal("0.01")
+ )
+ undiscounted_unit_price_net = line.undiscounted_unit_price.net.amount.quantize(
+ Decimal("0.01")
+ )
+ unit_price_gross = line.unit_price.gross.amount.quantize(Decimal("0.01"))
+ unit_price_net = line.unit_price.net.amount.quantize(Decimal("0.01"))
+
assert payload == {
"currency": "USD",
"product_name": line.product_name,
@@ -146,17 +157,13 @@ def test_generate_fulfillment_lines_payload(order_with_lines):
"id": graphene.Node.to_global_id("FulfillmentLine", fulfillment_line.id),
"product_type": "Default Type",
"quantity": fulfillment_line.quantity,
- "total_price_gross_amount": str(
- line.unit_price.gross.amount * fulfillment_line.quantity
- ),
- "total_price_net_amount": str(
- line.unit_price.net.amount * fulfillment_line.quantity
- ),
+ "total_price_gross_amount": str(unit_price_gross * fulfillment_line.quantity),
+ "total_price_net_amount": str(unit_price_net * fulfillment_line.quantity),
"type": "FulfillmentLine",
- "undiscounted_unit_price_gross": str(line.undiscounted_unit_price.gross.amount),
- "undiscounted_unit_price_net": str(line.undiscounted_unit_price.net.amount),
- "unit_price_gross": str(line.unit_price.gross.amount),
- "unit_price_net": str(line.unit_price.net.amount),
+ "undiscounted_unit_price_gross": str(undiscounted_unit_price_gross),
+ "undiscounted_unit_price_net": str(undiscounted_unit_price_net),
+ "unit_price_gross": str(unit_price_gross),
+ "unit_price_net": str(unit_price_net),
"weight": 0.0,
"weight_unit": "gram",
"warehouse_id": graphene.Node.to_global_id(
@@ -201,21 +208,21 @@ def test_order_lines_have_all_required_fields(order, order_line_with_one_allocat
assert len(lines_payload) == 1
line_id = graphene.Node.to_global_id("OrderLine", line.id)
line_payload = lines_payload[0]
- unit_net_amount = line.unit_price_net_amount.quantize(Decimal("0.001"))
- unit_gross_amount = line.unit_price_gross_amount.quantize(Decimal("0.001"))
- unit_discount_amount = line.unit_discount_amount.quantize(Decimal("0.001"))
+ unit_net_amount = line.unit_price_net_amount.quantize(Decimal("0.01"))
+ unit_gross_amount = line.unit_price_gross_amount.quantize(Decimal("0.01"))
+ unit_discount_amount = line.unit_discount_amount.quantize(Decimal("0.01"))
allocation = line.allocations.first()
undiscounted_unit_price_net_amount = (
- line.undiscounted_unit_price.net.amount.quantize(Decimal("0.001"))
+ line.undiscounted_unit_price.net.amount.quantize(Decimal("0.01"))
)
undiscounted_unit_price_gross_amount = (
- line.undiscounted_unit_price.gross.amount.quantize(Decimal("0.001"))
+ line.undiscounted_unit_price.gross.amount.quantize(Decimal("0.01"))
)
undiscounted_total_price_net_amount = (
- line.undiscounted_total_price.net.amount.quantize(Decimal("0.001"))
+ line.undiscounted_total_price.net.amount.quantize(Decimal("0.01"))
)
undiscounted_total_price_gross_amount = (
- line.undiscounted_total_price.gross.amount.quantize(Decimal("0.001"))
+ line.undiscounted_total_price.gross.amount.quantize(Decimal("0.01"))
)
total_line = line.total_price
@@ -238,9 +245,9 @@ def test_order_lines_have_all_required_fields(order, order_line_with_one_allocat
"unit_discount_reason": line.unit_discount_reason,
"unit_price_net_amount": str(unit_net_amount),
"unit_price_gross_amount": str(unit_gross_amount),
- "total_price_net_amount": str(total_line.net.amount.quantize(Decimal("0.001"))),
+ "total_price_net_amount": str(total_line.net.amount.quantize(Decimal("0.01"))),
"total_price_gross_amount": str(
- total_line.gross.amount.quantize(Decimal("0.001"))
+ total_line.gross.amount.quantize(Decimal("0.01"))
),
"tax_rate": str(line.tax_rate.quantize(Decimal("0.0001"))),
"allocations": [
@@ -454,7 +461,12 @@ def test_generate_invoice_payload(fulfilled_order):
fulfilled_order.save(update_fields=["origin"])
invoice = fulfilled_order.invoices.first()
payload = json.loads(generate_invoice_payload(invoice))[0]
-
+ undiscounted_total_net = fulfilled_order.undiscounted_total_net_amount.quantize(
+ Decimal("0.01")
+ )
+ undiscounted_total_gross = fulfilled_order.undiscounted_total_gross_amount.quantize(
+ Decimal("0.01")
+ )
assert payload == {
"type": "Invoice",
"id": graphene.Node.to_global_id("Invoice", invoice.id),
@@ -469,18 +481,14 @@ def test_generate_invoice_payload(fulfilled_order):
"user_email": "[email protected]",
"shipping_method_name": "DHL",
"collection_point_name": None,
- "shipping_price_net_amount": "10.000",
- "shipping_price_gross_amount": "12.300",
+ "shipping_price_net_amount": "10.00",
+ "shipping_price_gross_amount": "12.30",
"shipping_tax_rate": "0.0000",
- "total_net_amount": "80.000",
- "total_gross_amount": "98.400",
+ "total_net_amount": "80.00",
+ "total_gross_amount": "98.40",
"weight": "0.0:g",
- "undiscounted_total_net_amount": str(
- fulfilled_order.undiscounted_total_net_amount
- ),
- "undiscounted_total_gross_amount": str(
- fulfilled_order.undiscounted_total_gross_amount
- ),
+ "undiscounted_total_net_amount": str(undiscounted_total_net),
+ "undiscounted_total_gross_amount": str(undiscounted_total_gross),
},
"number": "01/12/2020/TEST",
"created": ANY,
@@ -499,6 +507,9 @@ def test_generate_list_gateways_payload(checkout):
def test_generate_payment_payload(dummy_webhook_app_payment_data):
payload = generate_payment_payload(dummy_webhook_app_payment_data)
expected_payload = asdict(dummy_webhook_app_payment_data)
+ expected_payload["amount"] = Decimal(expected_payload["amount"]).quantize(
+ Decimal("0.01")
+ )
expected_payload["payment_method"] = from_payment_app_id(
dummy_webhook_app_payment_data.gateway
).name
diff --git a/saleor/webhook/tests/test_webhook_sample_payloads.py b/saleor/webhook/tests/test_webhook_sample_payloads.py
index e8464bb7c0..58df0cdf1e 100644
--- a/saleor/webhook/tests/test_webhook_sample_payloads.py
+++ b/saleor/webhook/tests/test_webhook_sample_payloads.py
@@ -46,7 +46,7 @@ def test_generate_sample_payload_order(
order_id = graphene.Node.to_global_id("Order", order.id)
payload = generate_sample_payload(event_name)
- order_payload = json.loads(generate_order_payload(fulfilled_order))
+ order_payload = json.loads(generate_order_payload(order))
# Check anonymized data differ
assert order_id == payload[0]["id"]
assert order.user_email != payload[0]["user_email"]