feat: add basic support to "resolve" a pending product
This commit is contained in:
parent
6b4bc3da10
commit
1ee398e8fb
17 changed files with 780 additions and 69 deletions
|
@ -1144,6 +1144,8 @@ class TestOrderView(WebTestCase):
|
|||
row.department_id = 1
|
||||
row.department_name = "Bricks & Mortar"
|
||||
row.special_order = False
|
||||
row.vendor_name = 'Acme Distributors'
|
||||
row.vendor_item_code = '1234'
|
||||
row.case_size = None
|
||||
row.unit_cost = decimal.Decimal('599.99')
|
||||
row.unit_price_reg = decimal.Decimal('999.99')
|
||||
|
@ -1159,7 +1161,8 @@ class TestOrderView(WebTestCase):
|
|||
self.assertEqual(data['product_scancode'], '012345')
|
||||
self.assertEqual(data['product_full_description'], 'Acme Bricks 1 ton')
|
||||
self.assertIsNone(data['case_size'])
|
||||
self.assertNotIn('vendor_name', data) # TODO
|
||||
self.assertEqual(data['vendor_name'], 'Acme Distributors')
|
||||
self.assertEqual(data['vendor_item_code'], '1234')
|
||||
self.assertEqual(data['order_qty'], 1)
|
||||
self.assertEqual(data['order_uom'], 'EA')
|
||||
self.assertEqual(data['order_qty_display'], '1 Units')
|
||||
|
|
|
@ -132,6 +132,19 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertIn('brand_name', grid.linked_columns)
|
||||
self.assertIn('description', grid.linked_columns)
|
||||
|
||||
def test_grid_row_class(self):
|
||||
enum = self.app.enum
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
product = model.PendingProduct()
|
||||
|
||||
# null by default
|
||||
self.assertIsNone(view.grid_row_class(product, {}, 1))
|
||||
|
||||
# warning for ignored
|
||||
product.status = enum.PendingProductStatus.IGNORED
|
||||
self.assertEqual(view.grid_row_class(product, {}, 1), 'has-background-warning')
|
||||
|
||||
def test_configure_form(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
@ -141,7 +154,6 @@ class TestPendingProductView(WebTestCase):
|
|||
with patch.object(view, 'creating', new=True):
|
||||
form = view.make_form(model_class=model.PendingProduct)
|
||||
view.configure_form(form)
|
||||
self.assertNotIn('status', form)
|
||||
self.assertNotIn('created', form)
|
||||
self.assertNotIn('created_by', form)
|
||||
|
||||
|
@ -216,6 +228,39 @@ class TestPendingProductView(WebTestCase):
|
|||
self.assertEqual(len(grid.actions), 1)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
|
||||
def test_get_template_context(self):
|
||||
enum = self.app.enum
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING)
|
||||
orig_context = {'instance': product}
|
||||
|
||||
# local setting omitted by default
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
|
||||
# still omitted even though 'viewing'
|
||||
with patch.object(view, 'viewing', new=True):
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
|
||||
# still omitted even though correct status
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertNotIn('use_local_products', context)
|
||||
|
||||
# no longer omitted if user has perm
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertIn('use_local_products', context)
|
||||
# nb. true by default
|
||||
self.assertTrue(context['use_local_products'])
|
||||
|
||||
# accurately reflects config
|
||||
self.config.setdefault('sideshow.orders.use_local_products', 'false')
|
||||
context = view.get_template_context(orig_context)
|
||||
self.assertFalse(context['use_local_products'])
|
||||
|
||||
def test_delete_instance(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
model = self.app.model
|
||||
|
@ -259,3 +304,117 @@ class TestPendingProductView(WebTestCase):
|
|||
view.delete_instance(product)
|
||||
self.session.flush()
|
||||
self.assertEqual(self.session.query(model.PendingProduct).count(), 0)
|
||||
|
||||
def test_resolve(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
# sample data
|
||||
user = model.User(username='barney')
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
self.session.add(product)
|
||||
self.session.flush()
|
||||
|
||||
info = {
|
||||
'product_id': '07430500132',
|
||||
'scancode': '07430500132',
|
||||
'brand_name': "Bragg's",
|
||||
'description': "Apple Cider Vinegar",
|
||||
'size': "32oz",
|
||||
'weighed': False,
|
||||
'department_id': None,
|
||||
'department_name': None,
|
||||
'special_order': False,
|
||||
'vendor_name': None,
|
||||
'vendor_item_code': None,
|
||||
'case_size': 12,
|
||||
'unit_cost': 2.99,
|
||||
'unit_price_reg': 5.99,
|
||||
}
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': product.uuid}):
|
||||
|
||||
# flash error if wrong status
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["pending product does not have 'ready' status!"])
|
||||
|
||||
# flash error if product_id not specified
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["must specify valid product_id"])
|
||||
|
||||
# more sample data
|
||||
order = model.Order(order_id=100, created_by=user,
|
||||
customer_name="Fred Flintstone")
|
||||
item = model.OrderItem(pending_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)
|
||||
|
||||
# product + order items updated
|
||||
self.assertIsNone(product.product_id)
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.READY)
|
||||
self.assertIsNone(item.product_id)
|
||||
batch_handler = NewOrderBatchHandler(self.config)
|
||||
with patch.object(batch_handler, 'get_product_info_external',
|
||||
return_value=info):
|
||||
with patch.object(self.app, 'get_batch_handler',
|
||||
return_value=batch_handler):
|
||||
with patch.object(self.request, 'POST',
|
||||
new={'product_id': '07430500132'}):
|
||||
with patch.object(batch_handler, 'get_product_info_external',
|
||||
return_value=info):
|
||||
result = view.resolve()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertFalse(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(product.product_id, '07430500132')
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.RESOLVED)
|
||||
self.assertEqual(item.product_id, '07430500132')
|
||||
|
||||
def test_ignore(self):
|
||||
self.pyramid_config.add_route('pending_products.view', '/pending/products/{uuid}')
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
view = self.make_view()
|
||||
|
||||
# sample data
|
||||
user = model.User(username='barney')
|
||||
self.session.add(user)
|
||||
product = model.PendingProduct(status=enum.PendingProductStatus.PENDING,
|
||||
created_by=user)
|
||||
self.session.add(product)
|
||||
self.session.flush()
|
||||
|
||||
with patch.object(view, 'Session', return_value=self.session):
|
||||
with patch.object(self.request, 'user', new=user):
|
||||
with patch.object(self.request, 'matchdict', new={'uuid': product.uuid}):
|
||||
|
||||
# flash error if wrong status
|
||||
result = view.ignore()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertTrue(self.request.session.peek_flash('error'))
|
||||
self.assertEqual(self.request.session.pop_flash('error'),
|
||||
["pending product does not have 'ready' status!"])
|
||||
|
||||
# product updated
|
||||
product.status = enum.PendingProductStatus.READY
|
||||
self.assertIsNone(product.product_id)
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.READY)
|
||||
result = view.ignore()
|
||||
self.assertIsInstance(result, HTTPFound)
|
||||
self.assertFalse(self.request.session.peek_flash('error'))
|
||||
self.assertIsNone(product.product_id)
|
||||
self.assertEqual(product.status, enum.PendingProductStatus.IGNORED)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue