Add companies in context

Since 9a8805f
#048723
This commit is contained in:
Raimon Esteve 2022-01-10 18:22:59 +01:00
parent 7005593040
commit 264297b4d1
2 changed files with 23 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from . import bank
from . import employee
from . import carrier
from . import party
from . import user
def register():
Pool.register(
@ -17,6 +17,7 @@ def register():
party.Address,
party.PartyIdentifier,
party.ContactMechanism,
user.User,
module='party_company', type_='model')
Pool.register(
activity.Activity,

21
user.py Normal file
View File

@ -0,0 +1,21 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import PoolMeta
class User(metaclass=PoolMeta):
__name__ = 'res.user'
@classmethod
def __setup__(cls):
super(User, cls).__setup__()
if not 'companies' in cls._context_fields:
cls._context_fields.insert(0, 'companies')
@classmethod
def _get_preferences(cls, user, context_only=False):
res = super(User, cls)._get_preferences(user,
context_only=context_only)
if not res.get('companies'):
res['companies'] = [c.id for c in user.companies]
return res