feat: allow basic support for item discounts
This commit is contained in:
parent
f8f745c243
commit
bdf9e46be5
8 changed files with 229 additions and 25 deletions
|
@ -20,36 +20,66 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
def make_handler(self):
|
||||
return mod.NewOrderBatchHandler(self.config)
|
||||
|
||||
def tets_use_local_customers(self):
|
||||
def test_use_local_customers(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# true by default
|
||||
self.assertTrue(handler.use_local_customers())
|
||||
|
||||
# config can disable
|
||||
config.setdefault('sideshow.orders.use_local_customers', 'false')
|
||||
self.config.setdefault('sideshow.orders.use_local_customers', 'false')
|
||||
self.assertFalse(handler.use_local_customers())
|
||||
|
||||
def tets_use_local_products(self):
|
||||
def test_use_local_products(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# true by default
|
||||
self.assertTrue(handler.use_local_products())
|
||||
|
||||
# config can disable
|
||||
config.setdefault('sideshow.orders.use_local_products', 'false')
|
||||
self.config.setdefault('sideshow.orders.use_local_products', 'false')
|
||||
self.assertFalse(handler.use_local_products())
|
||||
|
||||
def tets_allow_unknown_products(self):
|
||||
def test_allow_unknown_products(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# true by default
|
||||
self.assertTrue(handler.allow_unknown_products())
|
||||
|
||||
# config can disable
|
||||
config.setdefault('sideshow.orders.allow_unknown_products', 'false')
|
||||
self.config.setdefault('sideshow.orders.allow_unknown_products', 'false')
|
||||
self.assertFalse(handler.allow_unknown_products())
|
||||
|
||||
def test_allow_item_discounts(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# false by default
|
||||
self.assertFalse(handler.allow_item_discounts())
|
||||
|
||||
# config can enable
|
||||
self.config.setdefault('sideshow.orders.allow_item_discounts', 'true')
|
||||
self.assertTrue(handler.allow_item_discounts())
|
||||
|
||||
def test_allow_item_discounts_if_on_sale(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# false by default
|
||||
self.assertFalse(handler.allow_item_discounts_if_on_sale())
|
||||
|
||||
# config can enable
|
||||
self.config.setdefault('sideshow.orders.allow_item_discounts_if_on_sale', 'true')
|
||||
self.assertTrue(handler.allow_item_discounts_if_on_sale())
|
||||
|
||||
def test_get_default_item_discount(self):
|
||||
handler = self.make_handler()
|
||||
|
||||
# null by default
|
||||
self.assertIsNone(handler.get_default_item_discount())
|
||||
|
||||
# config can define
|
||||
self.config.setdefault('sideshow.orders.default_item_discount', '15')
|
||||
self.assertEqual(handler.get_default_item_discount(), decimal.Decimal('15.00'))
|
||||
|
||||
def test_autocomplete_customers_external(self):
|
||||
handler = self.make_handler()
|
||||
self.assertRaises(NotImplementedError, handler.autocomplete_customers_external,
|
||||
|
@ -327,7 +357,7 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.config.setdefault('sideshow.orders.allow_unknown_products', 'false')
|
||||
self.assertRaises(TypeError, handler.add_item, batch, kw, 1, enum.ORDER_UOM_UNIT)
|
||||
|
||||
# local product
|
||||
# local product w/ discount
|
||||
local = model.LocalProduct(scancode='07430500002',
|
||||
description='Vinegar',
|
||||
size='2oz',
|
||||
|
@ -335,7 +365,9 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
case_size=12)
|
||||
self.session.add(local)
|
||||
self.session.flush()
|
||||
row = handler.add_item(batch, local.uuid.hex, 1, enum.ORDER_UOM_CASE)
|
||||
with patch.object(handler, 'allow_item_discounts', return_value=True):
|
||||
row = handler.add_item(batch, local.uuid.hex, 1, enum.ORDER_UOM_CASE,
|
||||
discount_percent=15)
|
||||
self.session.flush()
|
||||
self.session.refresh(row)
|
||||
self.session.refresh(local)
|
||||
|
@ -359,7 +391,8 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.assertEqual(row.unit_price_reg, decimal.Decimal('2.99'))
|
||||
self.assertEqual(row.unit_price_quoted, decimal.Decimal('2.99'))
|
||||
self.assertEqual(row.case_price_quoted, decimal.Decimal('35.88'))
|
||||
self.assertEqual(row.total_price, decimal.Decimal('35.88'))
|
||||
self.assertEqual(row.discount_percent, decimal.Decimal('15.00'))
|
||||
self.assertEqual(row.total_price, decimal.Decimal('30.50'))
|
||||
|
||||
# local product, not found
|
||||
mock_uuid = self.app.make_true_uuid()
|
||||
|
@ -511,8 +544,10 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.config.setdefault('sideshow.orders.allow_unknown_products', 'false')
|
||||
self.assertRaises(TypeError, handler.update_item, row, kw, 1, enum.ORDER_UOM_UNIT)
|
||||
|
||||
# update w/ local product
|
||||
handler.update_item(row, local.uuid.hex, 1, enum.ORDER_UOM_CASE)
|
||||
# update w/ local product and discount percent
|
||||
with patch.object(handler, 'allow_item_discounts', return_value=True):
|
||||
handler.update_item(row, local.uuid.hex, 1, enum.ORDER_UOM_CASE,
|
||||
discount_percent=15)
|
||||
self.assertIsNone(row.product_id)
|
||||
# nb. pending remains intact here
|
||||
self.assertIsNotNone(row.pending_product)
|
||||
|
@ -536,7 +571,8 @@ class TestNewOrderBatchHandler(DataTestCase):
|
|||
self.assertEqual(row.case_price_quoted, decimal.Decimal('47.88'))
|
||||
self.assertEqual(row.order_qty, 1)
|
||||
self.assertEqual(row.order_uom, enum.ORDER_UOM_CASE)
|
||||
self.assertEqual(row.total_price, decimal.Decimal('47.88'))
|
||||
self.assertEqual(row.discount_percent, decimal.Decimal('15.00'))
|
||||
self.assertEqual(row.total_price, decimal.Decimal('40.70'))
|
||||
|
||||
# update w/ local, not found
|
||||
mock_uuid = self.app.make_true_uuid()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue