Reviewers: ,
Please review this at http://codereview.tryton.org/562002/
Affected files:
M product.py
Index: product.py
===================================================================
--- a/product.py
+++ b/product.py
@@ -1,6 +1,7 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import datetime
+from collections import defaultdict
from decimal import Decimal
from trytond.model import ModelSQL, ModelView, fields
from trytond.wizard import Wizard, StateView, StateAction, Button
@@ -506,16 +507,19 @@
leafs.remove(location.parent.id)
parent[location.id] = location.parent.id
- while leafs:
- next_leafs = set()
- for l in leafs:
- if l not in parent:
- continue
- next_leafs.add(parent[l])
+ # bubble-up quantities
+ extra = defaultdict(float)
+ for l in leafs:
+ bubble = parent.get(l)
+ while bubble:
for product in res_product_ids:
- res.setdefault((parent[l], product), 0)
- res[(parent[l], product)] += res.get((l, product),
0)
- leafs = next_leafs
+ extra[(bubble, product)] += res.get((l, product),
0)
+ bubble = parent.get(bubble)
+
+ # Increment parents with childs quantities
+ for (location, product), qty in extra.iteritems():
+ res.setdefault((location, product), 0)
+ res[(location, product)] += qty
# clean result
for location, product in res.keys():
--
[email protected] mailing list