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


Python Sellable.is_valid_price方法代码示例

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


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

示例1: test_is_valid_price

# 需要导入模块: from stoqlib.domain.sellable import Sellable [as 别名]
# 或者: from stoqlib.domain.sellable.Sellable import is_valid_price [as 别名]
    def test_is_valid_price(self):

        def isValidPriceAssert(valid_data, expected_validity, min_price,
                               max_discount):
            self.assertEquals(valid_data['is_valid'], expected_validity)
            self.assertEquals(valid_data['min_price'], min_price)
            self.assertEquals(valid_data['max_discount'], max_discount)

        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                        price=150, max_discount=0,
                                        store=self.store)
        user = self.create_user()
        user.profile.max_discount = 50

        # without a category, and max_discount = 0, user = None
        valid_data = sellable.is_valid_price(-10)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(99)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(100)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        valid_data = sellable.is_valid_price(101)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        # without a category, and max_discount = 10%
        sellable.max_discount = 10

        valid_data = sellable.is_valid_price(-1)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(89)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(90)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        valid_data = sellable.is_valid_price(91)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        # Now with a category, max_discount = 0
        valid_data = sellable.is_valid_price(0, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(-10, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(150, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        valid_data = sellable.is_valid_price(151, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(135, cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(134, cat)
        isValidPriceAssert(valid_data, False, currency(135), 10)

        # with a user
        valid_data = sellable.is_valid_price(49, None, user)
        isValidPriceAssert(valid_data, False, currency(50), 50)

        valid_data = sellable.is_valid_price(50, None, user)
        isValidPriceAssert(valid_data, True, currency(50), 50)
开发者ID:LeonamSilva,项目名称:stoq,代码行数:90,代码来源:test_sellable.py

示例2: testIsValidPrice

# 需要导入模块: from stoqlib.domain.sellable import Sellable [as 别名]
# 或者: from stoqlib.domain.sellable.Sellable import is_valid_price [as 别名]
    def testIsValidPrice(self):
        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                        price=150, max_discount=0,
                                        store=self.store)

        # without a category, and max_discount = 0
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-10))
        self.assertFalse(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))
        self.assertTrue(sellable.is_valid_price(100))

        # without a category, and max_discount = 10%
        sellable.max_discount = 10
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-1))
        self.assertFalse(sellable.is_valid_price(89))
        self.assertTrue(sellable.is_valid_price(90))
        self.assertTrue(sellable.is_valid_price(95))
        self.assertTrue(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))

        # Now with a category, max_discount = 0
        self.assertFalse(sellable.is_valid_price(0, cat))
        self.assertFalse(sellable.is_valid_price(-10, cat))
        self.assertFalse(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(150, cat))
        self.assertTrue(sellable.is_valid_price(151, cat))

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10
        self.assertTrue(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(135, cat))
        self.assertFalse(sellable.is_valid_price(134, cat))
开发者ID:marianaanselmo,项目名称:stoq,代码行数:42,代码来源:test_sellable.py


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