changeset d7020b46d6e2 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=d7020b46d6e2
description:
Read products and uoms in bunch to compute internal quantity at creation
issue8861
review256291002
diffstat:
move.py | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diffs (29 lines):
diff -r a1dffeba1a03 -r d7020b46d6e2 move.py
--- a/move.py Sat Dec 07 16:08:54 2019 +0100
+++ b/move.py Wed Dec 11 19:38:57 2019 +0100
@@ -647,14 +647,20 @@
Uom = pool.get('product.uom')
vlist = [x.copy() for x in vlist]
+ # Use ordered dict to optimize cache alignment
+ products, uoms = OrderedDict(), OrderedDict()
+ for vals in vlist:
+ products[vals['product']] = None
+ uoms[vals['uom']] = None
+ id2product = {p.id: p for p in Product.browse(products.keys())}
+ id2uom = {u.id: u for u in Uom.browse(uoms.keys())}
for vals in vlist:
assert vals.get('state', cls.default_state()
) in ['draft', 'staging']
-
- product = Product(vals['product'])
- uom = Uom(vals['uom'])
- internal_quantity = cls._get_internal_quantity(vals['quantity'],
- uom, product)
+ product = id2product[vals['product']]
+ uom = id2uom[vals['uom']]
+ internal_quantity = cls._get_internal_quantity(
+ vals['quantity'], uom, product)
vals['internal_quantity'] = internal_quantity
moves = super(Move, cls).create(vlist)
cls.check_period_closed(moves)