trytond-patches/improve_performance_on_try_...

45 lines
1.7 KiB
Diff

diff -r e8f62a19c157 move.py
--- a/trytond/trytond/modules/stock/move.py Wed Feb 06 18:07:58 2019 +0100
+++ b/trytond/trytond/modules/stock/move.py Wed Feb 06 18:10:11 2019 +0100
@@ -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()
@@ -1447,13 +1448,28 @@
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)]
- quantities[key] = uom.round(quantity)
+ uom = Uom(default_uom[id_getter(key)])
+ quantities[key] = uom.round(float(quantity))
return quantities