Fix ordering worksheet API for date objects

This commit is contained in:
Lance Edgar 2022-12-08 14:54:36 -06:00
parent f80d3cd530
commit 1a51f3d854

View file

@ -29,6 +29,8 @@ API.
from __future__ import unicode_literals, absolute_import
import datetime
import six
from rattail.db import model
@ -94,6 +96,8 @@ class OrderingBatchViews(APIBatchView):
if batch.executed:
raise self.forbidden()
app = self.get_rattail_app()
# TODO: much of the logic below was copied from the traditional master
# view for ordering batches. should maybe let them share it somehow?
@ -179,6 +183,16 @@ class OrderingBatchViews(APIBatchView):
for i in range(6 - len(history)):
history.append(None)
history = list(reversed(history))
# must convert some date objects to string, for JSON sake
for h in history:
purchase = h.get('purchase')
if purchase:
dt = purchase.get('date_ordered')
if dt and isinstance(dt, datetime.date):
purchase['date_ordered'] = app.render_date(dt)
dt = purchase.get('date_received')
if dt and isinstance(dt, datetime.date):
purchase['date_received'] = app.render_date(dt)
return {
'batch': self.normalize(batch),