Esempio n. 1
0
    def test_price(self):
        p1 = self.create_product()
        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.price, 10)

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal('5.55')

        # And a interval that includes today
        yesterday = localtoday() - datetime.timedelta(days=1)
        tomorrow = localtoday() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('5.55'))

        # Testing with a sale price set, but in the past
        date1 = localtoday() - datetime.timedelta(days=10)
        date2 = localtoday() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, 10)
Esempio n. 2
0
    def testPostSearchCallback(self):
        self.clean_domain([ProductSupplierInfo, ProductStockItem, Storable,
                           Product])

        branch = self.create_branch()
        for i in range(20):
            self.create_product(branch=branch, stock=5)
        for i in range(10):
            self.create_product(branch=branch, stock=10)

        # Get just the products we created here
        sresults = self.store.find(ProductFullStockView)

        postresults = ProductFullStockView.post_search_callback(sresults)
        self.assertEqual(postresults[0], ('count', 'sum'))
        self.assertEqual(
            # Total stock = (10 * 10) + (20 * 5) = 200
            self.store.execute(postresults[1]).get_one(), (30, 200))

        sresults = sresults.find(ProductFullStockView.stock > 5)
        postresults = ProductFullStockView.post_search_callback(sresults)
        self.assertEqual(postresults[0], ('count', 'sum'))
        self.assertEqual(
            # Total stock = (10 * 10) = 100
            self.store.execute(postresults[1]).get_one(), (10, 100))
Esempio n. 3
0
    def testPrice(self):
        p1 = self.create_product()
        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.price, 10)

        # Set a sale price
        sellable = p1.sellable
        sellable.on_sale_price = Decimal('5.55')

        # And a interval that includes today
        yesterday = localtoday().date() - datetime.timedelta(days=1)
        tomorrow = localtoday().date() + datetime.timedelta(days=1)
        sellable.on_sale_start_date = yesterday
        sellable.on_sale_end_date = tomorrow

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, Decimal('5.55'))

        # Testing with a sale price set, but in the past
        date1 = localtoday().date() - datetime.timedelta(days=10)
        date2 = localtoday().date() - datetime.timedelta(days=5)
        sellable.on_sale_start_date = date1
        sellable.on_sale_end_date = date2

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.assertEquals(results[0].price, 10)
Esempio n. 4
0
    def test_post_search_callback(self):
        self.clean_domain([StockTransactionHistory, ProductSupplierInfo, ProductStockItem,
                           Storable, Product])

        branch = self.create_branch()
        for i in range(20):
            self.create_product(branch=branch, stock=5)
        for i in range(10):
            self.create_product(branch=branch, stock=10)

        # Get just the products we created here
        sresults = self.store.find(ProductFullStockView)

        postresults = ProductFullStockView.post_search_callback(sresults)
        self.assertEqual(postresults[0], ('count', 'sum'))
        self.assertEqual(
            # Total stock = (10 * 10) + (20 * 5) = 200
            self.store.execute(postresults[1]).get_one(), (30, 200))

        sresults = sresults.find(ProductFullStockView.stock > 5)
        postresults = ProductFullStockView.post_search_callback(sresults)
        self.assertEqual(postresults[0], ('count', 'sum'))
        self.assertEqual(
            # Total stock = (10 * 10) = 100
            self.store.execute(postresults[1]).get_one(), (10, 100))
