Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add TotalPrice to OrderLine
fowczrek135752c62fa4
diff --git a/saleor/graphql/order/tests/test_order.py b/saleor/graphql/order/tests/test_order.pyindex 9dbd5186d0..909394852a 100644--- a/saleor/graphql/order/tests/test_order.py+++ b/saleor/graphql/order/tests/test_order.py@@ -100,6 +100,19 @@ def test_orderline_query(staff_api_client, permission_manage_orders, fulfilled_ovariant {id}+ quantity+ unitPrice {+ currency+ gross {+ amount+ }+ }+ totalPrice {+ currency+ gross {+ amount+ }+ }}}}@@ -116,6 +129,19 @@ def test_orderline_query(staff_api_client, permission_manage_orders, fulfilled_oassert order_data["lines"][0]["thumbnail"] is Nonevariant_id = graphene.Node.to_global_id("ProductVariant", line.variant.pk)assert order_data["lines"][0]["variant"]["id"] == variant_id+ assert order_data["lines"][0]["quantity"] == line.quantity+ assert order_data["lines"][0]["unitPrice"]["currency"] == line.unit_price.currency+ expected_unit_price = Money(+ amount=str(order_data["lines"][0]["unitPrice"]["gross"]["amount"]),+ currency="USD",+ )+ assert order_data["lines"][0]["totalPrice"]["currency"] == line.unit_price.currency+ assert expected_unit_price == line.unit_price.gross+ expected_total_price = Money(+ amount=str(order_data["lines"][0]["totalPrice"]["gross"]["amount"]),+ currency="USD",+ )+ assert expected_total_price == line.unit_price.gross * line.quantitydef test_order_query(diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 558aeb57f5..a2e57ebd07 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -240,6 +240,7 @@ class OrderLine(CountableDjangoObjectType):unit_price = graphene.Field(TaxedMoney, description="Price of the single item in the order line.")+ total_price = graphene.Field(TaxedMoney, description="Price of the order line.",)variant = graphene.Field(ProductVariant,required=False,@@ -286,6 +287,10 @@ class OrderLine(CountableDjangoObjectType):def resolve_unit_price(root: models.OrderLine, _info):return root.unit_price+ @staticmethod+ def resolve_total_price(root: models.OrderLine, _info):+ return root.unit_price * root.quantity+@staticmethoddef resolve_translated_product_name(root: models.OrderLine, _info):return root.translated_product_namediff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex d5f75c8911..9826065e05 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3123,6 +3123,7 @@ type OrderLine implements Node {digitalContentUrl: DigitalContentUrlthumbnail(size: Int): ImageunitPrice: TaxedMoney+ totalPrice: TaxedMoneyvariant: ProductVarianttranslatedProductName: String!translatedVariantName: String!