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 reserve stock. The other one is to test it being # removed without ever decreasing the stock item1.reserve(item1.quantity) 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]: workorder.remove_item(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) with self.sysparam(SYNCHRONIZED_MODE=True): item = self.create_work_order_item() order = item.order before_remove = self.store.find(WorkOrderItem).count() order.remove_item(item) after_remove = self.store.find(WorkOrderItem).count() # The item should still be on the database self.assertEqual(before_remove, after_remove) # But not related to the loan self.assertEquals( self.store.find(WorkOrderItem, order=order).count(), 0)
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 reserve stock. The other one is to test it being # removed without ever decreasing the stock item1.reserve(item1.quantity) 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]: workorder.remove_item(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) with self.sysparam(SYNCHRONIZED_MODE=True): item = self.create_work_order_item() order = item.order before_remove = self.store.find(WorkOrderItem).count() order.remove_item(item) after_remove = self.store.find(WorkOrderItem).count() # The item should still be on the database self.assertEqual(before_remove, after_remove) # But not related to the loan self.assertEquals(self.store.find(WorkOrderItem, order=order).count(), 0)