Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Get order lines directly in recalculate order
Anna Siwik7ef88d2faaa3
diff --git a/saleor/order/utils.py b/saleor/order/utils.pyindex 34378b6e16..42dad1935b 100644--- a/saleor/order/utils.py+++ b/saleor/order/utils.py@@ -5,6 +5,7 @@ from django.db.models import Ffrom django.shortcuts import get_object_or_404, redirectfrom prices import Money+from saleor.order.models import OrderLinefrom ..account.utils import store_user_addressfrom ..core.exceptions import InsufficientStockfrom ..dashboard.order.utils import get_voucher_discount_for_order@@ -59,11 +60,9 @@ def recalculate_order(order, **kwargs):Voucher discount amount is recalculated by default. To avoid this, passupdate_voucher_discount argument set to False."""- # do not use prefetched order lines, cause they might have changed- if hasattr(order, '_prefetched_objects_cache'):- order._prefetched_objects_cache.pop('lines', None)-- prices = [line.get_total() for line in order]+ # avoid using prefetched order lines+ lines = [OrderLine.objects.get(pk=line.pk) for line in order]+ prices = [line.get_total() for line in lines]total = sum(prices, order.shipping_price)# discount amount can't be greater than order totalorder.discount_amount = min(order.discount_amount, total.gross)