Use Function fields for all party.* models.
This commit is contained in:
parent
ff6cdca18f
commit
add33864a3
17
carrier.py
17
carrier.py
|
@ -1,21 +1,10 @@
|
|||
# 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 PoolMeta
|
||||
from trytond.model import ModelSQL, ModelView
|
||||
from . import party
|
||||
|
||||
__all__ = ['Carrier']
|
||||
|
||||
|
||||
class Carrier:
|
||||
class Carrier(ModelSQL, ModelView, party.PartyCompanyMixin):
|
||||
__name__ = 'carrier'
|
||||
__metaclass__ = PoolMeta
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'get_company', searcher='search_company_field')
|
||||
|
||||
def get_company(self, name):
|
||||
if self.party and self.party.company:
|
||||
return self.party.company.id
|
||||
|
||||
@classmethod
|
||||
def search_company_field(cls, name, clause):
|
||||
return [('party.company',) + tuple(clause[1:])]
|
||||
|
|
|
@ -1,21 +1,11 @@
|
|||
# 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 PoolMeta
|
||||
from . import party
|
||||
|
||||
__all__ = ['Agent']
|
||||
|
||||
|
||||
class Agent:
|
||||
class Agent(party.PartyCompanyMixin):
|
||||
__name__ = 'commission.agent'
|
||||
__metaclass__ = PoolMeta
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'get_company', searcher='search_company_field')
|
||||
|
||||
def get_company(self, name):
|
||||
if self.party and self.party.company:
|
||||
return self.party.company.id
|
||||
|
||||
@classmethod
|
||||
def search_company_field(cls, name, clause):
|
||||
return [('party.company',) + tuple(clause[1:])]
|
||||
|
|
53
party.py
53
party.py
|
@ -1,6 +1,6 @@
|
|||
# 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.model import fields, ModelView, ModelSQL
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import If, Eval
|
||||
|
@ -23,46 +23,25 @@ class Party:
|
|||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class Address:
|
||||
class PartyCompanyMixin:
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'get_company', searcher='search_company')
|
||||
|
||||
def get_company(self, name):
|
||||
return self.party.company.id if self.party.company else None
|
||||
|
||||
@classmethod
|
||||
def search_company(cls, name, clause):
|
||||
return [('party.company',) + tuple(clause[1:])]
|
||||
|
||||
|
||||
class Address(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
__name__ = 'party.address'
|
||||
__metaclass__ = PoolMeta
|
||||
company = fields.Many2One('company.company', 'Company',
|
||||
domain=[
|
||||
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
select=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class PartyIdentifier:
|
||||
class PartyIdentifier(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
__name__ = 'party.identifier'
|
||||
__metaclass__ = PoolMeta
|
||||
company = fields.Many2One('company.company', 'Company',
|
||||
domain=[
|
||||
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
select=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class ContactMechanism:
|
||||
class ContactMechanism(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
__name__ = 'party.contact_mechanism'
|
||||
__metaclass__ = PoolMeta
|
||||
company = fields.Many2One('company.company', 'Company',
|
||||
domain=[
|
||||
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
||||
Eval('context', {}).get('company', -1)),
|
||||
],
|
||||
select=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
|
Loading…
Reference in New Issue