Open
Description
When your order is paid and you want to go back "one step" to previous OrderStatus
it means that you have to prune through the OrderLogEntry
objects to find last status_change
and then match the name to OrderStatus
to find the correct one.
Simple example of this:
def get_last_order_status_change(order):
return order.log_entries.filter(
identifier="status_change"
).values_list(
"message", "created_on"
).order_by("-created_on").first()
def resolve_previous_order_status_change(order, default_status=None):
last_status = get_last_order_status_change(order)
if not last_status:
if not default_status:
default_status = OrderStatus.objects.get_default_initial()
return default_status, default_status
frm, to = last_status[0].split(":")[1].split("to")
from_status = OrderStatus.objects.filter(translations__name=frm.strip()).first()
to_status = OrderStatus.objects.filter(translations__name=to.strip()).first()
return from_status, to_status
It would make sense if Shuup had an OrderStatusHistory
which would help matching the status changes better.