Skip to content

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

Revert "Use total_net and total_tax fields instead of calculating order total on demand"

Artur Smętda78c615b74c
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.py
index fa925ef30b..ba73d6b794 100644
--- a/saleor/dashboard/order/views.py
+++ b/saleor/dashboard/order/views.py
@@ -41,7 +41,7 @@ def order_details(request, order_pk):
all_payments = order.payments.all()
payment = order.payments.last()
groups = list(order)
- captured = preauthorized = Price(0, currency=order.total.currency)
+ captured = preauthorized = Price(0, currency=order.get_total().currency)
if payment:
can_capture = (payment.status == 'preauth' and
order.status != 'cancelled')
@@ -83,7 +83,7 @@ def order_add_note(request, order_pk):
def capture_payment(request, order_pk, payment_pk):
order = get_object_or_404(Order, pk=order_pk)
payment = get_object_or_404(order.payments, pk=payment_pk)
- amount = order.total.quantize('0.01').gross
+ amount = order.get_total().quantize('0.01').gross
form = CapturePaymentForm(request.POST or None, payment=payment,
initial={'amount': amount})
if form.is_valid() and form.capture():
diff --git a/saleor/order/admin.py b/saleor/order/admin.py
index 3982baeb56..3ba17484bb 100644
--- a/saleor/order/admin.py
+++ b/saleor/order/admin.py
@@ -94,7 +94,7 @@ class OrderAdmin(OrderModelAdmin):
customer.allow_tags = True
def total(self, obj):
- total = obj.total
+ total = obj.get_total()
return '%s %s' % (total.gross, total.currency)
total.short_description = 'Total'
diff --git a/saleor/order/models.py b/saleor/order/models.py
index 27be32bc65..bb43ddb9c9 100644
--- a/saleor/order/models.py
+++ b/saleor/order/models.py
@@ -93,7 +93,7 @@ class Order(models.Model, ItemSet):
def is_fully_paid(self):
total_paid = sum([payment.total for payment in
self.payments.filter(status='confirmed')], Decimal())
- total = self.total
+ total = self.get_total()
return total_paid >= total.gross
def get_user_email(self):
@@ -111,8 +111,10 @@ class Order(models.Model, ItemSet):
return '#%d' % (self.id, )
def get_total(self):
- # For backwards compatibility
- return self.total
+ try:
+ return super(Order, self).get_total()
+ except AttributeError:
+ return Price(0, currency=settings.DEFAULT_CURRENCY)
@property
def billing_full_name(self):
diff --git a/saleor/order/views.py b/saleor/order/views.py
index dc6b024fae..7cc0c34e01 100644
--- a/saleor/order/views.py
+++ b/saleor/order/views.py
@@ -63,7 +63,7 @@ def start_payment(request, order, variant):
if waiting_payments:
return redirect('order:payment', token=order.token)
billing = order.billing_address
- total = order.total
+ total = order.get_total()
defaults = {'total': total.gross,
'tax': total.tax, 'currency': total.currency,
'delivery': order.get_delivery_total().gross,