本文整理汇总了Python中stoqlib.domain.workorder.WorkOrderItem.sync_stock方法的典型用法代码示例。如果您正苦于以下问题:Python WorkOrderItem.sync_stock方法的具体用法?Python WorkOrderItem.sync_stock怎么用?Python WorkOrderItem.sync_stock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.domain.workorder.WorkOrderItem
的用法示例。
在下文中一共展示了WorkOrderItem.sync_stock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_remove
# 需要导入模块: from stoqlib.domain.workorder import WorkOrderItem [as 别名]
# 或者: from stoqlib.domain.workorder.WorkOrderItem import sync_stock [as 别名]
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)