changeset 36cc0671bb90 in modules/stock:default
details: https://hg.tryton.org/modules/stock?cmd=changeset;node=36cc0671bb90
description:
        Override warehouse with context value for current user

        issue9328
        review311541002
diffstat:

 CHANGELOG |   2 ++
 res.py    |  16 ++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diffs (39 lines):

diff -r eab80eaced1d -r 36cc0671bb90 CHANGELOG
--- a/CHANGELOG Tue May 19 18:45:29 2020 +0200
+++ b/CHANGELOG Tue May 19 18:57:21 2020 +0200
@@ -1,3 +1,5 @@
+* Override warehouse with context value for current user
+
 Version 5.6.0 - 2020-05-04
 * Bug fixes (see mercurial logs for details)
 * Add visual on product and location quantities
diff -r eab80eaced1d -r 36cc0671bb90 res.py
--- a/res.py    Tue May 19 18:45:29 2020 +0200
+++ b/res.py    Tue May 19 18:57:21 2020 +0200
@@ -2,6 +2,7 @@
 # this repository contains the full copyright notices and license terms.
 from trytond.model import fields
 from trytond.pool import PoolMeta, Pool
+from trytond.transaction import Transaction
 
 
 class User(metaclass=PoolMeta):
@@ -33,3 +34,18 @@
                 and len(Location.search([('type', '=', 'warehouse')])) > 1):
             status += ' - %s' % self.warehouse.rec_name
         return status
+
+    @classmethod
+    def read(cls, ids, fields_names):
+        context = Transaction().context
+        user_id = Transaction().user
+        if user_id == 0 and 'user' in Transaction().context:
+            user_id = Transaction().context['user']
+        result = super().read(ids, fields_names)
+        if ('warehouse' in fields_names
+                and context.get('warehouse')
+                and user_id in ids):
+            for values in result:
+                if values['id'] == user_id:
+                    values['warehouse'] = context['warehouse']
+        return result

Reply via email to