Browse Source

[IMP] partner_multi_relation_tabs. Forward to 100% coverage.

12.0
Ronald Portier 6 years ago
committed by Jan Verbeek
parent
commit
192c444463
  1. 4
      partner_multi_relation_tabs/demo/res_partner_category_demo.xml
  2. 20
      partner_multi_relation_tabs/demo/res_partner_demo.xml
  3. 21
      partner_multi_relation_tabs/demo/res_partner_relation_demo.xml
  4. 11
      partner_multi_relation_tabs/demo/res_partner_relation_type_demo.xml
  5. 10
      partner_multi_relation_tabs/demo/res_partner_tab_demo.xml
  6. 2
      partner_multi_relation_tabs/models/res_partner.py
  7. 11
      partner_multi_relation_tabs/models/res_partner_relation_all.py
  8. 4
      partner_multi_relation_tabs/tests/common.py
  9. 33
      partner_multi_relation_tabs/tests/test_partner_tabs.py
  10. 15
      partner_multi_relation_tabs/tests/test_tab.py

4
partner_multi_relation_tabs/demo/res_partner_category_demo.xml

@ -10,4 +10,8 @@
<field name="name">Functionary</field>
</record>
<record id="category_department" model="res.partner.category">
<field name="name">Department</field>
</record>
</odoo>

20
partner_multi_relation_tabs/demo/res_partner_demo.xml

@ -25,4 +25,24 @@
<field name="ref">HS</field>
</record>
<record id="partner_programming_department" model="res.partner">
<field
name="category_id"
eval="[(6,0,[ref('category_department')])]"
/>
<field name="name">Programming</field>
<field name="is_company">1</field>
<field name="ref">HACKDEP</field>
</record>
<record id="partner_helpdesk_department" model="res.partner">
<field
name="category_id"
eval="[(6,0,[ref('category_department')])]"
/>
<field name="name">Helpdesk</field>
<field name="is_company">1</field>
<field name="ref">HELPDEP</field>
</record>
</odoo>

21
partner_multi_relation_tabs/demo/res_partner_relation_demo.xml

@ -1,11 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Relations -->
<!-- Company has ceo. -->
<record id="relation_company_ceo" model="res.partner.relation">
<field name="left_partner_id" ref="partner_big_company" />
<field name="right_partner_id" ref="partner_important_person" />
<field name="type_id" ref="relation_type_company_has_ceo" />
</record>
<!-- Departments of main organisation. -->
<record id="relation_programming_department" model="res.partner.relation">
<field name="left_partner_id" ref="base.main_partner" />
<field name="right_partner_id" ref="partner_programming_department" />
<field
name="type_id"
ref="relation_type_organisation_has_department"
/>
</record>
<record id="relation_helpdesk_department" model="res.partner.relation">
<field name="left_partner_id" ref="base.main_partner" />
<field name="right_partner_id" ref="partner_helpdesk_department" />
<field
name="type_id"
ref="relation_type_organisation_has_department"
/>
</record>
</odoo>

11
partner_multi_relation_tabs/demo/res_partner_relation_type_demo.xml

@ -27,4 +27,15 @@
<field name="tab_right_id" ref="tab_positions" />
</record>
<!-- Organisation has department -->
<record
id="relation_type_organisation_has_department"
model="res.partner.relation.type">
<field name="name">has department</field>
<field name="name_inverse">is department of</field>
<field name="tab_left_id" ref="tab_departments" />
<field name="contact_type_right">c</field>
<field name="partner_category_right" ref="category_department"/>
</record>
</odoo>

10
partner_multi_relation_tabs/demo/res_partner_tab_demo.xml

@ -21,4 +21,14 @@
<field name="partner_category_id" ref="category_functionary" />
</record>
<!-- Tab that will only be shown on our own main company partner. -->
<record id="tab_departments" model="res.partner.tab">
<field name="code">departments</field>
<field name="name">Our departments</field>
<field
name="partner_ids"
eval="[(6,0,[ref('base.main_partner')])]"
/>
</record>
</odoo>

2
partner_multi_relation_tabs/models/res_partner.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2018 Therp BV <https://therp.nl>
# Copyright 2014-2018 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=no-member
import logging

11
partner_multi_relation_tabs/models/res_partner_relation_all.py

