2019-05-02 09:58:17 +02:00
|
|
|
diff -r f95dbecc064f trytond/trytond/modules/stock/move.py
|
|
|
|
--- a/trytond/trytond/modules/stock/move.py Thu May 02 09:50:09 2019 +0200
|
|
|
|
+++ b/trytond/trytond/modules/stock/move.py Thu May 02 09:52:21 2019 +0200
|
|
|
|
@@ -904,7 +904,8 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
|
|
|
|
@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.
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -922,6 +923,8 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
stock_skip_warehouse: if set, quantities on a warehouse are no more
|
|
|
|
quantities of all child locations but quantities of the storage
|
|
|
|
zone.
|
2019-04-04 17:42:22 +02:00
|
|
|
+ quantity_field is the name of the field containing the quantity to
|
|
|
|
+ be aggregated.
|
2019-01-22 10:23:00 +01:00
|
|
|
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.
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -974,7 +977,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
if use_product:
|
|
|
|
product = Product.__table__()
|
|
|
|
columns = ['id', 'state', 'effective_date', 'planned_date',
|
|
|
|
- 'internal_quantity', 'from_location', 'to_location']
|
|
|
|
+ quantity_field, 'from_location', 'to_location']
|
2019-04-04 17:42:22 +02:00
|
|
|
columns += [c for c in grouping if c not in columns]
|
2019-01-22 10:23:00 +01:00
|
|
|
columns = [get_column(c, move, product) for c in columns]
|
|
|
|
move = (move
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -987,7 +990,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
period_cache = PeriodCache.__table__()
|
|
|
|
if use_product:
|
|
|
|
product_cache = Product.__table__()
|
|
|
|
- columns = ['internal_quantity', 'period', 'location']
|
|
|
|
+ columns = [quantity_field, 'period', 'location']
|
2019-04-04 17:42:22 +02:00
|
|
|
columns += [c for c in grouping if c not in columns]
|
2019-01-22 10:23:00 +01:00
|
|
|
columns = [get_column(c, period_cache, product_cache)
|
|
|
|
for c in columns]
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1004,7 +1007,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
to_location = Location.__table__()
|
|
|
|
to_parent_location = Location.__table__()
|
|
|
|
columns = ['id', 'state', 'effective_date', 'planned_date',
|
2019-04-04 17:42:22 +02:00
|
|
|
- 'internal_quantity']
|
|
|
|
+ quantity_field]
|
|
|
|
columns += [c for c in grouping if c not in columns]
|
2019-01-22 10:23:00 +01:00
|
|
|
columns = [Column(move, c).as_(c) for c in columns]
|
|
|
|
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1059,7 +1062,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
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(
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1257,7 +1260,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
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
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1267,7 +1270,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
& 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
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1282,7 +1285,7 @@
|
2019-01-22 10:23:00 +01:00
|
|
|
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))
|
2019-05-02 09:58:17 +02:00
|
|
|
@@ -1391,7 +1394,7 @@
|
|
|
|
for key, quantity in quantities.items():
|
|
|
|
location = key[0]
|
|
|
|
uom = default_uom[id_getter(key)]
|
|
|
|
- quantities[key] = uom.round(quantity)
|
2019-05-07 10:41:59 +02:00
|
|
|
+ quantities[key] = uom.round(quantity) if quantity else 0.0
|
2019-05-02 09:58:17 +02:00
|
|
|
|
|
|
|
return quantities
|