trytond-party_company/employee.py.back

47 lines
1.6 KiB
Plaintext

# 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:])]