Skip to content

Commit

Permalink
[IMP] check travis failure_2
Browse files Browse the repository at this point in the history
  • Loading branch information
foliveira-odoogap authored and jacob-willdooit committed Mar 20, 2021
1 parent 9b58314 commit e330a5c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion partner_contact_in_several_companies/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
6 changes: 4 additions & 2 deletions partner_contact_in_several_companies/demo/ir_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_mode">kanban,tree,form</field>
<field name="context">{"search_default_customer":1, 'search_show_all_positions': {'is_set': True, 'set_value': True}}</field>
<field name="search_view_id" ref="base.view_res_partner_filter"/>
<field
name="context"
>{"search_default_customer":1, 'search_show_all_positions': {'is_set': True, 'set_value': True}}</field>
<field name="search_view_id" ref="base.view_res_partner_filter" />
</record>
</odoo>
9 changes: 4 additions & 5 deletions partner_contact_in_several_companies/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class ResPartner(models.Model):
compute="_compute_contact_type",
store=True,
index=True,
default="standalone")
default="standalone"
)
contact_id = fields.Many2one(
"res.partner",
string="Main Contact",
domain=[("is_company", "=", False), ("contact_type", "=", "standalone"), ],
domain=[("is_company", "=", False), ("contact_type", "=", "standalone")],
)
other_contact_ids = fields.One2many(
"res.partner", "contact_id", string="Others Positions",
Expand Down Expand Up @@ -120,9 +121,7 @@ def update_contact(self, vals):
if self.env.context.get("__update_contact_lock"):
return
contact_fields = self._contact_fields()
contact_vals = {
field: vals[field] for field in contact_fields if field in vals
}
contact_vals = {field: vals[field] for field in contact_fields if field in vals}
if contact_vals:
self.with_context(__update_contact_lock=True).write(contact_vals)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ def setUp(self):
# Get test records reference
self.main_partner = self.env.ref("base.main_partner")
self.bob_contact = self.env.ref("%s.res_partner_contact1" % current_module)
self.bob_job1 = self.env.ref("%s.res_partner_contact1_work_position1" % current_module)
self.bob_job1 = self.env.ref(
"%s.res_partner_contact1_work_position1" % current_module
)
self.roger_contact = self.env.ref("base.res_partner_main2")
self.roger_job2 = self.env.ref("%s.res_partner_main2_position_consultant" % current_module)
self.roger_job2 = self.env.ref(
"%s.res_partner_main2_position_consultant" % current_module
)

def test_00_show_only_standalone_contact(self):
"""Check that only standalone contact are shown if context
Expand Down Expand Up @@ -52,13 +56,21 @@ def test_02_reading_other_contact_one2many_show_all_positions(self):
"""

ctx = {}
self.assertEqual(self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids)
self.assertEqual(
self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids
)
ctx = {"search_show_all_positions": {"is_set": False}}
self.assertEqual(self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids)
self.assertEqual(
self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids
)
ctx = {"search_show_all_positions": {"is_set": True, "set_value": False}}
self.assertEqual(self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids)
self.assertEqual(
self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids
)
ctx = {"search_show_all_positions": {"is_set": True, "set_value": True}}
self.assertEqual(self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids)
self.assertEqual(
self.bob_job1, self.bob_contact.with_context(ctx).other_contact_ids
)

ctx = {}
self.assertIn(self.bob_job1, self.main_partner.with_context(ctx).child_ids)
Expand All @@ -83,7 +95,9 @@ def test_03_search_match_attached_contacts(self):
# but when searching without 'all positions',
# we should get the position standalone contact instead.
ctx = {"search_show_all_positions": {"is_set": True, "set_value": False}}
partner_ids = self.partner.with_context(ctx).search([("parent_id", "ilike", "YourCompany")])
partner_ids = self.partner.with_context(ctx).search(
[("parent_id", "ilike", "YourCompany")]
)
self.assertTrue(self.bob_contact in partner_ids)

def test_04_contact_creation(self):
Expand All @@ -100,19 +114,25 @@ def test_04_contact_creation(self):

# Create a contact with both contact_id and name;
# contact's name should override provided value in that case
new_contact = self.partner.create({"contact_id": self.bob_contact.id, "name": "Rob Egnops"})
new_contact = self.partner.create(
{"contact_id": self.bob_contact.id, "name": "Rob Egnops"}
)
self.assertEqual(new_contact.name, "Bob Egnops")

# Reset contact to standalone
new_contact.write({"contact_id": False})
self.assertEqual(new_contact.contact_type, "standalone",)
self.assertEqual(
new_contact.contact_type, "standalone",
)

# Reset contact to attached, and ensure only it is unlinked (i.e.
# context is ignored).
new_contact.write({"contact_id": self.bob_contact.id})
ctx = {"search_show_all_positions": {"is_set": True, "set_value": True}}
new_contact.with_context(ctx).unlink()
partner_ids = self.partner.with_context(ctx).search([("id", "in", [new_contact.id, self.bob_contact.id])])
partner_ids = self.partner.with_context(ctx).search(
[("id", "in", [new_contact.id, self.bob_contact.id])]
)
self.assertIn(self.bob_contact, partner_ids)
self.assertNotIn(new_contact, partner_ids)

Expand All @@ -123,11 +143,15 @@ 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.assertEqual(
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.assertEqual(
self.bob_contact.name, "Bob Egnops",
)

def test_06_ir_action(self):
"""Check ir_action context is auto updated.
Expand All @@ -144,7 +168,7 @@ def test_06_ir_action(self):
self.assertIn(
new_context_val,
details["context"],
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(
Expand All @@ -154,7 +178,7 @@ def test_06_ir_action(self):
self.assertNotIn(
new_context_val,
details["context"],
msg="Custom actions incorrectly updated with new context"
msg="Custom actions incorrectly updated with new context",
)

def test_07_onchange(self):
Expand All @@ -164,15 +188,11 @@ def test_07_onchange(self):
new_contact = self.partner.create({"name": "Bob before onchange"})
new_contact.write({"contact_id": self.bob_contact.id})
new_contact._onchange_contact_id()
self.assertEqual(
new_contact.name, "Bob Egnops"
)
self.assertEqual(new_contact.name, "Bob Egnops")

new_contact.write({"contact_type": "standalone"})
new_contact._onchange_contact_type()
self.assertEqual(
new_contact.contact_id, self.partner
)
self.assertEqual(new_contact.contact_id, self.partner)

def test_08_commercial_partner_compute(self):
new_contact = self.partner.create({"name": "Bob before onchange"})
Expand Down
25 changes: 17 additions & 8 deletions partner_contact_in_several_companies/views/res_partner.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_res_partner_filter_contact" model="ir.ui.view">
<field name="name">res.partner.select.contact</field>
Expand Down Expand Up @@ -48,17 +48,20 @@
expr="//field[@name='child_ids']/form//field[@name='name']"
position="before"
>
<field name='contact_type' readonly='0'/>
<field name="contact_id"
string="Contact"
attrs="{'invisible': [('contact_type','!=','attached')], 'required': [('contact_type','=','attached')]}"
<field name='contact_type' readonly='0' />
<field
name="contact_id"
string="Contact"
attrs="{'invisible': [('contact_type','!=','attached')], 'required': [('contact_type','=','attached')]}"
/>
</xpath>
<xpath
expr="//field[@name='child_ids']/form//field[@name='name']"
position="attributes"
>
<attribute name="attrs">{'invisible': [('contact_type','=','attached')]}</attribute>
<attribute
name="attrs"
>{'invisible': [('contact_type','=','attached')]}</attribute>
</xpath>
<field name="is_company" position="after">
<field name="contact_type" invisible="1" />
Expand Down Expand Up @@ -219,7 +222,10 @@
<field name="email" />
<field name="phone" widget="phone" />
<field name="mobile" widget="phone" />
<field name="comment" placeholder="internal note..." />
<field
name="comment"
placeholder="internal note..."
/>
</group>
</group>
<field name="lang" invisible="True" />
Expand All @@ -234,7 +240,10 @@
<record id="personal_contact_information" model="ir.ui.view">
<field name="name">Contacts in several partners: personal info</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_contact_personal_information_page.personal_information" />
<field
name="inherit_id"
ref="partner_contact_personal_information_page.personal_information"
/>
<field name="arch" type="xml">
<xpath
expr="//page[@name='personal_information_page']/group[@name='personal_information_group']"
Expand Down

0 comments on commit e330a5c

Please sign in to comment.