Esempio n. 5
0
    def test_select_by_branch(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        self.failUnless(list(results))
        # FIXME: Storm does not support count() with group_by
        # self.assertEquals(results.count(), 1)
        self.assertEquals(len(list(results)), 1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        self.assertEquals(len(list(results)), 1)
Esempio n. 6
0
    def testSelectByBranch(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        self.failUnless(list(results))
        # FIXME: Storm does not support count() with group_by
        # self.assertEquals(results.count(), 1)
        self.assertEquals(len(list(results)), 1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        self.assertEquals(len(list(results)), 1)
Esempio n. 7
0
    def test_select_by_branch(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        self.failUnless(list(results))
        # FIXME: Storm does not support count() with group_by
        # self.assertEquals(results.count(), 1)
        # The results should have 11 items. 10 for the products that already
        # exists, and 1 more for the one we created
        self.assertEquals(len(list(results)), 11)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        self.assertEquals(len(list(results)), 1)
Esempio n. 8
0
    def test_stock_cost(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.stock_cost, 10)

        branch = get_current_branch(self.store)
        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.stock_cost, 0)
Esempio n. 9
0
    def test_select_by_branch(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        self.failUnless(list(results))
        # FIXME: Storm does not support count() with group_by
        # self.assertEquals(results.count(), 1)
        # The results should have 11 items. 10 for the products that already
        # exists, and 1 more for the one we created
        self.assertEquals(len(list(results)), 11)

        results = ProductFullStockView.find_by_branch(self.store, branch)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        self.assertEquals(len(list(results)), 1)
Esempio n. 10
0
    def test_stock_cost(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.assertTrue(list(results))
        pv = results[0]
        self.assertEqual(pv.stock_cost, 10)

        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p2.id)
        self.assertTrue(list(results))
        pv = results[0]
        self.assertEqual(pv.stock_cost, 0)
Esempio n. 11
0
    def test_unit_description(self):
        p1 = self.create_product()
        p1.sellable.unit = self.create_sellable_unit()
        p1.sellable.unit.description = u"kg"

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(self.store, None)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        product_view = results[0]
        self.assertEquals(product_view.get_unit_description(), u"kg")

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        product_view = results[0]
        self.assertEquals(product_view.get_unit_description(), u"un")
Esempio n. 12
0
    def testStockCost(self):
        branch = self.create_branch()
        p1 = self.create_product(branch=branch, stock=1)

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.stock_cost, 10)

        branch = get_current_branch(self.store)
        results = ProductFullStockView.find_by_branch(
            self.store, None).find(ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        pv = results[0]
        self.assertEquals(pv.stock_cost, 0)
Esempio n. 13
0
    def test_get_product_and_category_description(self):
        p1 = self.create_product()
        p1.sellable.category = self.create_sellable_category()
        p1.sellable.category.description = u"category"

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        desc = pv.get_product_and_category_description()
        self.assertEquals(desc, u"[category] Description")

        results = ProductFullStockView.find_by_branch(self.store, None).find(ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        pv = results[0]
        desc = pv.get_product_and_category_description()
        self.assertEquals(desc, u"Description")
Esempio n. 14
0
    def test_unit_description(self):
        p1 = self.create_product()
        p1.sellable.unit = self.create_sellable_unit()
        p1.sellable.unit.description = u"kg"

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(self.store, None)
        results = results.find(ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        product_view = results[0]
        self.assertEquals(product_view.unit_description, u"kg")

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        product_view = results[0]
        self.assertEquals(product_view.unit_description, u"un")
Esempio n. 15
0
    def test_get_product_and_category_description(self):
        p1 = self.create_product()
        p1.sellable.category = self.create_sellable_category()
        p1.sellable.category.description = u"category"

        p2 = self.create_product()

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p1.id)
        self.failUnless(list(results))
        pv = results[0]
        desc = pv.get_product_and_category_description()
        self.assertEquals(desc, u"[category] Description")

        results = ProductFullStockView.find_by_branch(self.store, None).find(
            ProductFullStockView.product_id == p2.id)
        self.failUnless(list(results))
        pv = results[0]
        desc = pv.get_product_and_category_description()
        self.assertEquals(desc, u"Description")
Esempio n. 16
0
    def test_highjacked_equality(self):
        self.clean_domain([StockTransactionHistory, ProductStockItem, Storable, ProductSupplierInfo, Product])

        branch = self.create_branch()
        self.create_product(branch=branch, stock=1)

        res = self.store.find(ProductFullStockView)
        res_by_branch = ProductFullStockView.find_by_branch(self.store, branch)

        self.assertEqual(res[0], res_by_branch[0])
        self.assertEqual(res_by_branch[0], res[0])

        product = self.create_product()
        other_viewable = self.store.find(ProductFullStockView, Sellable.id == product.sellable.id).one()
        self.assertNotEqual(res[0], other_viewable)
        self.assertNotEqual(res[0], object())
Esempio n. 17
0
    def test_highjacked_equality(self):
        self.clean_domain([StockTransactionHistory, ProductStockItem, Storable,
                           ProductSupplierInfo, Product])

        branch = self.create_branch()
        self.create_product(branch=branch, stock=1)

        res = self.store.find(ProductFullStockView)
        res_by_branch = ProductFullStockView.find_by_branch(self.store, branch)

        self.assertEqual(res[0], res_by_branch[0])
        self.assertEqual(res_by_branch[0], res[0])

        product = self.create_product()
        other_viewable = self.store.find(
            ProductFullStockView, Sellable.id == product.sellable.id).one()
        self.assertNotEqual(res[0], other_viewable)
        self.assertNotEqual(res[0], object())