trytond-patches/issue53451002_1_10001.diff

104 lines
5.3 KiB
Diff

Index: diloy/trytond/trytond/modules/stock/move.py
===================================================================
--- diloy.orig/trytond/trytond/modules/stock/move.py
+++ diloy/trytond/trytond/modules/stock/move.py
@@ -854,7 +854,6 @@ class Move(Workflow, ModelSQL, ModelView
])
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)))
companies = {m.company for m in moves}
@@ -982,7 +981,8 @@ class Move(Workflow, ModelSQL, ModelView
@classmethod
def compute_quantities_query(cls, location_ids, with_childs=False,
- grouping=('product',), grouping_filter=None):
+ grouping=('product',), grouping_filter=None,
+ quantity_field='internal_quantity'):
"""
Prepare a query object to compute for each location and product the
stock quantity in the default uom of the product.
@@ -1000,6 +1000,8 @@ class Move(Workflow, ModelSQL, ModelView
stock_skip_warehouse: if set, quantities on a warehouse are no more
quantities of all child locations but quantities of the storage
zone.
+ quantity_field: Is the name of the field containing the quantity to
+ be aggregated
If with_childs, it computes also for child locations.
grouping is a tuple of Move (or Product if prefixed by 'product.')
field names and defines how stock moves are grouped.
@@ -1052,7 +1054,7 @@ class Move(Workflow, ModelSQL, ModelView
if use_product:
product = Product.__table__()
columns = ['id', 'state', 'effective_date', 'planned_date',
- 'internal_quantity', 'from_location', 'to_location', 'company']
+ quantity_field, 'from_location', 'to_location', 'company']
columns += [c for c in grouping if c not in columns]
columns = [get_column(c, move, product) for c in columns]
move = (move
@@ -1066,7 +1068,7 @@ class Move(Workflow, ModelSQL, ModelView
period_table = Period.__table__()
if use_product:
product_cache = Product.__table__()
- columns = ['internal_quantity', 'period', 'location']
+ columns = [quantity_field, 'period', 'location']
columns += [c for c in grouping if c not in columns]
columns = [get_column(c, period_cache, product_cache)
for c in columns]
@@ -1087,7 +1089,7 @@ class Move(Workflow, ModelSQL, ModelView
to_location = Location.__table__()
to_parent_location = Location.__table__()
columns = ['id', 'state', 'effective_date', 'planned_date',
- 'internal_quantity', 'company']
+ quantity_field, 'company']
columns += [c for c in grouping if c not in columns]
columns = [Column(move, c).as_(c) for c in columns]
@@ -1142,7 +1144,7 @@ class Move(Workflow, ModelSQL, ModelView
if PeriodCache:
location = Location.__table__()
parent_location = Location.__table__()
- columns = ['internal_quantity', 'period'] + list(grouping)
+ columns = [quantity_field, 'period'] + list(grouping)
columns = [Column(period_cache, c).as_(c) for c in columns]
period_cache = Union(
period_cache.select(
@@ -1341,7 +1343,7 @@ class Move(Workflow, ModelSQL, ModelView
move_keys_alias = [Column(move, key).as_(key) for key in grouping]
move_keys = [Column(move, key) for key in grouping]
query = move.select(move.to_location.as_('location'),
- Sum(move.internal_quantity).as_('quantity'),
+ Sum(getattr(move, quantity_field)).as_('quantity'),
*move_keys_alias,
where=state_date_clause_in
& where
@@ -1350,7 +1352,7 @@ class Move(Workflow, ModelSQL, ModelView
& dest_clause_from,
group_by=[move.to_location] + move_keys)
query = Union(query, move.select(move.from_location.as_('location'),
- (-Sum(move.internal_quantity)).as_('quantity'),
+ (-Sum(getattr(move, quantity_field))).as_('quantity'),
*move_keys_alias,
where=state_date_clause_out
& where
@@ -1364,7 +1366,7 @@ class Move(Workflow, ModelSQL, ModelView
for key in grouping]
query = Union(query, from_period.select(
period_cache.location.as_('location'),
- period_cache.internal_quantity.as_('quantity'),
+ getattr(period_cache, quantity_field).as_('quantity'),
*period_keys,
where=(period_cache.period
== (period.id if period else None))
@@ -1425,7 +1427,7 @@ class Move(Workflow, ModelSQL, ModelView
location = line[0]
key = tuple(line[1:-1])
quantity = line[-1]
- quantities[(location,) + key] += quantity
+ quantities[(location,) + key] += quantity or 0
ids.add(id_getter(line))
keys.add(key)