fix: require store for new orders, if so configured

This commit is contained in:
Lance Edgar 2025-02-19 19:18:30 -06:00
parent f3cca2e370
commit 7ea83b2715
2 changed files with 13 additions and 1 deletions

View file

@ -1017,8 +1017,14 @@ class NewOrderBatchHandler(BatchHandler):
def why_not_execute(self, batch, **kwargs): def why_not_execute(self, batch, **kwargs):
""" """
By default this checks to ensure the batch has a customer with By default this checks to ensure the batch has a customer with
phone number, and at least one item. phone number, and at least one item. It also may check to
ensure the store is assigned, if applicable.
""" """
if not batch.store_id:
order_handler = self.app.get_order_handler()
if order_handler.expose_store_id():
return "Must assign the store"
if not batch.customer_name: if not batch.customer_name:
return "Must assign the customer" return "Must assign the customer"

View file

@ -1114,9 +1114,15 @@ class TestNewOrderBatchHandler(DataTestCase):
self.session.add(row) self.session.add(row)
self.session.flush() self.session.flush()
# batch is okay to execute..
reason = handler.why_not_execute(batch) reason = handler.why_not_execute(batch)
self.assertIsNone(reason) self.assertIsNone(reason)
# unless we also require store
self.config.setdefault('sideshow.orders.expose_store_id', 'true')
reason = handler.why_not_execute(batch)
self.assertEqual(reason, "Must assign the store")
def test_make_local_customer(self): def test_make_local_customer(self):
model = self.app.model model = self.app.model
enum = self.app.enum enum = self.app.enum