fix: require vendor when making new ordering batch via api

pretty sure this pattern needs to be expanded and probably improved,
but wanted to fix this one scenario for now, per error email
This commit is contained in:
Lance Edgar 2024-06-28 17:58:27 -05:00
parent ec5ed490d9
commit 9b6447c4cb
2 changed files with 11 additions and 5 deletions

View file

@ -86,6 +86,8 @@ class OrderingBatchViews(APIBatchView):
Sets the mode to "ordering" for the new batch.
"""
data = dict(data)
if not data.get('vendor_uuid'):
raise ValueError("You must specify the vendor")
data['mode'] = self.enum.PURCHASE_BATCH_MODE_ORDERING
batch = super().create_object(data)
return batch

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -31,7 +31,7 @@ from rattail.db.util import get_fieldnames
from cornice import resource, Service
from tailbone.api import APIView, api
from tailbone.api import APIView
from tailbone.db import Session
from tailbone.util import SortColumn
@ -355,9 +355,13 @@ class APIMasterView(APIView):
data = self.request.json_body
# add instance to session, and return data for it
obj = self.create_object(data)
self.Session.flush()
return self._get(obj)
try:
obj = self.create_object(data)
except Exception as error:
return self.json_response({'error': str(error)})
else:
self.Session.flush()
return self._get(obj)
def create_object(self, data):
"""