2017-05-25 15:59:45 +02:00
|
|
|
# The COPYRIGHT file at the top level of this repository contains the full
|
|
|
|
# copyright notices and license terms.
|
2017-06-20 13:48:02 +02:00
|
|
|
from trytond.model import fields, ModelView, ModelSQL
|
2017-05-25 17:26:59 +02:00
|
|
|
from trytond.pool import PoolMeta
|
2017-05-25 15:59:45 +02:00
|
|
|
from trytond.transaction import Transaction
|
|
|
|
from trytond.pyson import If, Eval
|
|
|
|
|
|
|
|
__all__ = ['Party', 'Address', 'PartyIdentifier', 'ContactMechanism']
|
|
|
|
|
|
|
|
|
|
|
|
class Party:
|
|
|
|
__name__ = 'party.party'
|
|
|
|
__metaclass__ = PoolMeta
|
2017-05-25 17:22:06 +02:00
|
|
|
company = fields.Many2One('company.company', 'Company',
|
2017-05-25 15:59:45 +02:00
|
|
|
domain=[
|
|
|
|
('id', If(Eval('context', {}).contains('company'), '=', '!='),
|
|
|
|
Eval('context', {}).get('company', -1)),
|
|
|
|
],
|
|
|
|
select=True)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def default_company():
|
|
|
|
return Transaction().context.get('company')
|
|
|
|
|
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
class PartyCompanyMixin:
|
|
|
|
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
|
|
|
'get_company', searcher='search_company')
|
2017-05-25 15:59:45 +02:00
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
def get_company(self, name):
|
|
|
|
return self.party.company.id if self.party.company else None
|
2017-05-25 15:59:45 +02:00
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
@classmethod
|
|
|
|
def search_company(cls, name, clause):
|
|
|
|
return [('party.company',) + tuple(clause[1:])]
|
2017-05-25 15:59:45 +02:00
|
|
|
|
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
class Address(ModelSQL, ModelView, PartyCompanyMixin):
|
|
|
|
__name__ = 'party.address'
|
2017-05-25 15:59:45 +02:00
|
|
|
|
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
class PartyIdentifier(ModelSQL, ModelView, PartyCompanyMixin):
|
|
|
|
__name__ = 'party.identifier'
|
2017-05-25 15:59:45 +02:00
|
|
|
|
2017-06-20 13:48:02 +02:00
|
|
|
|
|
|
|
class ContactMechanism(ModelSQL, ModelView, PartyCompanyMixin):
|
|
|
|
__name__ = 'party.contact_mechanism'
|