IMP other classes to use PartyCompanyMixin
From changeset-033bb5cdc41e
This commit is contained in:
parent
add33864a3
commit
f3310379e3
16
activity.py
16
activity.py
|
@ -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__ = ['Activity']
|
||||
|
||||
|
||||
class Activity:
|
||||
__name__ = "activity.activity"
|
||||
class Activity(object, party.PartyCompanyMixin):
|
||||
__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:])]
|
||||
__name__ = "activity.activity"
|
||||
|
|
17
bank.py
17
bank.py
|
@ -2,28 +2,19 @@
|
|||
# copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from . import party
|
||||
|
||||
__all__ = ['Bank', 'BankAccount']
|
||||
|
||||
|
||||
class Bank:
|
||||
__name__ = "bank"
|
||||
class Bank(object, party.PartyCompanyMixin):
|
||||
__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:])]
|
||||
__name__ = "bank"
|
||||
|
||||
|
||||
class BankAccount:
|
||||
__name__ = 'bank.account'
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'bank.account'
|
||||
company = fields.Function(fields.Many2One('company.company', 'Company'),
|
||||
'get_company', searcher='search_company_field')
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import ModelSQL, ModelView
|
||||
from trytond.pool import PoolMeta
|
||||
from . import party
|
||||
|
||||
__all__ = ['Carrier']
|
||||
|
||||
|
||||
class Carrier(ModelSQL, ModelView, party.PartyCompanyMixin):
|
||||
class Carrier(object, party.PartyCompanyMixin):
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'carrier'
|
||||
|
|
|
@ -6,6 +6,6 @@ from . import party
|
|||
__all__ = ['Agent']
|
||||
|
||||
|
||||
class Agent(party.PartyCompanyMixin):
|
||||
__name__ = 'commission.agent'
|
||||
class Agent(object, party.PartyCompanyMixin):
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'commission.agent'
|
||||
|
|
11
party.py
11
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, ModelView, ModelSQL
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import If, Eval
|
||||
|
@ -35,13 +35,16 @@ class PartyCompanyMixin:
|
|||
return [('party.company',) + tuple(clause[1:])]
|
||||
|
||||
|
||||
class Address(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
class Address(object, PartyCompanyMixin):
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.address'
|
||||
|
||||
|
||||
class PartyIdentifier(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
class PartyIdentifier(object, PartyCompanyMixin):
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.identifier'
|
||||
|
||||
|
||||
class ContactMechanism(ModelSQL, ModelView, PartyCompanyMixin):
|
||||
class ContactMechanism(object, PartyCompanyMixin):
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.contact_mechanism'
|
||||
|
|
|
@ -29,15 +29,25 @@ class PartyCompanyTestCase(ModuleTestCase):
|
|||
'Create party company'
|
||||
pool = Pool()
|
||||
Party = pool.get('party.party')
|
||||
Address = pool.get('party.address')
|
||||
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
party2, = Party.create([{
|
||||
party, = Party.create([{
|
||||
'name': 'Party 2',
|
||||
}])
|
||||
self.assert_(party2.id)
|
||||
self.assertNotEqual(party2.company, None)
|
||||
self.assert_(party.id)
|
||||
self.assertNotEqual(party.company, None)
|
||||
address, = Address.create([{
|
||||
'party': party.id,
|
||||
'street': 'St sample, 15',
|
||||
'city': 'City',
|
||||
}])
|
||||
self.assertEqual(address.company == company, True)
|
||||
|
||||
address1, address2 = Address.search([])
|
||||
self.assertEqual(address1.company, None)
|
||||
self.assertEqual(address2.company == company, True)
|
||||
|
||||
def suite():
|
||||
suite = trytond.tests.test_tryton.suite()
|
||||
|
|
Loading…
Reference in New Issue