2017-05-25 15:59:45 +02:00
|
|
|
# This file is part party_company module for Tryton.
|
|
|
|
# The COPYRIGHT file at the top level of this repository contains
|
|
|
|
# the full copyright notices and license terms.
|
|
|
|
import unittest
|
|
|
|
import trytond.tests.test_tryton
|
|
|
|
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
|
|
|
from trytond.pool import Pool
|
2017-05-26 13:46:50 +02:00
|
|
|
from trytond.modules.company.tests import create_company, set_company
|
2017-05-25 15:59:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PartyCompanyTestCase(ModuleTestCase):
|
|
|
|
'Test Party Company module'
|
|
|
|
module = 'party_company'
|
|
|
|
|
2017-05-26 13:46:50 +02:00
|
|
|
@with_transaction()
|
|
|
|
def test_party(self):
|
|
|
|
'Create party'
|
|
|
|
pool = Pool()
|
|
|
|
Party = pool.get('party.party')
|
|
|
|
|
|
|
|
party1, = Party.create([{
|
|
|
|
'name': 'Party 1',
|
|
|
|
}])
|
|
|
|
self.assert_(party1.id)
|
2017-11-24 14:51:35 +01:00
|
|
|
self.assertEqual(party1.companies, ())
|
2017-05-26 13:46:50 +02:00
|
|
|
|
|
|
|
@with_transaction()
|
|
|
|
def test_party_company(self):
|
|
|
|
'Create party company'
|
|
|
|
pool = Pool()
|
|
|
|
Party = pool.get('party.party')
|
2017-06-20 16:31:22 +02:00
|
|
|
Address = pool.get('party.address')
|
2017-11-24 14:51:35 +01:00
|
|
|
User = pool.get('res.user')
|
2017-05-26 13:46:50 +02:00
|
|
|
|
|
|
|
company = create_company()
|
|
|
|
with set_company(company):
|
2017-11-24 14:51:35 +01:00
|
|
|
party = Party()
|
|
|
|
party.name = 'Party 2'
|
|
|
|
party.companies = [company]
|
|
|
|
party.save()
|
2017-06-20 16:31:22 +02:00
|
|
|
self.assert_(party.id)
|
2017-11-24 14:51:35 +01:00
|
|
|
self.assertEqual(len(party.companies), 1)
|
2017-06-20 16:31:22 +02:00
|
|
|
address, = Address.create([{
|
|
|
|
'party': party.id,
|
|
|
|
'street': 'St sample, 15',
|
|
|
|
'city': 'City',
|
|
|
|
}])
|
2017-11-24 14:51:35 +01:00
|
|
|
self.assertEqual(address.companies == (company,), True)
|
2017-05-26 13:46:50 +02:00
|
|
|
|
2017-06-20 16:31:22 +02:00
|
|
|
address1, address2 = Address.search([])
|
2017-11-24 14:51:35 +01:00
|
|
|
self.assertEqual(address1.companies, ())
|
|
|
|
self.assertEqual(address2.companies == (company,), True)
|
2017-05-26 13:46:50 +02:00
|
|
|
|
2017-05-25 15:59:45 +02:00
|
|
|
def suite():
|
|
|
|
suite = trytond.tests.test_tryton.suite()
|
|
|
|
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
|
|
|
|
PartyCompanyTestCase))
|
|
|
|
return suite
|