Skip to content

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

Fix calculating order price

Anna Siwikfb8c46fc71de
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 51e9a82e7d..52d225d5d7 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -457,7 +457,7 @@ def create_fake_order():
[line.get_total() for line in lines], delivery_group.shipping_price)
order.save()
- payment = create_payment(delivery_group)
+ create_payment(delivery_group)
return order
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 1c12ab16a8..c81e310711 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -248,9 +248,8 @@ class DeliveryGroup(models.Model, ItemSet):
def shipping_required(self):
return self.shipping_method_name is not None
- def get_total(self, **kwargs):
- subtotal = super(DeliveryGroup, self).get_total(**kwargs)
- return subtotal + self.shipping_price
+ def get_total_with_shipping(self, **kwargs):
+ return self.get_total() + self.shipping_price
def get_total_quantity(self):
return sum([line.get_quantity() for line in self])
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index 231b80db15..a541a95d8c 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -36,21 +36,14 @@ def cancel_order(order):
def recalculate_order(order):
"""Recalculates and assigns total price of order.
- Total price is a sum of items and shippings in order shipment groups. """
+ Total price is a sum of items and shippings in order shipment groups."""
prices = [
- group.get_total() for group in order
+ group.get_total_with_shipping() for group in order
if group.status != GroupStatus.CANCELLED]
total_net = sum(p.net for p in prices)
total_gross = sum(p.gross for p in prices)
- total = Price(
- net=total_net, gross=total_gross,
- currency=settings.DEFAULT_CURRENCY)
- shipping = [group.shipping_price for group in order]
- total_shipping = (
- sum(shipping[1:], shipping[0]) if shipping
- else Price(0, currency=settings.DEFAULT_CURRENCY))
- total += total_shipping
- order.total = total
+ order.total = Price(
+ net=total_net, gross=total_gross, currency=settings.DEFAULT_CURRENCY)
order.save()
@@ -64,8 +57,7 @@ def attach_order_to_user(order, user):
def fill_group_with_partition(group, partition, discounts=None):
- """Fills shipment group with order lines created from partition items.
- """
+ """Fills shipment group with order lines created from partition items."""
for item in partition:
add_variant_to_delivery_group(
group, item.variant, item.get_quantity(), discounts,