fix: expose config for new order w/ pending product
- whether or not this feature should be allowed at all - user must have permission also - UI should honor both of the above - also, which fields are required for new pending product
This commit is contained in:
parent
e677cd5d8c
commit
ebd22fe6ee
5 changed files with 177 additions and 28 deletions
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
|
||||
import datetime
|
||||
import decimal
|
||||
|
||||
from wuttjamaican.testing import DataTestCase
|
||||
|
@ -18,6 +19,16 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
def make_handler(self):
|
||||
return mod.NewOrderBatchHandler(self.config)
|
||||
|
||||
def tets_allow_unknown_product(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# true by default
|
||||
self.assertTrue(handler.allow_unknown_product())
|
||||
|
||||
# config can disable
|
||||
config.setdefault('sideshow.orders.allow_unknown_product', 'false')
|
||||
self.assertFalse(handler.allow_unknown_product())
|
||||
|
||||
def test_set_pending_customer(self):
|
||||
model = self.app.model
|
||||
handler = self.make_handler()
|
||||
|
@ -119,6 +130,10 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.assertEqual(product.unit_price_reg, decimal.Decimal('5.99'))
|
||||
self.assertIs(product.created_by, user)
|
||||
|
||||
# error if unknown products not allowed
|
||||
self.config.setdefault('sideshow.orders.allow_unknown_product', 'false')
|
||||
self.assertRaises(TypeError, handler.add_pending_product, batch, kw, 1, enum.ORDER_UOM_UNIT)
|
||||
|
||||
def test_set_pending_product(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
@ -210,6 +225,15 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.assertEqual(product.unit_price_reg, decimal.Decimal('3.59'))
|
||||
self.assertIs(product.created_by, user)
|
||||
|
||||
# error if unknown products not allowed
|
||||
self.config.setdefault('sideshow.orders.allow_unknown_product', 'false')
|
||||
self.assertRaises(TypeError, handler.set_pending_product, row, dict(
|
||||
scancode='07430500116',
|
||||
size='16oz',
|
||||
unit_cost=decimal.Decimal('2.19'),
|
||||
unit_price_reg=decimal.Decimal('3.59'),
|
||||
))
|
||||
|
||||
def test_refresh_row(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
@ -310,6 +334,37 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.assertEqual(row.case_price_quoted, decimal.Decimal('71.88'))
|
||||
self.assertEqual(row.total_price, decimal.Decimal('143.76'))
|
||||
|
||||
# refreshed from pending product (sale price)
|
||||
product = model.PendingProduct(scancode='07430500132',
|
||||
brand_name='Bragg',
|
||||
description='Vinegar',
|
||||
size='32oz',
|
||||
case_size=12,
|
||||
unit_cost=decimal.Decimal('3.99'),
|
||||
unit_price_reg=decimal.Decimal('5.99'),
|
||||
created_by=user,
|
||||
status=enum.PendingProductStatus.PENDING)
|
||||
row = handler.make_row(pending_product=product, order_qty=2, order_uom=enum.ORDER_UOM_CASE,
|
||||
unit_price_sale=decimal.Decimal('5.19'),
|
||||
sale_ends=datetime.datetime(2099, 1, 1))
|
||||
self.assertIsNone(row.status_code)
|
||||
handler.add_row(batch, row)
|
||||
self.assertEqual(row.status_code, row.STATUS_OK)
|
||||
self.assertIsNone(row.product_id)
|
||||
self.assertIs(row.pending_product, product)
|
||||
self.assertEqual(row.product_scancode, '07430500132')
|
||||
self.assertEqual(row.product_brand, 'Bragg')
|
||||
self.assertEqual(row.product_description, 'Vinegar')
|
||||
self.assertEqual(row.product_size, '32oz')
|
||||
self.assertEqual(row.case_size, 12)
|
||||
self.assertEqual(row.unit_cost, decimal.Decimal('3.99'))
|
||||
self.assertEqual(row.unit_price_reg, decimal.Decimal('5.99'))
|
||||
self.assertEqual(row.unit_price_sale, decimal.Decimal('5.19'))
|
||||
self.assertEqual(row.sale_ends, datetime.datetime(2099, 1, 1))
|
||||
self.assertEqual(row.unit_price_quoted, decimal.Decimal('5.19'))
|
||||
self.assertEqual(row.case_price_quoted, decimal.Decimal('62.28'))
|
||||
self.assertEqual(row.total_price, decimal.Decimal('124.56'))
|
||||
|
||||
def test_remove_row(self):
|
||||
model = self.app.model
|
||||
enum = self.app.enum
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue