Skip to content

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

Remove order's get_total method

Anna Siwik2236e8a3c1ab
diff --git a/saleor/core/analytics.py b/saleor/core/analytics.py
index 01ef9daa25..be88dc3381 100644
--- a/saleor/core/analytics.py
+++ b/saleor/core/analytics.py
@@ -48,12 +48,12 @@ def report_view(client_id, path, language, headers):
def report_order(client_id, order):
for group in order:
- items = [ga.Item(oi.product_name,
- oi.get_price_per_item(),
- quantity=oi.quantity,
- item_id=oi.product_sku)
- for oi in group]
- trans = ga.Transaction('%s-%s' % (order.id, group.id), items,
- revenue=group.get_total(),
- shipping=group.order.shipping_price)
+ items = [
+ ga.Item(
+ ol.product_name, ol.get_price_per_item(), quantity=ol.quantity,
+ item_id=ol.product_sku)
+ for ol in group]
+ trans = ga.Transaction(
+ '%s-%s' % (order.id, group.id), items, revenue=group.get_total(),
+ shipping=group.order.shipping_price)
_report(client_id, trans, {})
diff --git a/saleor/order/models.py b/saleor/order/models.py
index d379cab499..80e62427d3 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -94,8 +94,7 @@ class Order(models.Model):
total_paid = sum(
[payment.total for payment in
self.payments.filter(status=PaymentStatus.CONFIRMED)], Decimal())
- total = self.get_total()
- return total_paid >= total.gross
+ return total_paid >= self.total.gross
def get_user_current_email(self):
return self.user.email if self.user else self.user_email
@@ -120,9 +119,6 @@ class Order(models.Model):
return FixedDiscount(
amount=self.discount_amount, name=self.discount_name)
- def get_total(self):
- return self.total
-
def get_absolute_url(self):
return reverse('order:details', kwargs={'token': self.token})
@@ -183,15 +179,9 @@ class Order(models.Model):
self.total_net = price
self.total_tax = Price(price.tax, currency=price.currency)
- def get_total(self):
- subtotals = [group.get_total() for group in self]
- if not subtotals:
- raise AttributeError('Calling get_total() on an empty order')
- return sum(subtotals[1:], subtotals[0])
-
def get_subtotal_without_voucher(self):
if self.get_lines():
- return self.get_total()
+ return self.total
return Price(net=0, currency=settings.DEFAULT_CURRENCY)
def can_cancel(self):
diff --git a/saleor/order/utils.py b/saleor/order/utils.py
index c054b6d89e..34e3e10a4d 100644
--- a/saleor/order/utils.py
+++ b/saleor/order/utils.py
@@ -40,9 +40,9 @@ def cancel_order(order):
def recalculate_order(order):
- """Recalculate and assigns total price of order.
+ """Recalculate and assign total price of order.
- Total price is a sum of items and shippings in order shipment groups.
+ Total price is a sum of items in shipment groups and order shipping price.
"""
prices = [
group.get_total() for group in order
diff --git a/templates/account/details.html b/templates/account/details.html
index 20f6b9e77d..c5d7c6f7df 100644
--- a/templates/account/details.html
+++ b/templates/account/details.html
@@ -76,7 +76,7 @@
{{ order.created }}
</div>
<div class="col-md-2 col-4">
- <span class="float-right">{% gross order.get_total html=True %}</span>
+ <span class="float-right">{% gross order.total html=True %}</span>
</div>
<div class="col-md-4 d-none d-md-block">
{% render_status order.status order.get_status_display %}
diff --git a/templates/dashboard/customer/detail.html b/templates/dashboard/customer/detail.html
index 9ab300e000..1294442aae 100644
--- a/templates/dashboard/customer/detail.html
+++ b/templates/dashboard/customer/detail.html
@@ -110,7 +110,7 @@
{% render_status order.status order.get_status_display %}
</td>
<td class="right-align">
- {% gross order.get_total html=True %}
+ {% gross order.total html=True %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/index.html b/templates/dashboard/index.html
index bbf3b4edc0..a88c642fcd 100644
--- a/templates/dashboard/index.html
+++ b/templates/dashboard/index.html
@@ -113,7 +113,7 @@
{% render_status order.get_last_payment_status order.get_last_payment_status_display %}
</td>
<td class="right-align">
- {% gross order.get_total html=True %}
+ {% gross order.total html=True %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/order/detail.html b/templates/dashboard/order/detail.html
index ae87f51af5..e67f89dbb9 100644
--- a/templates/dashboard/order/detail.html
+++ b/templates/dashboard/order/detail.html
@@ -384,7 +384,7 @@
{% trans "Grand total" context "Order totals header" %}
</td>
<td>
- {% gross order.get_total html=True %}
+ {% gross order.total html=True %}
</td>
</tr>
</tfoot>
diff --git a/templates/dashboard/order/list.html b/templates/dashboard/order/list.html
index 47e0de3fc7..59a22056d8 100644
--- a/templates/dashboard/order/list.html
+++ b/templates/dashboard/order/list.html
@@ -62,7 +62,7 @@
{% render_status order.get_last_payment_status order.get_last_payment_status_display %}
</td>
<td class="right-align">
- {% gross order.get_total html=True %}
+ {% gross order.total html=True %}
</td>
</tr>
{% endfor %}
diff --git a/templates/dashboard/order/modal/capture.html b/templates/dashboard/order/modal/capture.html
index c92b0d211f..1635e4bd60 100644
--- a/templates/dashboard/order/modal/capture.html
+++ b/templates/dashboard/order/modal/capture.html
@@ -19,7 +19,7 @@
{% trans "Before this action:" context "Modal capture payment title" %}
<ul class="list">
<li class="list-item">{% trans "Order total:" context "Modal capture payment list title" %}
- {% gross payment.order.get_total html=True %}
+ {% gross payment.order.total html=True %}
</li>
<li class="list-item">{% trans "Captured amount:" context "Modal capture payment list title" %}
{{ captured|currencyfmt:currency }}
diff --git a/templates/dashboard/order/modal/refund.html b/templates/dashboard/order/modal/refund.html
index c3f6d84b1c..2a4ab71555 100644
--- a/templates/dashboard/order/modal/refund.html
+++ b/templates/dashboard/order/modal/refund.html
@@ -20,7 +20,7 @@
{% trans "Before this action:" context "Modal refund payment title" %}
<ul class="list">
<li class="list-item">{% trans "Order total:" context "Modal refund payment list title" %}
- {% gross payment.order.get_total html=True %}
+ {% gross payment.order.total html=True %}
</li>
<li class="list-item">{% trans "Captured amount:" context "Modal refund payment list title" %}
{{ captured|currencyfmt:currency }}
diff --git a/templates/dashboard/order/pdf/invoice.html b/templates/dashboard/order/pdf/invoice.html
index 726b0dc9fa..9d241ecb41 100644
--- a/templates/dashboard/order/pdf/invoice.html
+++ b/templates/dashboard/order/pdf/invoice.html
@@ -151,7 +151,7 @@
{% trans "Grand total" context "Order total price header" %}
</td>
<td class="right-align">
- {% gross order.get_total html=True %}
+ {% gross order.total html=True %}
</td>
</tr>
</tfoot>
diff --git a/templates/templated_email/source/order/confirm_order.email b/templates/templated_email/source/order/confirm_order.email
index 02852b2f68..ff979c6fa8 100644
--- a/templates/templated_email/source/order/confirm_order.email
+++ b/templates/templated_email/source/order/confirm_order.email
@@ -17,7 +17,7 @@ Thank you for your order. Below is the list of ordered products. To see your pay
{% trans "Order summary" context "Order confirmation e-mail table header" %}:
{% trans "Subtotal" context "Order confirmation e-mail table header" %}: {% gross order.get_subtotal_without_voucher %}
{% trans "Shipping" context "Order confirmation e-mail table header" %}: {% gross order.shipping_price %}
-{% trans "Total" context "Order confirmation e-mail table header" %}: {% gross order.get_total %}
+{% trans "Total" context "Order confirmation e-mail table header" %}: {% gross order.total %}
{% trans "Billing address" context "Order confirmation e-mail billing address" %}
{{ order.billing_address }}
diff --git a/templates/templated_email/source/order/partials/_order_lines.mjml b/templates/templated_email/source/order/partials/_order_lines.mjml
index 67c4ca8a6e..2061d342fd 100644
--- a/templates/templated_email/source/order/partials/_order_lines.mjml
+++ b/templates/templated_email/source/order/partials/_order_lines.mjml
@@ -30,7 +30,7 @@
<strong>{% trans "Total" context "E-mail order lines summary table" %}</strong>
</td>
<td style="text-align: right;">
- <strong>{% gross order.get_total html=True %}</strong>
+ <strong>{% gross order.total html=True %}</strong>
</td>
</tr>
</tfoot>