Browse Source

[14.0][MIG] partner_contact_in_several_companies

14.0
Jacob Oldfield 4 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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Known issues / Roadmap
====================== ======================

2
partner_contact_in_several_companies/__manifest__.py

@ -3,7 +3,7 @@
{ {
"name": "Contacts in several partners", "name": "Contacts in several partners",
"summary": "Allow to have one contact 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", "category": "Customer Relationship Management",
"website": "https://github.com/OCA/partner-contact", "website": "https://github.com/OCA/partner-contact",
"author": "Nicolas JEUDY, Odoo Community Association (OCA),Odoo SA", "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")], domain=[("is_company", "=", False), ("contact_type", "=", "standalone")],
) )
other_contact_ids = fields.One2many( other_contact_ids = fields.One2many(
"res.partner", "contact_id", string="Others Positions",
"res.partner",
"contact_id",
string="Others Positions",
) )
@api.depends("contact_id") @api.depends("contact_id")
@ -32,7 +34,7 @@ class ResPartner(models.Model):
rec.contact_type = "attached" if rec.contact_id else "standalone" rec.contact_type = "attached" if rec.contact_id else "standalone"
def _basecontact_check_context(self, mode): 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 Keeping it in context can result in unexpected behaviour (ex: reading
one2many might return wrong result - i.e with "attached contact" one2many might return wrong result - i.e with "attached contact"
removed even if it"s directly linked to a company). removed even if it"s directly linked to a company).
@ -47,8 +49,8 @@ class ResPartner(models.Model):
@api.model @api.model
def search(self, args, offset=0, limit=None, order=None, count=False): 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 ctx = self.env.context
if ( if (
ctx.get("search_show_all_positions", {}).get("is_set") ctx.get("search_show_all_positions", {}).get("is_set")
@ -71,7 +73,7 @@ class ResPartner(models.Model):
@api.model @api.model
def create(self, vals): 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 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 that the name on an attached contact is the same as the name on the
contact it is attached to.""" contact it is attached to."""
@ -93,9 +95,9 @@ class ResPartner(models.Model):
return super(ResPartner, modified_self).unlink() return super(ResPartner, modified_self).unlink()
def _compute_commercial_partner(self): 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 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() result = super(ResPartner, self)._compute_commercial_partner()
for partner in self: for partner in self:
if partner.contact_type == "attached" and not partner.parent_id: if partner.contact_type == "attached" and not partner.parent_id:
@ -103,12 +105,12 @@ class ResPartner(models.Model):
return result return result
def _contact_fields(self): 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"] return ["name", "title"]
def _contact_sync_from_parent(self): 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 is set, as if they were related fields
""" """
self.ensure_one() 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 # Reset contact to standalone
new_contact.write({"contact_id": False}) new_contact.write({"contact_id": False})
self.assertEqual( self.assertEqual(
new_contact.contact_type, "standalone",
new_contact.contact_type,
"standalone",
) )
# Reset contact to attached, and ensure only it is unlinked (i.e. # Reset contact to attached, and ensure only it is unlinked (i.e.
@ -143,26 +144,25 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase):
# Test DOWNSTREAM sync # Test DOWNSTREAM sync
self.bob_contact.write({"name": "Rob Egnops"}) self.bob_contact.write({"name": "Rob Egnops"})
self.assertEqual( self.assertEqual(
self.bob_job1.name, "Rob Egnops",
self.bob_job1.name,
"Rob Egnops",
) )
# Test UPSTREAM sync # Test UPSTREAM sync
self.bob_job1.write({"name": "Bob Egnops"}) self.bob_job1.write({"name": "Bob Egnops"})
self.assertEqual( self.assertEqual(
self.bob_contact.name, "Bob Egnops",
self.bob_contact.name,
"Bob Egnops",
) )
def test_06_ir_action(self): def test_06_ir_action(self):
"""Check ir_action context is auto updated.
"""
"""Check ir_action context is auto updated."""
new_context_val = ( new_context_val = (
"'search_show_all_positions': " "{'is_set': True, 'set_value': False}" "'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( self.assertIn(
new_context_val, new_context_val,
@ -170,9 +170,9 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase):
msg="Default actions not updated with new 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( self.assertNotIn(
new_context_val, new_context_val,
@ -181,8 +181,7 @@ class PartnerContactInSeveralCompaniesCase(common.TransactionCase):
) )
def test_07_onchange(self): def test_07_onchange(self):
"""Check onchange method
"""
"""Check onchange method"""
new_contact = self.partner.create({"name": "Bob before onchange"}) new_contact = self.partner.create({"name": "Bob before onchange"})
new_contact.write({"contact_id": self.bob_contact.id}) 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.write({"contact_id": self.bob_contact.id, "parent_id": False})
new_contact._compute_commercial_partner() new_contact._compute_commercial_partner()
self.assertEqual( 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" t-if="!read_only_mode"
type="delete" type="delete"
class="fa fa-times pull-right" class="fa fa-times pull-right"
title="Delete Contact"
/> />
<div class="o_kanban_image"> <div class="o_kanban_image">
<img <img
alt="Contact Image"
t-if="record.image_128.raw_value" t-if="record.image_128.raw_value"
t-att-src="'data:image/png;base64,' + record.image_128.raw_value" t-att-src="'data:image/png;base64,' + record.image_128.raw_value"
/> />

Loading…
Cancel
Save