Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Keep full order history
Marcin Gębalac4fb1c264151
diff --git a/saleor/dashboard/order/views.py b/saleor/dashboard/order/views.pyindex d8f34ab1d7..4fa01dda70 100644--- a/saleor/dashboard/order/views.py+++ b/saleor/dashboard/order/views.py@@ -70,7 +70,9 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):if form.is_valid():if action == 'capture' and payment.status == 'preauth':try:- payment.capture(amount=form.cleaned_data['amount'])+ payment.capture(+ amount=form.cleaned_data['amount'],+ user=self.request.user)except PaymentError, e:error_msg = _('Payment gateway error: ') + e.messageelse:@@ -78,7 +80,9 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):elif action == 'refund' and payment.status == 'confirmed':try:- payment.refund(amount=payment.captured_amount)+ payment.refund(+ amount=payment.captured_amount,+ user=self.request.user)except PaymentError, e:error_msg = _('Payment gateway error: ') + e.messageelse:@@ -86,7 +90,7 @@ class OrderDetails(StaffMemberOnlyMixin, DetailView):elif action == 'release' and payment.status == 'preauth':try:- payment.release()+ payment.release(user=self.request.user)except PaymentError, e:error_msg = _('Payment gateway error: ') + e.messageelse:diff --git a/saleor/dashboard/templates/dashboard/order/detail.html b/saleor/dashboard/templates/dashboard/order/detail.htmlindex af2ec9f722..e711995635 100644--- a/saleor/dashboard/templates/dashboard/order/detail.html+++ b/saleor/dashboard/templates/dashboard/order/detail.html@@ -133,10 +133,18 @@</div><div class="panel-body"><ul class="list-unstyled">- {% for status_change in order.status_history.all %}+ {% for event in order.history.all %}<li>- <span>{{ status_change.date }}</span>- {% include 'dashboard/includes/_status_label.html' with status=status_change.status status_display=status_change.get_status_display %}+ {{ event.date }}+ {% include 'dashboard/includes/_status_label.html' with status=event.status status_display=event.get_status_display %}+ <small>+ {% if event.user %}+ <span>{{ event.user }}</span>+ {% endif %}+ {% if event.comment %}+ <span>{{ event.comment }}</span>+ {% endif %}+ </small></li>{% endfor %}</ul>diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 273fbbec87..8270c7468b 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -69,14 +69,14 @@ class Order(models.Model, ItemSet):self.token = tokenbreaksuper(Order, self).save(*args, **kwargs)- if not self.status_history.exists():- self.status_history.create(status=self.status)+ if not self.history.exists():+ self.history.create(status=self.status)def change_status(self, status):if status != self.status:self.status = statusself.save()- self.status_history.create(status=status)+ self.history.create(status=status)def get_items(self):return OrderedItem.objects.filter(delivery_group__order=self)@@ -267,17 +267,53 @@ class Payment(BasePayment):for item in self.order.get_items()]return items+ def capture(self, user=None, **kwargs):+ result = super(Payment, self).capture(**kwargs)+ amount = kwargs.get('amount', self.total)+ comment = pgettext_lazy(+ 'Order history',+ 'Captured %(amount)s %(currency)s'+ % {'amount': amount, 'currency': self.currency})+ self.order.history.create(+ status=self.order.status,+ comment=comment,+ user=user)+ return result++ def release(self, user=None, **kwargs):+ result = super(Payment, self).release(**kwargs)+ comment = pgettext_lazy('Order history', 'Released funds')+ self.order.history.create(+ status=self.order.status,+ comment=comment,+ user=user)+ return result++ def refund(self, user=None, **kwargs):+ result = super(Payment, self).refund(**kwargs)+ amount = kwargs.get('amount', self.total)+ comment = pgettext_lazy(+ 'Order history',+ 'Refunded %(amount)s %(currency)s'+ % {'amount': amount, 'currency': self.currency})+ self.order.history.create(+ status=self.order.status,+ comment=comment,+ user=user)+ return result+@python_2_unicode_compatible-class OrderStatusChange(models.Model):+class OrderHistoryEntry(models.Model):date = models.DateTimeField(- pgettext_lazy('Order field', 'last status change'),+ pgettext_lazy('Order field', 'last history change'),default=now, editable=False)- order = models.ForeignKey(Order, related_name='status_history')+ order = models.ForeignKey(Order, related_name='history')status = models.CharField(pgettext_lazy('Order field', 'order status'),max_length=32, choices=Order.STATUS_CHOICES)comment = models.CharField(max_length=100, null=True, blank=True)+ user = models.ForeignKey(User, blank=True, null=True)def __str__(self):return 'Order #{0} status changed: {1}'.format(@@ -297,3 +333,10 @@ class OrderNote(models.Model):def __str__(self):return 'OrderNote for Order {0}'.format(self.order.pk)++ def save(self, *args, **kwargs):+ super(OrderNote, self).save(*args, **kwargs)+ self.order.history.create(+ status=self.order.status,+ comment=pgettext_lazy('Order history', 'Added note'),+ user=self.user)