From 90fc474338133f91e4b0d695552118afaa5cbbf5 Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Thu, 27 Sep 2018 16:14:28 +0200 Subject: [PATCH] Remove employee rule to allow user and user preferences change employee #035369 --- employee.py | 17 ++++++----------- employee.py.back | 46 ++++++++++++++++++++++++++++++++++++++++++++++ employee.xml | 20 ++------------------ 3 files changed, 54 insertions(+), 29 deletions(-) create mode 100644 employee.py.back diff --git a/employee.py b/employee.py index aaf1535..f7c3daf 100644 --- a/employee.py +++ b/employee.py @@ -1,7 +1,8 @@ # The COPYRIGHT file at the top level of this repository contains the full # copyright notices and license terms. -from trytond.pool import Pool, PoolMeta +from trytond.pool import PoolMeta from trytond.pyson import Eval, If +from trytond.transaction import Transaction __all__ = ['Employee'] @@ -17,13 +18,7 @@ class Employee(metaclass=PoolMeta): ] @classmethod - def search(cls, args, offset=0, limit=None, order=None, count=False, - query=False): - Rule = Pool().get('ir.rule') - # TODO clear domain cache because when an user change company (set preferences), - # the new domain cache is [u'company', u'=', None] and not return - # employees with company context. At the moment, search employees - # drop domain cache (clear) - Rule._domain_get_cache.clear() - return super(Employee, cls).search(args, offset, limit, order, - count, query) + def read(cls, ids, fields_names=None): + # Skip access rule + with Transaction().set_user(0): + return super(Employee, cls).read(ids, fields_names=fields_names) diff --git a/employee.py.back b/employee.py.back new file mode 100644 index 0000000..26d3235 --- /dev/null +++ b/employee.py.back @@ -0,0 +1,46 @@ +# The COPYRIGHT file at the top level of this repository contains the full +# copyright notices and license terms. +from trytond.pool import Pool, PoolMeta +from trytond.model import fields +from trytond.pyson import Eval, If + +__all__ = ['Employee', 'UserEmployee'] + + +class Employee: + __metaclass__ = PoolMeta + __name__ = 'company.employee' + + @classmethod + def __setup__(cls): + super(Employee, cls).__setup__() + cls.company.domain = [ + ('id', If(Eval('context', {}).contains('company'), '=', '!='), + Eval('context', {}).get('company', -1)), + ] + + @classmethod + def search(cls, args, offset=0, limit=None, order=None, count=False, + query=False): + Rule = Pool().get('ir.rule') + # TODO clear domain cache because when an user change company (set preferences), + # the new domain cache is [u'company', u'=', None] and not return + # employees with company context. At the moment, search employees + # drop domain cache (clear) + Rule._domain_get_cache.clear() + return super(Employee, cls).search(args, offset, limit, order, + count, query) + + +class UserEmployee: + __metaclass__ = PoolMeta + __name__ = 'res.user-company.employee' + company = fields.Function(fields.Many2One('company.company', + 'Company'), 'get_company', searcher='search_company') + + def get_company(self, name): + return employee.id if self.employee else None + + @classmethod + def search_company(cls, name, clause): + return [('employee.%s' % name,) + tuple(clause[1:])] diff --git a/employee.xml b/employee.xml index 6dd159c..de44164 100644 --- a/employee.xml +++ b/employee.xml @@ -3,26 +3,10 @@ this repository contains the full copyright notices and license terms. --> - - - - - + - - - - - - - - - -