Fix ordering worksheet API for date objects
This commit is contained in:
		
							parent
							
								
									f80d3cd530
								
							
						
					
					
						commit
						1a51f3d854
					
				
					 1 changed files with 14 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -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),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue