This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathres.py
51 lines (43 loc) · 1.77 KB
/
res.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
class User(metaclass=PoolMeta):
__name__ = 'res.user'
warehouse = fields.Many2One('stock.location',
"Current Warehouse",
domain=[('type', '=', 'warehouse')],
help="The warehouse that the user works at.")
@classmethod
def __setup__(cls):
super(User, cls).__setup__()
cls._context_fields.insert(0, 'warehouse')
@classmethod
def _get_preferences(cls, user, context_only=False):
preferences = super()._get_preferences(user, context_only=context_only)
if user.warehouse:
preferences['warehouse'] = user.warehouse.id
return preferences
def get_status_bar(self, name):
pool = Pool()
Location = pool.get('stock.location')
status = super().get_status_bar(name)
if (self.warehouse
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