diff --git a/move.py b/move.py index 26aa9f4712..3739911e00 100644 --- a/move.py +++ b/move.py @@ -8,8 +8,9 @@ from decimal import Decimal from itertools import groupby from sql import Column, For, Literal, Null, Union -from sql.aggregate import Sum +from sql.aggregate import Max, Sum from sql.conditionals import Case, Coalesce +from sql.functions import Round from trytond.i18n import gettext from trytond.model import Check, Model, ModelSQL, ModelView, Workflow, fields @@ -118,6 +119,8 @@ class StockMixin(object): pool = Pool() Product = pool.get('product.product') Move = pool.get('stock.move') + Uom = pool.get('product.uom') + uom = Uom.__table__() if not location_ids or not domain: return [] @@ -135,7 +138,12 @@ class StockMixin(object): query = Move.compute_quantities_query( location_ids, with_childs, grouping=grouping) col_id = Column(query, grouping[position]) - quantity = Sum(query.quantity) + # We need to round the result to have same result as + # products_by_location but as we do not have the unit, we use + # the biggest digits of all unit as best approximation. + quantity = Round( + fields.Numeric('quantity').sql_cast(Sum(query.quantity)), + uom.select(Max(uom.digits))) group_by = [Column(query, key).as_(key) for key in grouping] return [('id', 'in', query.select( col_id,