Browse Source

[14.0][MIG] partner_contact_in_several_companies

14.0
Jacob Oldfield 3 years ago
parent
commit
fab6ba2451
  1. 2
      partner_contact_in_several_companies/README.rst
  2. 2
      partner_contact_in_several_companies/__manifest__.py
  3. 22
      partner_contact_in_several_companies/models/res_partner.py
  4. 28
      partner_contact_in_several_companies/tests/test_partner_contact_in_several_companies.py
  5. 2
      partner_contact_in_several_companies/views/res_partner.xml

2
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
======================

2
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",

22
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()

28
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,
)

2
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"
/>
<div class="o_kanban_image">
<img
alt="Contact Image"
t-if="record.image_128.raw_value"
t-att-src="'data:image/png;base64,' + record.image_128.raw_value"
/>

Loading…
Cancel
Save