Skip to content

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

Remove get_total_shipping from checkout

Anna Siwik6b55d8bfc113
diff --git a/saleor/checkout/core.py b/saleor/checkout/core.py
index 7c25028bb3..dc17705ad0 100644
--- a/saleor/checkout/core.py
+++ b/saleor/checkout/core.py
@@ -301,6 +301,7 @@ class Checkout:
'billing_address': billing_address,
'shipping_address': shipping_address,
'tracking_client_id': self.tracking_code,
+ 'shipping_price': self.shipping_method.get_total(),
'total': self.get_total()}
if self.user.is_authenticated:
@@ -320,14 +321,10 @@ class Checkout:
for partition in self.cart.partition():
shipping_required = partition.is_shipping_required()
- if shipping_required:
- shipping_price = self.shipping_method.get_total()
- shipping_method_name = smart_text(self.shipping_method)
- else:
- shipping_price = 0
- shipping_method_name = None
+ shipping_method_name = (
+ smart_text(self.shipping_method) if shipping_required else None
+ )
group = order.groups.create(
- shipping_price=shipping_price,
shipping_method_name=shipping_method_name)
fill_group_with_partition(
group, partition, discounts=self.cart.discounts)
@@ -382,15 +379,6 @@ class Checkout:
total = sum(cost_iterator, zero)
return total if self.discount is None else self.discount.apply(total)
- def get_total_shipping(self):
- """Calculate shipping total."""
- zero = Price(0, currency=settings.DEFAULT_CURRENCY)
- cost_iterator = (
- shipping_cost
- for shipment, shipping_cost, total in self.deliveries)
- total = sum(cost_iterator, zero)
- return total
-
def load_checkout(view):
"""Decorate view with checkout session and cart for each request.
diff --git a/saleor/dashboard/order/utils.py b/saleor/dashboard/order/utils.py
index 60b9d48400..d2fb37a3b8 100644
--- a/saleor/dashboard/order/utils.py
+++ b/saleor/dashboard/order/utils.py
@@ -30,8 +30,7 @@ def create_invoice_pdf(order_pk, absolute_url):
'user', 'shipping_address', 'billing_address', 'voucher',
'groups').get(pk=order_pk))
shipping_methods = [
- {'name': d.shipping_method_name,
- 'price': d.shipping_price} for d in order.groups.all()]
+ {'name': d.shipping_method_name} for d in order.groups.all()]
ctx = {'order': order, 'shipping_methods': shipping_methods}
rendered_template = get_template(INVOICE_TEMPLATE).render(ctx)
pdf_file = _create_pdf(rendered_template, absolute_url)
diff --git a/templates/checkout/details.html b/templates/checkout/details.html
index 35bd40240c..5f0d2490d4 100644
--- a/templates/checkout/details.html
+++ b/templates/checkout/details.html
@@ -51,7 +51,7 @@
</div>
<div class="col-4">
<p class="float-right">{% if checkout.shipping_method %}
- {% net checkout.get_total_shipping %}
+ {% net checkout.shipping_method.get_total %}
{% else %}
&mdash;
{% endif %}</p>
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 6a180c7ad6..699860897c 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -99,13 +99,11 @@
{% if order.shipping_price.gross or order.is_shipping_required %}
{% for shipping in shipping_methods %}
<tr>
- <td colspan="4">
- {% blocktrans trimmed with shipping_name=shipping.name context "Shipment order table item column data" %}
- Shipping ({{ shipping_name }})
- {% endblocktrans %}
+ <td>
+ {% trans "Shipping" context "Shipment order table item column data" %}
</td>
- <td class="right-align">
- {% gross shipping.price html=True %}
+ <td colspan="3">
+ {{ shipping.name }}
</td>
</tr>
{% endfor %}
@@ -126,10 +124,10 @@
</tr>
<tr>
<td>
- {% trans "Total Shipping Price" context "Order total shipping price header" %}
+ {% trans "Shipping total" context "Order total shipping price header" %}
</td>
<td class="right-align">
- {% gross order.get_total_shipping html=True %}
+ {% gross order.shipping_price html=True %}
</td>
</tr>
{% if order.voucher %}
diff --git a/templates/order/success.html b/templates/order/success.html
index ad31273ae9..a720d1d2bc 100644
--- a/templates/order/success.html
+++ b/templates/order/success.html
@@ -20,7 +20,7 @@
'id': '{{ order.id }}',
'affiliation': 'Saleor',
'revenue': '{{ order.get_total.gross }}',
- 'shipping': '{{ order.get_delivery_total.gross }}',
+ 'shipping': '{{ order.shipping_price.gross }}',
'tax': '{{ order.get_total.tax }}'
});
{% for item in order.get_lines %}