unbreak refund order function, while here show on order list and detail pages if an order is refunded, also fix tickettype detail stats so they dont include refunded orders
This commit is contained in:
parent
929cde010e
commit
792fc2bfc0
|
@ -14,6 +14,7 @@ from django.utils.dateparse import parse_datetime
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
|
||||||
|
from tickets.models import ShopTicket
|
||||||
from utils.models import CreatedUpdatedModel, UUIDModel
|
from utils.models import CreatedUpdatedModel, UUIDModel
|
||||||
from utils.slugs import unique_slugify
|
from utils.slugs import unique_slugify
|
||||||
|
|
||||||
|
@ -290,16 +291,17 @@ class Order(CreatedUpdatedModel):
|
||||||
else:
|
else:
|
||||||
self.refunded = True
|
self.refunded = True
|
||||||
# delete any tickets related to this order
|
# delete any tickets related to this order
|
||||||
if self.shoptickets.all():
|
tickets = ShopTicket.objects.filter(opr__order=self)
|
||||||
|
if tickets.exists():
|
||||||
msg = "Order %s marked as refunded, deleting %s tickets..." % (
|
msg = "Order %s marked as refunded, deleting %s tickets..." % (
|
||||||
self.pk,
|
self.pk,
|
||||||
self.shoptickets.count(),
|
tickets.count(),
|
||||||
)
|
)
|
||||||
if request:
|
if request:
|
||||||
messages.success(request, msg)
|
messages.success(request, msg)
|
||||||
else:
|
else:
|
||||||
print(msg)
|
print(msg)
|
||||||
self.shoptickets.all().delete()
|
tickets.delete()
|
||||||
else:
|
else:
|
||||||
msg = "Order %s marked as refunded, no tickets to delete" % self.pk
|
msg = "Order %s marked as refunded, no tickets to delete" % self.pk
|
||||||
if request:
|
if request:
|
||||||
|
@ -399,7 +401,10 @@ class ProductCategory(CreatedUpdatedModel, UUIDModel):
|
||||||
class ProductStatsManager(models.Manager):
|
class ProductStatsManager(models.Manager):
|
||||||
def with_ticket_stats(self):
|
def with_ticket_stats(self):
|
||||||
return (
|
return (
|
||||||
self.filter(orderproductrelation__order__paid=True)
|
self.filter(
|
||||||
|
orderproductrelation__order__paid=True,
|
||||||
|
orderproductrelation__order__refunded=False,
|
||||||
|
)
|
||||||
.annotate(total_units_sold=Sum("orderproductrelation__quantity"))
|
.annotate(total_units_sold=Sum("orderproductrelation__quantity"))
|
||||||
.annotate(profit=F("price") - F("cost"))
|
.annotate(profit=F("price") - F("cost"))
|
||||||
.annotate(total_income=F("price") * F("total_units_sold"))
|
.annotate(total_income=F("price") * F("total_units_sold"))
|
||||||
|
|
|
@ -116,9 +116,13 @@ Details for Order #{{ order.id }} | {{ block.super }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if order.paid %}
|
{% if order.paid %}
|
||||||
<div class="panel-footer">
|
<div class="panel-footer">
|
||||||
<h4>Your order is paid in full.</h4>
|
{% if order.refunded %}
|
||||||
</div>
|
<h4>This order has been refunded and tickets related to it are deleted and no longer valid.</h4>
|
||||||
|
{% else %}
|
||||||
|
<h4>This order is paid in full.</h4>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ Orders | {{ block.super }}
|
||||||
<th>Total amount</th>
|
<th>Total amount</th>
|
||||||
<th>Open?</th>
|
<th>Open?</th>
|
||||||
<th>Paid?</th>
|
<th>Paid?</th>
|
||||||
|
<th>Refunded?</th>
|
||||||
<th>Delivered?</th>
|
<th>Delivered?</th>
|
||||||
<th>Invoice</th>
|
<th>Invoice</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
|
@ -35,6 +36,7 @@ Orders | {{ block.super }}
|
||||||
<td>{{ order.total|currency }}</td>
|
<td>{{ order.total|currency }}</td>
|
||||||
<td class="text-center">{{ order.open|truefalseicon }}</td>
|
<td class="text-center">{{ order.open|truefalseicon }}</td>
|
||||||
<td class="text-center">{{ order.paid|truefalseicon }}</td>
|
<td class="text-center">{{ order.paid|truefalseicon }}</td>
|
||||||
|
<td class="text-center">{{ order.refunded|truefalseicon }}</td>
|
||||||
<td class="text-center">{{ order.ticket_generated_status }}</td>
|
<td class="text-center">{{ order.ticket_generated_status }}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if order.paid %}
|
{% if order.paid %}
|
||||||
|
|
Loading…
Reference in a new issue