trytond-patches/improve_performance_on_try_...

44 lines
1.6 KiB
Diff

diff -r 3239605d105d move.py
--- a/trytond/trytond/modules/stock/move.py Mon May 21 20:17:34 2018 +0200
+++ b/trytond/trytond/modules/stock/move.py Fri Jul 20 12:16:25 2018 +0200
@@ -850,6 +850,7 @@
])
else:
locations = list(set((m.from_location for m in moves)))
+
location_ids = [l.id for l in locations]
product_ids = list(set((m.product.id for m in moves)))
stock_date_end = Date.today()
@@ -1446,12 +1447,27 @@
if location not in location_ids:
del quantities[key]
- # Round quantities
- default_uom = dict((p.id, p.default_uom) for p in
- Model.browse(list(ids)))
+ Uom = Pool().get('product.uom')
+ ttemplate = Template.__table__()
+ table = Model.__table__()
+ cursor = Transaction().connection.cursor()
+
+ if Model == Template:
+ cursor.execute(*ttemplate.select(ttemplate.id,
+ ttemplate.default_uom,
+ where=reduce_ids(ttemplate.id, ids)))
+ else:
+ cursor.execute(*ttemplate.join(table,
+ condition=table.template == ttemplate.id).select(
+ table.id, ttemplate.default_uom,
+ where=reduce_ids(table.id, ids)))
+
+ default_uom = dict((x[0], x[1]) for x in
+ cursor.fetchall())
+
for key, quantity in quantities.iteritems():
location = key[0]
- uom = default_uom[id_getter(key)]
+ uom = Uom(default_uom[id_getter(key)])
quantities[key] = uom.round(quantity)
return quantities