Skip to content

Commit

Permalink
[14.0][MIG] partner_contact_in_several_companies
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-willdooit committed Mar 20, 2021
1 parent 7efff2c commit fab6ba2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion partner_contact_in_several_companies/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
======================
Expand Down
2 changes: 1 addition & 1 deletion partner_contact_in_several_companies/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 12 additions & 10 deletions partner_contact_in_several_companies/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -32,7 +34,7 @@ def _compute_contact_type(self):
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).
Expand All @@ -47,8 +49,8 @@ def _basecontact_check_context(self, mode):

@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")
Expand All @@ -71,7 +73,7 @@ def search(self, args, offset=0, limit=None, order=None, count=False):

@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."""
Expand All @@ -93,22 +95,22 @@ def unlink(self):
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:
partner.commercial_partner_id = partner.contact_id
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def test_04_contact_creation(self):
# 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.
Expand All @@ -143,36 +144,35 @@ def test_05_contact_fields_sync(self):
# 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,
details["context"],
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,
Expand All @@ -181,8 +181,7 @@ def test_06_ir_action(self):
)

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})
Expand All @@ -198,5 +197,6 @@ def test_08_commercial_partner_compute(self):
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 changes: 2 additions & 0 deletions partner_contact_in_several_companies/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand Down

0 comments on commit fab6ba2

Please sign in to comment.