From fab6ba2451b89150dd69620466643584521185f3 Mon Sep 17 00:00:00 2001 From: Jacob Oldfield Date: Sat, 20 Mar 2021 13:05:47 +1100 Subject: [PATCH] [14.0][MIG] partner_contact_in_several_companies --- .../README.rst | 2 +- .../__manifest__.py | 2 +- .../models/res_partner.py | 22 ++++++++------- ...st_partner_contact_in_several_companies.py | 28 +++++++++---------- .../views/res_partner.xml | 2 ++ 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/partner_contact_in_several_companies/README.rst b/partner_contact_in_several_companies/README.rst index 27ec4c416..243639cbd 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/11.0 + :target: https://runbot.odoo-community.org/runbot/134/14.0 Known issues / Roadmap ====================== diff --git a/partner_contact_in_several_companies/__manifest__.py b/partner_contact_in_several_companies/__manifest__.py index 7537ba078..ea272f05a 100644 --- a/partner_contact_in_several_companies/__manifest__.py +++ b/partner_contact_in_several_companies/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Contacts in several partners", "summary": "Allow to have one contact in several partners", - "version": "13.0.1.1.0", + "version": "14.0.1.0.0", "category": "Customer Relationship Management", "website": "https://github.com/OCA/partner-contact", "author": "Nicolas JEUDY, Odoo Community Association (OCA),Odoo SA", diff --git a/partner_contact_in_several_companies/models/res_partner.py b/partner_contact_in_several_companies/models/res_partner.py index fe648d0f4..9b4e1f897 100644 --- a/partner_contact_in_several_companies/models/res_partner.py +++ b/partner_contact_in_several_companies/models/res_partner.py @@ -23,7 +23,9 @@ class ResPartner(models.Model): domain=[("is_company", "=", False), ("contact_type", "=", "standalone")], ) other_contact_ids = fields.One2many( - "res.partner", "contact_id", string="Others Positions", + "res.partner", + "contact_id", + string="Others Positions", ) @api.depends("contact_id") @@ -32,7 +34,7 @@ class ResPartner(models.Model): rec.contact_type = "attached" if rec.contact_id else "standalone" def _basecontact_check_context(self, mode): - """ Remove "search_show_all_positions" for non-search mode. + """Remove "search_show_all_positions" for non-search mode. Keeping it in context can result in unexpected behaviour (ex: reading one2many might return wrong result - i.e with "attached contact" removed even if it"s directly linked to a company). @@ -47,8 +49,8 @@ class ResPartner(models.Model): @api.model def search(self, args, offset=0, limit=None, order=None, count=False): - """ Display only standalone contact matching ``args`` or having - attached contact matching ``args`` """ + """Display only standalone contact matching ``args`` or having + attached contact matching ``args``""" ctx = self.env.context if ( ctx.get("search_show_all_positions", {}).get("is_set") @@ -71,7 +73,7 @@ class ResPartner(models.Model): @api.model def create(self, vals): - """ When creating, use a modified self to alter the context (see + """When creating, use a modified self to alter the context (see comment in _basecontact_check_context). Also, we need to ensure that the name on an attached contact is the same as the name on the contact it is attached to.""" @@ -93,9 +95,9 @@ class ResPartner(models.Model): return super(ResPartner, modified_self).unlink() def _compute_commercial_partner(self): - """ Returns the partner that is considered the commercial + """Returns the partner that is considered the commercial entity of this partner. The commercial entity holds the master data - for all commercial fields (see :py:meth:`~_commercial_fields`) """ + for all commercial fields (see :py:meth:`~_commercial_fields`)""" result = super(ResPartner, self)._compute_commercial_partner() for partner in self: if partner.contact_type == "attached" and not partner.parent_id: @@ -103,12 +105,12 @@ class ResPartner(models.Model): return result def _contact_fields(self): - """ Returns the list of contact fields that are synced from the parent - when a partner is attached to him. """ + """Returns the list of contact fields that are synced from the parent + when a partner is attached to him.""" return ["name", "title"] def _contact_sync_from_parent(self): - """ Handle sync of contact fields when a new parent contact entity + """Handle sync of contact fields when a new parent contact entity is set, as if they were related fields """ self.ensure_one() 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 70e527157..88a35647c 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 @@ -121,7 +121,8 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): # Reset contact to standalone new_contact.write({"contact_id": False}) self.assertEqual( - new_contact.contact_type, "standalone", + new_contact.contact_type, + "standalone", ) # Reset contact to attached, and ensure only it is unlinked (i.e. @@ -143,26 +144,25 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): # Test DOWNSTREAM sync self.bob_contact.write({"name": "Rob Egnops"}) self.assertEqual( - self.bob_job1.name, "Rob Egnops", + self.bob_job1.name, + "Rob Egnops", ) # Test UPSTREAM sync self.bob_job1.write({"name": "Bob Egnops"}) self.assertEqual( - self.bob_contact.name, "Bob Egnops", + self.bob_contact.name, + "Bob Egnops", ) def test_06_ir_action(self): - """Check ir_action context is auto updated. - """ + """Check ir_action context is auto updated.""" new_context_val = ( "'search_show_all_positions': " "{'is_set': True, 'set_value': False}" ) - details = self.env["ir.actions.act_window"].for_xml_id( - "base", "action_partner_form" - ) + details = self.env.ref("{}.{}".format("base", "action_partner_form")).read()[0] self.assertIn( new_context_val, @@ -170,9 +170,9 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): msg="Default actions not updated with new context", ) - details = self.env["ir.actions.act_window"].for_xml_id( - "partner_contact_in_several_companies", "action_partner_form" - ) + details = self.env.ref( + "partner_contact_in_several_companies.action_partner_form" + ).read()[0] self.assertNotIn( new_context_val, @@ -181,8 +181,7 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): ) def test_07_onchange(self): - """Check onchange method - """ + """Check onchange method""" new_contact = self.partner.create({"name": "Bob before onchange"}) new_contact.write({"contact_id": self.bob_contact.id}) @@ -198,5 +197,6 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase): new_contact.write({"contact_id": self.bob_contact.id, "parent_id": False}) new_contact._compute_commercial_partner() self.assertEqual( - new_contact.commercial_partner_id, self.bob_contact, + new_contact.commercial_partner_id, + self.bob_contact, ) diff --git a/partner_contact_in_several_companies/views/res_partner.xml b/partner_contact_in_several_companies/views/res_partner.xml index b557e6507..ed1bfac3d 100644 --- a/partner_contact_in_several_companies/views/res_partner.xml +++ b/partner_contact_in_several_companies/views/res_partner.xml @@ -106,9 +106,11 @@ t-if="!read_only_mode" type="delete" class="fa fa-times pull-right" + title="Delete Contact" />
Contact Image