Reviewers: ,
Please review this at http://codereview.tryton.org/558002/
Affected files:
M product.py
M tests/test_stock.py
Index: product.py
===================================================================
--- a/product.py
+++ b/product.py
@@ -505,16 +505,21 @@
if location.parent.id in leafs:
leafs.remove(location.parent.id)
parent[location.id] = location.parent.id
-
+ locations = set((l.id for l in locations))
while leafs:
- next_leafs = set()
for l in leafs:
+ locations.remove(l)
if l not in parent:
continue
- next_leafs.add(parent[l])
for product in res_product_ids:
res.setdefault((parent[l], product), 0)
res[(parent[l], product)] += res.get((l, product),
0)
+ next_leafs = set(locations)
+ for l in locations:
+ if l not in parent:
+ continue
+ if parent[l] in next_leafs and parent[l] in locations:
+ next_leafs.remove(parent[l])
leafs = next_leafs
# clean result
Index: tests/test_stock.py
===================================================================
--- a/tests/test_stock.py
+++ b/tests/test_stock.py
@@ -317,6 +317,61 @@
self.period.close([period])
test_products_by_location()
+ # Test with_childs
+ with Transaction().start(DB_NAME, USER,
+ context=CONTEXT) as transaction:
+ company, = self.company.search([('name', '=', 'B2CK')])
+ self.user.write([self.user(USER)], {
+ 'main_company': company.id,
+ 'company': company.id,
+ })
+
+ unit, = self.uom.search([('name', '=', 'Unit')])
+ product = self.product.create({
+ 'name': 'Test products_by_location',
+ 'type': 'goods',
+ 'list_price': Decimal(0),
+ 'cost_price': Decimal(0),
+ 'cost_price_method': 'fixed',
+ 'default_uom': unit.id,
+ })
+
+ lost_found, =
self.location.search([('type', '=', 'lost_found')])
+ warehouse, = self.location.search([('type', '=', 'warehouse')])
+ storage, = self.location.search([('code', '=', 'STO')])
+ storage1 = self.location.create({
+ 'name': 'Storage 1',
+ 'type': 'view',
+ 'parent': storage.id,
+ })
+ self.location.create({
+ 'name': 'Storage 1.1',
+ 'type': 'storage',
+ 'parent': storage1.id,
+ })
+ self.location.create({
+ 'name': 'Storage 2',
+ 'type': 'view',
+ 'parent': storage.id,
+ })
+
+ self.move.create({
+ 'product': product.id,
+ 'uom': unit.id,
+ 'quantity': 1,
+ 'from_location': lost_found.id,
+ 'to_location': storage.id,
+ 'planned_date': today,
+ 'effective_date': today,
+ 'state': 'done',
+ 'company': company.id,
+ })
+
+ products_by_location = self.product.products_by_location(
+ [warehouse.id], [product.id], with_childs=True)
+ self.assertEqual(products_by_location[(warehouse.id,
product.id)],
+ 1)
+
def test0030period(self):
'''
Test period.
--
[email protected] mailing list