Browse Source

[IMP] partner_multi_relation_tabs: improve tab performance

Restrict partner relation tab loading to contact forms
12.0
Stephan Keller 5 years ago
parent
commit
aa2f171a84
  1. 20
      partner_multi_relation_tabs/models/res_partner.py
  2. 4
      partner_multi_relation_tabs/tests/test_partner_tabs.py
  3. 3
      partner_multi_relation_tabs/views/menu.xml

20
partner_multi_relation_tabs/models/res_partner.py

@ -15,11 +15,12 @@ class ResPartner(models.Model):
@api.multi @api.multi
def browse(self, arg=None, prefetch=None): def browse(self, arg=None, prefetch=None):
for tab in self._get_tabs():
fieldname = tab.get_fieldname()
if fieldname not in self._fields:
# Check this for performance reasons.
self.add_field(tab)
if "update_relation_tab" in self.env.context:
for tab in self._get_tabs():
fieldname = tab.get_fieldname()
if fieldname not in self._fields:
# Check this for performance reasons.
self.add_field(tab)
return super(ResPartner, self).browse(arg=arg, prefetch=prefetch) return super(ResPartner, self).browse(arg=arg, prefetch=prefetch)
@api.model @api.model
@ -71,10 +72,11 @@ class ResPartner(models.Model):
@api.depends('is_company', 'category_id') @api.depends('is_company', 'category_id')
def _compute_tabs_visibility(self): def _compute_tabs_visibility(self):
"""Compute for all tabs wether they should be visible.""" """Compute for all tabs wether they should be visible."""
for tab in self._get_tabs(): # get all tabs
for this in self:
this[tab.get_visible_fieldname()] = \
tab.compute_visibility(this)
if "update_relation_tab" in self.env.context:
for tab in self._get_tabs(): # get all tabs
for this in self:
this[tab.get_visible_fieldname()] = \
tab.compute_visibility(this)
def _get_tabs(self): def _get_tabs(self):
tab_model = self.env['res.partner.tab'] tab_model = self.env['res.partner.tab']

4
partner_multi_relation_tabs/tests/test_partner_tabs.py

@ -140,7 +140,9 @@ class TestPartnerTabs(common.TestCommon):
def test_compute_visibility(self): def test_compute_visibility(self):
"""Check the computation of visibility on partners.""" """Check the computation of visibility on partners."""
# pylint: disable=protected-access # pylint: disable=protected-access
main_partner = self.env.ref('base.main_partner')
main_partner = self.env.ref('base.main_partner').with_context({
'update_relation_tab': 1
})
main_partner._compute_tabs_visibility() main_partner._compute_tabs_visibility()
tab_obj = Tab(self.tab_departments) tab_obj = Tab(self.tab_departments)
fieldname = tab_obj.get_fieldname() fieldname = tab_obj.get_fieldname()

3
partner_multi_relation_tabs/views/menu.xml

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<odoo> <odoo>
<record id="contacts.action_contacts" model="ir.actions.act_window">
<field name="context">{'update_relation_tab': 1}</field>
</record>
<act_window <act_window
id="action_res_partner_tab" id="action_res_partner_tab"

Loading…
Cancel
Save