changeset 617b75bbdae5 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=617b75bbdae5
description:
        Add relates for lots

        - relate from lot to locations quantity
        - relate from product/template to lots by warehouse

        issue9504
        review298351002
diffstat:

 location.py |  31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

diffs (62 lines):

diff -r b3a812230160 -r 617b75bbdae5 location.py
--- a/location.py       Fri Oct 09 19:09:06 2020 +0200
+++ b/location.py       Sun Oct 11 16:05:16 2020 +0200
@@ -333,6 +333,20 @@
             ]
 
     @classmethod
+    def _get_quantity_grouping(cls):
+        context = Transaction().context
+        grouping, grouping_filter, key = (), (), []
+        if context.get('product') is not None:
+            grouping = ('product',)
+            grouping_filter = ([context['product']],)
+            key = (context['product'],)
+        elif context.get('product_template') is not None:
+            grouping = ('product.template',)
+            grouping_filter = ([context['product_template']],)
+            key = (context['product_template'],)
+        return grouping, grouping_filter, key
+
+    @classmethod
     def get_quantity(cls, locations, name):
         pool = Pool()
         Product = pool.get('product.product')
@@ -343,9 +357,6 @@
             return (trans_context.get(name) is not None
                 and isinstance(trans_context[name], int))
 
-        if not any(map(valid_context, ['product', 'product_template'])):
-            return {l.id: None for l in locations}
-
         context = {}
         if (name == 'quantity'
                 and (trans_context.get('stock_date_end', datetime.date.max)
@@ -357,14 +368,10 @@
             if not trans_context.get('stock_date_end'):
                 context['stock_date_end'] = datetime.date.max
 
-        if trans_context.get('product') is not None:
-            grouping = ('product',)
-            grouping_filter = ([trans_context['product']],)
-            key = trans_context['product']
-        else:
-            grouping = ('product.template',)
-            grouping_filter = ([trans_context['product_template']],)
-            key = trans_context['product_template']
+        grouping, grouping_filter, key = cls._get_quantity_grouping()
+        if not grouping:
+            return {loc.id: None for loc in locations}
+
         pbl = {}
         for sub_locations in grouped_slice(locations):
             location_ids = [l.id for l in sub_locations]
@@ -375,7 +382,7 @@
                         grouping_filter=grouping_filter,
                         with_childs=trans_context.get('with_childs', True)))
 
-        return dict((loc.id, pbl.get((loc.id, key), 0)) for loc in locations)
+        return dict((loc.id, pbl.get((loc.id,) + key, 0)) for loc in locations)
 
     @classmethod
     def search_quantity(cls, name, domain):

Reply via email to