feat: allow re-order past product for new orders
assuming batch has a customer set, with order history nb. this only uses past *products* and not order qty/uom
This commit is contained in:
parent
aa31d23fc8
commit
3ca89a8479
5 changed files with 633 additions and 54 deletions
|
@ -16,6 +16,7 @@ from sideshow.orders import OrderHandler
|
|||
from sideshow.testing import WebTestCase
|
||||
from sideshow.web.views import orders as mod
|
||||
from sideshow.web.forms.schema import OrderRef, PendingProductRef
|
||||
from sideshow.config import SideshowConfig
|
||||
|
||||
|
||||
class TestIncludeme(WebTestCase):
|
||||
|
@ -26,6 +27,11 @@ class TestIncludeme(WebTestCase):
|
|||
|
||||
class TestOrderView(WebTestCase):
|
||||
|
||||
def make_config(self, **kw):
|
||||
config = super().make_config(**kw)
|
||||
SideshowConfig().configure(config)
|
||||
return config
|
||||
|
||||
def make_view(self):
|
||||
return mod.OrderView(self.request)
|
||||
|
||||
|
@ -661,6 +667,51 @@ class TestOrderView(WebTestCase):
|
|||
context = view.get_product_info(batch, {'product_id': '42'})
|
||||
self.assertEqual(context, {'error': "something smells fishy"})
|
||||
|
||||
def test_get_past_products(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
handler = view.batch_handler
|
||||
|
||||
user = model.User(username='barney')
|
||||
self.session.add(user)
|
||||
batch = handler.make_batch(self.session, created_by=user)
|
||||
self.session.add(batch)
|
||||
self.session.flush()
|
||||
|
||||
# (nb. this all assumes local customers and products)
|
||||
|
||||
# error if no customer
|
||||
self.assertRaises(ValueError, view.get_past_products, batch, {})
|
||||
|
||||
# empty history for customer
|
||||
customer = model.LocalCustomer(full_name='Fred Flintstone')
|
||||
batch.local_customer = customer
|
||||
self.session.flush()
|
||||
products = view.get_past_products(batch, {})
|
||||
self.assertEqual(len(products), 0)
|
||||
|
||||
# mock historical order
|
||||
order = model.Order(order_id=42, local_customer=customer, created_by=user)
|
||||
product = model.LocalProduct(scancode='07430500132', description='Vinegar',
|
||||
unit_price_reg=5.99, case_size=12)
|
||||
item = model.OrderItem(local_product=product, order_qty=1, order_uom=enum.ORDER_UOM_UNIT,
|
||||
status_code=enum.ORDER_ITEM_STATUS_READY)
|
||||
order.items.append(item)
|
||||
self.session.add(order)
|
||||
self.session.flush()
|
||||
self.session.refresh(product)
|
||||
|
||||
# that should now be returned
|
||||
products = view.get_past_products(batch, {})
|
||||
self.assertEqual(len(products), 1)
|
||||
self.assertEqual(products[0]['product_id'], product.uuid.hex)
|
||||
self.assertEqual(products[0]['scancode'], '07430500132')
|
||||
self.assertEqual(products[0]['description'], 'Vinegar')
|
||||
# nb. this is a float, since result is JSON-safe
|
||||
self.assertEqual(products[0]['case_price_quoted'], 71.88)
|
||||
self.assertEqual(products[0]['case_price_quoted_display'], '$71.88')
|
||||
|
||||
def test_add_item(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
@ -911,14 +962,6 @@ class TestOrderView(WebTestCase):
|
|||
'error': f"ValueError: batch has already been executed: {batch}",
|
||||
})
|
||||
|
||||
def test_get_default_uom_choices(self):
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
uoms = view.get_default_uom_choices()
|
||||
self.assertEqual(uoms, [{'key': key, 'value': val}
|
||||
for key, val in enum.ORDER_UOM.items()])
|
||||
|
||||
def test_normalize_batch(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue