当前位置: 首页>>代码示例>>Python>>正文


Python WorkOrderItem.reserve方法代码示例

本文整理汇总了Python中stoqlib.domain.workorder.WorkOrderItem.reserve方法的典型用法代码示例。如果您正苦于以下问题:Python WorkOrderItem.reserve方法的具体用法?Python WorkOrderItem.reserve怎么用?Python WorkOrderItem.reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stoqlib.domain.workorder.WorkOrderItem的用法示例。


在下文中一共展示了WorkOrderItem.reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove

# 需要导入模块: from stoqlib.domain.workorder import WorkOrderItem [as 别名]
# 或者: from stoqlib.domain.workorder.WorkOrderItem import reserve [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 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)
开发者ID:EasyDevSolutions,项目名称:stoq,代码行数:45,代码来源:test_workorder.py


注:本文中的stoqlib.domain.workorder.WorkOrderItem.reserve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。