Reviewers: ,


Please review this at http://codereview.tryton.org/897003/

Affected files:
  M tests/test_stock.py


Index: tests/test_stock.py
===================================================================

--- a/tests/test_stock.py
+++ b/tests/test_stock.py
@@ -377,7 +377,8 @@
         '''
         Test period.
         '''
-        with Transaction().start(DB_NAME, USER, context=CONTEXT):
+        with Transaction().start(DB_NAME, USER,
+                context=CONTEXT) as transaction:
             category, = self.category.create([{
                         'name': 'Test period',
                         }])
@@ -454,6 +455,33 @@
                 })
             ]

+ products_by_location = partial(self.product.products_by_location,
+                [storage.id], [product.id])
+            products_by_location_zero = partial(
+                    self.product.products_by_location,
+                    [storage.id], [product.id], skip_zero=False)
+
+            tests_pbl = [
+                ({'stock_date_end': today + relativedelta(days=-6)}, 0),
+                ({'stock_date_end': today + relativedelta(days=-5)}, 10),
+                ({'stock_date_end': today + relativedelta(days=-4)}, 25),
+                ({'stock_date_end': today + relativedelta(days=-3)}, 20),
+                ({'stock_date_end': today + relativedelta(days=-2)}, 20),
+                ({'stock_date_end': today}, 20),
+                ]
+
+            def test_products_by_location():
+                for context, quantity in tests_pbl:
+                    with transaction.set_context(context):
+                        if not quantity:
+                            self.assertEqual(products_by_location(), {})
+                            self.assertEqual(products_by_location_zero(),
+                                    {(storage.id, product.id): quantity})
+                        else:
+                            self.assertEqual(products_by_location(),
+                                    {(storage.id, product.id): quantity})
+
+            test_products_by_location()
             for days, quantities in tests:
                 period, = self.period.create([{
                             'date': today + relativedelta(days=days),
@@ -469,6 +497,8 @@
                     self.assertEqual(cache.internal_quantity,
                         quantities[cache.location.id])

+                test_products_by_location()
+
             # Test check_period_closed
             moves = self.move.create([{
                         'product': product.id,



Reply via email to