From 5ea5ebe08f525afeb8ccc3f17efd3a01f2b0a550 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 23 Apr 2014 17:11:36 +0200 Subject: [PATCH] Add option try_parent in open_filtered_object In the wizard "Open Calling Partner", when you click on "open related orders" for example, it will open the orders with an explicit filter that you can then delete. --- asterisk_click2dial/wizard/open_calling_partner.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/asterisk_click2dial/wizard/open_calling_partner.py b/asterisk_click2dial/wizard/open_calling_partner.py index 61bf5d7..0b9ec97 100644 --- a/asterisk_click2dial/wizard/open_calling_partner.py +++ b/asterisk_click2dial/wizard/open_calling_partner.py @@ -77,7 +77,8 @@ class wizard_open_calling_partner(orm.TransientModel): return res - def open_filtered_object(self, cr, uid, ids, oerp_object, context=None): + def open_filtered_object( + self, cr, uid, ids, oerp_object, try_parent=True, context=None): '''Returns the action that opens the list view of the 'oerp_object' given as argument filtered on the partner''' # This module only depends on "base" @@ -87,7 +88,13 @@ class wizard_open_calling_partner(orm.TransientModel): raise orm.except_orm(_('Error :'), _("The object '%s' is not found in your OpenERP database, probably because the related module is not installed." % oerp_object._description)) partner = self.read(cr, uid, ids[0], ['partner_id', 'parent_partner_id'], context=context) - partner_id_to_filter = partner['parent_partner_id'] and partner['parent_partner_id'][0] or (partner['partner_id'] and partner['partner_id'][0] or False) + if try_parent: + partner_id_to_filter = ( + partner['parent_partner_id'] + and partner['parent_partner_id'][0] + or (partner['partner_id'] and partner['partner_id'][0] or False)) + else: + partner_id_to_filter = partner['partner_id'] and partner['partner_id'][0] or False if partner_id_to_filter: action = { 'name': oerp_object._description, @@ -97,7 +104,7 @@ class wizard_open_calling_partner(orm.TransientModel): 'type': 'ir.actions.act_window', 'nodestroy': False, # close the pop-up wizard after action 'target': 'current', - 'domain': [('partner_id', '=', partner_id_to_filter)], + 'context': {'search_default_partner_id': partner_id_to_filter}, } return action else: