|
|
@ -1,7 +1,8 @@ |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
from openerp.tests import common |
|
|
|
from odoo import api, SUPERUSER_ID |
|
|
|
from odoo.tests import common |
|
|
|
|
|
|
|
|
|
|
|
class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
@ -10,9 +11,10 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
"""*****setUp*****""" |
|
|
|
super(PartnerContactInSeveralCompaniesCase, self).setUp() |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
ModelData = self.registry('ir.model.data') |
|
|
|
self.partner = self.registry('res.partner') |
|
|
|
self.action = self.registry('ir.actions.act_window') |
|
|
|
env = api.Environment(cr, SUPERUSER_ID, {}) |
|
|
|
ModelData = env['ir.model.data'] |
|
|
|
self.partner = env['res.partner'] |
|
|
|
self.action = env['ir.actions.act_window'] |
|
|
|
|
|
|
|
# Get test records reference |
|
|
|
for attr, module, name in [ |
|
|
@ -32,7 +34,7 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
'partner_contact_in_several_companies', |
|
|
|
'action_partner_form'), |
|
|
|
]: |
|
|
|
r = ModelData.get_object_reference(cr, uid, module, name) |
|
|
|
r = ModelData.get_object_reference(module, name) |
|
|
|
setattr(self, attr, r[1] if r else False) |
|
|
|
|
|
|
|
def test_00_show_only_standalone_contact(self): |
|
|
@ -43,7 +45,7 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': False |
|
|
|
}} |
|
|
|
partner_ids = self.partner.search(cr, uid, [], context=ctx) |
|
|
|
partner_ids = self.partner.search([]) |
|
|
|
partner_ids.sort() |
|
|
|
self.assertTrue(self.bob_job1_id not in partner_ids) |
|
|
|
self.assertTrue(self.roger_job2_id not in partner_ids) |
|
|
@ -53,21 +55,20 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
explicitly state to display all positions or the "is_set" |
|
|
|
value has been set to False. |
|
|
|
""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
|
|
|
|
partner_ids = self.partner.search(cr, uid, [], context=None) |
|
|
|
partner_ids = self.partner.search([]) |
|
|
|
self.assertTrue(self.bob_job1_id in partner_ids) |
|
|
|
self.assertTrue(self.roger_job2_id in partner_ids) |
|
|
|
|
|
|
|
ctx = {'search_show_all_positions': {'is_set': False}} |
|
|
|
partner_ids = self.partner.search(cr, uid, [], context=ctx) |
|
|
|
partner_ids = self.partner.search([]) |
|
|
|
self.assertTrue(self.bob_job1_id in partner_ids) |
|
|
|
self.assertTrue(self.roger_job2_id in partner_ids) |
|
|
|
|
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': True |
|
|
|
}} |
|
|
|
partner_ids = self.partner.search(cr, uid, [], context=ctx) |
|
|
|
partner_ids = self.partner.search([]) |
|
|
|
self.assertTrue(self.bob_job1_id in partner_ids) |
|
|
|
self.assertTrue(self.roger_job2_id in partner_ids) |
|
|
|
|
|
|
@ -75,16 +76,14 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
"""Check that readonly partner's ``other_contact_ids`` return |
|
|
|
all values whatever the context |
|
|
|
""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
|
|
|
|
def read_other_contacts(pid, context=None): |
|
|
|
return self.partner.read( |
|
|
|
cr, uid, [pid], ['other_contact_ids'], |
|
|
|
context=context)[0]['other_contact_ids'] |
|
|
|
cr, uid, [pid], ['other_contact_ids'])[0]['other_contact_ids'] |
|
|
|
|
|
|
|
def read_contacts(pid, context=None): |
|
|
|
return self.partner.read( |
|
|
|
cr, uid, [pid], ['child_ids'], context=context)[0]['child_ids'] |
|
|
|
[pid], ['child_ids'])[0]['child_ids'] |
|
|
|
|
|
|
|
ctx = None |
|
|
|
self.assertEqual( |
|
|
@ -93,63 +92,59 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': False}} |
|
|
|
self.assertEqual(read_other_contacts( |
|
|
|
self.bob_contact_id, context=ctx), |
|
|
|
self.bob_contact_id), |
|
|
|
[self.bob_job1_id], |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': False |
|
|
|
}} |
|
|
|
self.assertEqual(read_other_contacts( |
|
|
|
self.bob_contact_id, context=ctx), |
|
|
|
self.bob_contact_id,), |
|
|
|
[self.bob_job1_id], |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': True |
|
|
|
}} |
|
|
|
self.assertEqual( |
|
|
|
read_other_contacts(self.bob_contact_id, context=ctx), |
|
|
|
read_other_contacts(self.bob_contact_id), |
|
|
|
[self.bob_job1_id], |
|
|
|
) |
|
|
|
|
|
|
|
ctx = None |
|
|
|
self.assertIn( |
|
|
|
self.bob_job1_id, |
|
|
|
read_contacts(self.main_partner_id, context=ctx), |
|
|
|
read_contacts(self.main_partner_id), |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': False}} |
|
|
|
self.assertIn( |
|
|
|
self.bob_job1_id, |
|
|
|
read_contacts(self.main_partner_id, context=ctx), |
|
|
|
read_contacts(self.main_partner_id), |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': False |
|
|
|
}} |
|
|
|
self.assertIn( |
|
|
|
self.bob_job1_id, |
|
|
|
read_contacts(self.main_partner_id, context=ctx), |
|
|
|
read_contacts(self.main_partner_id), |
|
|
|
) |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': True |
|
|
|
}} |
|
|
|
self.assertIn( |
|
|
|
self.bob_job1_id, |
|
|
|
read_contacts(self.main_partner_id, context=ctx), |
|
|
|
read_contacts(self.main_partner_id), |
|
|
|
) |
|
|
|
|
|
|
|
def test_03_search_match_attached_contacts(self): |
|
|
|
"""Check that searching partner also return partners having |
|
|
|
attached contacts matching search criteria |
|
|
|
""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
# Bob's contact has one other position which is related to |
|
|
|
# 'YourCompany' |
|
|
|
# so search for all contacts working for 'YourCompany' |
|
|
|
# should contain Bob position. |
|
|
|
partner_ids = self.partner.search( |
|
|
|
cr, uid, |
|
|
|
[('parent_id', 'ilike', 'YourCompany')], |
|
|
|
context=None |
|
|
|
) |
|
|
|
[('parent_id', 'ilike', 'YourCompany')]) |
|
|
|
self.assertIn(self.bob_job1_id, partner_ids, ) |
|
|
|
|
|
|
|
# but when searching without 'all positions', |
|
|
@ -158,18 +153,14 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
'set_value': False |
|
|
|
}} |
|
|
|
partner_ids = self.partner.search( |
|
|
|
cr, uid, |
|
|
|
[('parent_id', 'ilike', 'YourCompany')], |
|
|
|
context=ctx |
|
|
|
) |
|
|
|
[('parent_id', 'ilike', 'YourCompany')]) |
|
|
|
self.assertIn(self.bob_contact_id, partner_ids, ) |
|
|
|
|
|
|
|
def test_04_contact_creation(self): |
|
|
|
"""Check that we're begin to create a contact""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
|
|
|
|
# Create a contact using only name |
|
|
|
new_contact_id = self.partner.create(cr, uid, {'name': 'Bob Egnops'}) |
|
|
|
new_contact_id = self.partner.create({'name': 'Bob Egnops'}) |
|
|
|
self.assertEqual( |
|
|
|
self.partner.browse(cr, uid, new_contact_id).contact_type, |
|
|
|
'standalone', |
|
|
@ -177,26 +168,26 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
|
|
|
|
# Create a contact with only contact_id |
|
|
|
new_contact_id = self.partner.create( |
|
|
|
cr, uid, {'contact_id': self.bob_contact_id} |
|
|
|
{'contact_id': self.bob_contact_id} |
|
|
|
) |
|
|
|
new_contact = self.partner.browse(cr, uid, new_contact_id) |
|
|
|
new_contact = self.partner.browse(new_contact_id) |
|
|
|
self.assertEqual(new_contact.name, 'Bob Egnops') |
|
|
|
self.assertEqual(new_contact.contact_type, 'attached') |
|
|
|
|
|
|
|
# Create a contact with both contact_id and name; |
|
|
|
# contact's name should override provided value in that case |
|
|
|
new_contact_id = self.partner.create( |
|
|
|
cr, uid, {'contact_id': self.bob_contact_id, 'name': 'Rob Egnops'} |
|
|
|
{'contact_id': self.bob_contact_id, 'name': 'Rob Egnops'} |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
self.partner.browse(cr, uid, new_contact_id).name, |
|
|
|
self.partner.browse(new_contact_id).name, |
|
|
|
'Bob Egnops' |
|
|
|
) |
|
|
|
|
|
|
|
# Reset contact to standalone |
|
|
|
self.partner.write(cr, uid, [new_contact_id], {'contact_id': False}) |
|
|
|
self.assertEqual( |
|
|
|
self.partner.browse(cr, uid, new_contact_id).contact_type, |
|
|
|
self.partner.browse(new_contact_id).contact_type, |
|
|
|
'standalone', |
|
|
|
) |
|
|
|
|
|
|
@ -207,9 +198,9 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
ctx = {'search_show_all_positions': {'is_set': True, |
|
|
|
'set_value': True |
|
|
|
}} |
|
|
|
self.partner.unlink(cr, uid, [new_contact_id], context=ctx) |
|
|
|
self.partner.unlink([new_contact_id]) |
|
|
|
partner_ids = self.partner.search( |
|
|
|
cr, uid, [('id', 'in', [new_contact_id, self.bob_contact_id])]) |
|
|
|
[('id', 'in', [new_contact_id, self.bob_contact_id])]) |
|
|
|
self.assertIn(self.bob_contact_id, partner_ids) |
|
|
|
self.assertNotIn(new_contact_id, partner_ids) |
|
|
|
|
|
|
@ -217,34 +208,32 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
"""Check that contact's fields are correctly synced between |
|
|
|
parent contact or related contacts |
|
|
|
""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
|
|
|
|
# Test DOWNSTREAM sync |
|
|
|
self.partner.write( |
|
|
|
cr, uid, [self.bob_contact_id], {'name': 'Rob Egnops'} |
|
|
|
[self.bob_contact_id], {'name': 'Rob Egnops'} |
|
|
|
) |
|
|
|
self.assertEqual( |
|
|
|
self.partner.browse(cr, uid, self.bob_job1_id).name, |
|
|
|
self.partner.browse(self.bob_job1_id).name, |
|
|
|
'Rob Egnops', |
|
|
|
) |
|
|
|
|
|
|
|
# Test UPSTREAM sync |
|
|
|
self.partner.write(cr, uid, [self.bob_job1_id], {'name': 'Bob Egnops'}) |
|
|
|
self.partner.write([self.bob_job1_id], {'name': 'Bob Egnops'}) |
|
|
|
self.assertEqual( |
|
|
|
self.partner.browse(cr, uid, self.bob_contact_id).name, |
|
|
|
self.partner.browse(self.bob_contact_id).name, |
|
|
|
'Bob Egnops', |
|
|
|
) |
|
|
|
|
|
|
|
def test_06_ir_action(self): |
|
|
|
"""Check ir_action context is auto updated. |
|
|
|
""" |
|
|
|
cr, uid = self.cr, self.uid |
|
|
|
|
|
|
|
new_context_val = "'search_show_all_positions': " \ |
|
|
|
"{'is_set': True, 'set_value': False}," |
|
|
|
|
|
|
|
details = self.action.read( |
|
|
|
cr, uid, [self.base_partner_action_id] |
|
|
|
[self.base_partner_action_id] |
|
|
|
) |
|
|
|
self.assertIn( |
|
|
|
new_context_val, |
|
|
@ -253,7 +242,7 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): |
|
|
|
) |
|
|
|
|
|
|
|
details = self.action.read( |
|
|
|
cr, uid, [self.custom_partner_action_id] |
|
|
|
[self.custom_partner_action_id] |
|
|
|
) |
|
|
|
self.assertNotIn( |
|
|
|
new_context_val, |
|
|
|