def test_remove(self): workorder = self.create_workorder() product1 = self.create_product(stock=10, branch=workorder.branch) product2 = self.create_product(stock=10, branch=workorder.branch) item1 = WorkOrderItem(self.store, sellable=product1.sellable, quantity=5) item2 = WorkOrderItem(self.store, sellable=product1.sellable, quantity=5) for item in [item1, item2]: self.assertRaises(AssertionError, workorder.remove_item, item) workorder.add_item(item1) workorder.add_item(item2) # Only item1 will sync stock. The other one is to test it being # removed without ever decreasing the stock item1.sync_stock() self.assertEqual( product1.storable.get_balance_for_branch(workorder.branch), 5) self.assertEqual( product2.storable.get_balance_for_branch(workorder.branch), 10) for item in [item1, item2]: with mock.patch.object(self.store, 'remove') as remove: workorder.remove_item(item) remove.assert_called_once_with(item) storable = item.sellable.product.storable # Everything should be back to the stock, like # the item never existed self.assertEqual( storable.get_balance_for_branch(workorder.branch), 10)
def test_remove(self): workorder = self.create_workorder() product1 = self.create_product(stock=10, branch=workorder.branch) product2 = self.create_product(stock=10, branch=workorder.branch) item1 = WorkOrderItem(self.store, sellable=product1.sellable, quantity=5) item2 = WorkOrderItem(self.store, sellable=product1.sellable, quantity=5) for item in [item1, item2]: self.assertRaises(AssertionError, workorder.remove_item, item) workorder.add_item(item1) workorder.add_item(item2) # Only item1 will sync stock. The other one is to test it being # removed without ever decreasing the stock item1.sync_stock() self.assertEqual( product1.storable.get_balance_for_branch(workorder.branch), 5) self.assertEqual( product2.storable.get_balance_for_branch(workorder.branch), 10) for item in [item1, item2]: with mock.patch.object(self.store, 'remove') as remove: workorder.remove_item(item) remove.assert_called_once_with(item) storable = item.sellable.product.storable # Everything should be back to the stock, like # the item never existed self.assertEqual( storable.get_balance_for_branch(workorder.branch), 10)