diff --git a/partner_contact_in_several_companies/README.rst b/partner_contact_in_several_companies/README.rst index 18d9a8d8c..1ea21d6b2 100644 --- a/partner_contact_in_several_companies/README.rst +++ b/partner_contact_in_several_companies/README.rst @@ -32,7 +32,7 @@ For further information, please visit: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/134/9.0 + :target: https://runbot.odoo-community.org/runbot/134/10.0 Known issues / Roadmap ====================== @@ -48,7 +48,7 @@ In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. +10.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. Credits @@ -57,7 +57,7 @@ Credits Contributors ------------ -* Xavier ALT (original author) +* Xavier ALT (original author) * El Hadji Dem * TheCloneMaster * Sandy Carter @@ -65,6 +65,7 @@ Contributors * Sebastien Alix * Jairo Llopis * Richard deMeester +* Nicolas JEUDY Maintainer ---------- diff --git a/partner_contact_in_several_companies/__init__.py b/partner_contact_in_several_companies/__init__.py index a77a6fcbc..1765d7791 100644 --- a/partner_contact_in_several_companies/__init__.py +++ b/partner_contact_in_several_companies/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import models +import models diff --git a/partner_contact_in_several_companies/__manifest__.py b/partner_contact_in_several_companies/__manifest__.py index 9560f814f..1a544f1c7 100644 --- a/partner_contact_in_several_companies/__manifest__.py +++ b/partner_contact_in_several_companies/__manifest__.py @@ -4,12 +4,12 @@ { "name": "Contacts in several partners", "summary": "Allow to have one contact in several partners", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "category": "Customer Relationship Management", "website": "https://odoo-community.org/", "author": "Odoo Community Association (OCA)", "contributors": [ - 'Xavier ALT ', + 'Xavier ALT ', 'El Hadji Dem ', 'TheCloneMaster ', 'Sandy Carter ', @@ -17,10 +17,11 @@ 'Sebastien Alix ', 'Jairo Llopis ', 'Richard deMeester ', + 'Nicolas JEUDY ', ], "license": "AGPL-3", 'application': False, - 'installable': False, + 'installable': True, 'auto_install': False, "depends": [ "base", diff --git a/partner_contact_in_several_companies/models/__init__.py b/partner_contact_in_several_companies/models/__init__.py index 46c28af40..d1a721fbf 100644 --- a/partner_contact_in_several_companies/models/__init__.py +++ b/partner_contact_in_several_companies/models/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import res_partner, ir_actions +import res_partner, ir_actions diff --git a/partner_contact_in_several_companies/models/ir_actions.py b/partner_contact_in_several_companies/models/ir_actions.py index 756163aa1..fb0ba243a 100644 --- a/partner_contact_in_several_companies/models/ir_actions.py +++ b/partner_contact_in_several_companies/models/ir_actions.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, api +from odoo import models, api class IRActionsWindow(models.Model): diff --git a/partner_contact_in_several_companies/models/res_partner.py b/partner_contact_in_several_companies/models/res_partner.py index 580463498..8aadb9440 100644 --- a/partner_contact_in_several_companies/models/res_partner.py +++ b/partner_contact_in_several_companies/models/res_partner.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models, _, api -from openerp.osv import expression +from odoo import fields, models, _, api +from odoo.osv import expression class ResPartner(models.Model): @@ -12,8 +12,7 @@ class ResPartner(models.Model): [('standalone', _('Standalone Contact')), ('attached', _('Attached to existing Contact')), ], - compute='_get_contact_type', - required=True, select=1, store=True, + required=True, default='standalone') contact_id = fields.Many2one('res.partner', string='Main Contact', domain=[('is_company', '=', False), @@ -23,10 +22,10 @@ class ResPartner(models.Model): other_contact_ids = fields.One2many('res.partner', 'contact_id', string='Others Positions') - @api.one - @api.depends('contact_id') + @api.onchange('contact_id') def _get_contact_type(self): - self.contact_type = self.contact_id and 'attached' or 'standalone' + for record in self: + record.contact_type = record.contact_id and 'attached' or 'standalone' def _basecontact_check_context(self, mode): """ Remove 'search_show_all_positions' for non-search mode. @@ -115,8 +114,7 @@ class ResPartner(models.Model): self.ensure_one() if self.contact_id: contact_fields = self._contact_fields() - sync_vals = self._update_fields_values(self.contact_id, - contact_fields) + sync_vals = self._update_fields_values(contact_fields) self.write(sync_vals) def update_contact(self, vals): @@ -130,24 +128,24 @@ class ResPartner(models.Model): self.with_context(__update_contact_lock=True).write(contact_vals) @api.model - def _fields_sync(self, partner, update_values): + def _fields_sync(self, update_values): """Sync commercial fields and address fields from company and to children, contact fields from contact and to attached contact after create/update, just as if those were all modeled as fields.related to the parent """ - super(ResPartner, self)._fields_sync(partner, update_values) + super(ResPartner, self)._fields_sync(update_values) contact_fields = self._contact_fields() # 1. From UPSTREAM: sync from parent contact if update_values.get('contact_id'): - partner._contact_sync_from_parent() + self._contact_sync_from_parent() # 2. To DOWNSTREAM: sync contact fields to parent or related elif any(field in contact_fields for field in update_values): update_ids = [ - c.id for c in partner.other_contact_ids if not c.is_company + c.id for c in self.other_contact_ids if not c.is_company ] - if partner.contact_id: - update_ids.append(partner.contact_id.id) + if self.contact_id: + update_ids.append(self.contact_id.id) self.browse(update_ids).update_contact(update_values) @api.onchange('contact_id') diff --git a/partner_contact_in_several_companies/tests/__init__.py b/partner_contact_in_several_companies/tests/__init__.py index 8a8361492..a4bc591f5 100644 --- a/partner_contact_in_several_companies/tests/__init__.py +++ b/partner_contact_in_several_companies/tests/__init__.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from . import test_partner_contact_in_several_companies +import test_partner_contact_in_several_companies diff --git a/partner_contact_in_several_companies/tests/test_partner_contact_in_several_companies.py b/partner_contact_in_several_companies/tests/test_partner_contact_in_several_companies.py index 2e6714a43..61a759264 100644 --- a/partner_contact_in_several_companies/tests/test_partner_contact_in_several_companies.py +++ b/partner_contact_in_several_companies/tests/test_partner_contact_in_several_companies.py @@ -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, diff --git a/partner_contact_in_several_companies/views/res_partner.xml b/partner_contact_in_several_companies/views/res_partner.xml index a56bb51b3..003e4e03f 100644 --- a/partner_contact_in_several_companies/views/res_partner.xml +++ b/partner_contact_in_several_companies/views/res_partner.xml @@ -75,7 +75,7 @@
-
+
at
Phone:
Mobile:
@@ -123,12 +123,12 @@
- - + - \ No newline at end of file +