@ -48,11 +48,10 @@ class ResPartnerRelationAll(models.AbstractModel):
# pylint: disable=no-member
result = super(ResPartnerRelationAll, self).onchange_partner_id()
if 'default_tab_id' in self.env.context:
if 'domain' not in result:
result['domain'] = {}
if 'type_selection_id' not in result['domain']:
result['domain']['type_selection_id'] = []
selection_domain = result['domain']['type_selection_id']
selection_domain.append(
result['domain'] = result['domain'] if 'domain' in result else {}
result['domain']['type_selection_id'] = \
result['domain']['type_selection_id'] \
if 'type_selection_id' in result['domain'] else {}
result['domain']['type_selection_id'].append(
('tab_id', '=', self.env.context['default_tab_id']))
return result

4
partner_multi_relation_tabs/tests/common.py

@ -21,6 +21,8 @@ class TestCommon(common.SingleTransactionCase):
'partner_multi_relation_tabs.category_government')
self.category_functionary = self.env.ref(
'partner_multi_relation_tabs.category_functionary')
self.category_department = self.env.ref(
'partner_multi_relation_tabs.category_department')
# Tabs.
self.tab_committee = self.env.ref(
'partner_multi_relation_tabs.tab_committee')
@ -28,6 +30,8 @@ class TestCommon(common.SingleTransactionCase):
'partner_multi_relation_tabs.tab_board')
self.tab_positions = self.env.ref(
'partner_multi_relation_tabs.tab_positions')
self.tab_departments = self.env.ref(
'partner_multi_relation_tabs.tab_departments')
# Types.
self.type_chairperson = self.env.ref(
'partner_multi_relation_tabs'

33
partner_multi_relation_tabs/tests/test_partner_tabs.py

@ -42,6 +42,13 @@ class TestPartnerTabs(common.TestCommon):
'Tab field %s should not exist in %s.' %
(fieldname, etree.tostring(tree)))
def test_view_without_pages(self):
"""Check that _add_tab_pages does not effect view without pages."""
# pylint: disable=protected-access
view = etree.Element('view')
extra_fields = self.partner_model._add_tab_pages(view)
self.assertFalse(extra_fields)
def test_tab_modifications(self):
tab_executive = self.tab_model.create({
'code': 'executive',
@ -73,6 +80,13 @@ class TestPartnerTabs(common.TestCommon):
self.assertEqual(
type_chairperson.tab_left_id.id,
False)
# It should not be possible to add category or contact type to as
# selection criteria to a tab meant for specific partners.
with self.assertRaises(ValidationError):
self.tab_departments.write({'contact_type': 'c'})
with self.assertRaises(ValidationError):
self.tab_departments.write({
'partner_category_id': self.category_government.id})
def test_type_modifications(self):
self.assertTrue(bool(self.tab_board))
@ -123,3 +137,22 @@ class TestPartnerTabs(common.TestCommon):
self.assertEqual(
onchange_result['domain']['type_selection_id'][-1],
('tab_id', '=', self.tab_board.id))
def test_compute_visibility(self):
"""Check the computation of visibility on partners."""
# pylint: disable=protected-access
main_partner = self.env.ref('base.main_partner')
main_partner._compute_tabs_visibility()
tab_obj = Tab(self.tab_departments)
fieldname = tab_obj.get_fieldname()
visible_fieldname = tab_obj.get_visible_fieldname()
self.assertIn(visible_fieldname, main_partner._fields)
self.assertIn(fieldname, main_partner._fields)
self.assertEqual(main_partner[visible_fieldname], True)
department_relations = main_partner[fieldname]
self.assertTrue(len(department_relations) >= 1)
departments = [
relation.other_partner_id for relation in department_relations]
for department in departments:
self.assertIn(
self.category_department, department.category_id)

15
partner_multi_relation_tabs/tests/test_tab.py

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# pylint: disable=protected-access
from . import common
from ..tablib import Tab
@ -25,7 +24,17 @@ class TestTab(common.TestCommon):
tab_obj = Tab(self.tab_positions)
self.assertTrue(
tab_obj.compute_visibility(self.partner_important_person),
'Board tab should be visible for functionary.')
'Positions tab should be visible for functionary.')
self.assertFalse(
tab_obj.compute_visibility(self.partner_common_person),
'Board tab should not be visible for non-functionary.')
'Positions tab should not be visible for non-functionary.')
# Tab for departments should only be visible for main partner
self.assertTrue(bool(self.tab_departments))
self.assertTrue(bool(self.partner_big_company))
tab_obj = Tab(self.tab_departments)
self.assertTrue(
tab_obj.compute_visibility(self.env.ref('base.main_partner')),
'Department tab should be visible for main partner.')
self.assertFalse(
tab_obj.compute_visibility(self.partner_big_company),
'Department tab should not be visible for other partners.')
Loading…
Cancel
Save