From 96bcaadd46e7685de3f5267506f051f47e601624 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Mon, 27 Oct 2014 13:23:16 +0100 Subject: [PATCH] [FIX] account: limit search for fields_view_get to one result + use ir.model.data get_object_reference method for better performance (cached result) opw-616616 --- addons/account/account_invoice.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 9390e2cf3fd..f324a07d684 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -355,13 +355,22 @@ class account_invoice(osv.osv): if context.get('active_model', '') in ['res.partner'] and context.get('active_ids', False) and context['active_ids']: partner = self.pool.get(context['active_model']).read(cr, uid, context['active_ids'], ['supplier','customer'])[0] if not view_type: - view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'account.invoice.tree')]) + try: + view_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'account', 'invoice_tree')[1] + except ValueError: + view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'account.invoice.tree')], limit=1) view_type = 'tree' if view_type == 'form': if partner['supplier'] and not partner['customer']: - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name', '=', 'account.invoice.supplier.form')]) + try: + view_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'account', 'invoice_supplier_form')[1] + except ValueError: + view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name', '=', 'account.invoice.supplier.form')], limit=1) elif partner['customer'] and not partner['supplier']: - view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name', '=', 'account.invoice.form')]) + try: + view_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'account', 'invoice_form')[1] + except ValueError: + view_id = self.pool.get('ir.ui.view').search(cr,uid,[('name', '=', 'account.invoice.form')], limit=1) if view_id and isinstance(view_id, (list, tuple)): view_id = view_id[0] res = super(account_invoice,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)