From cd6de8ccd217adc0b16d9204a6462038a98dc773 Mon Sep 17 00:00:00 2001 From: "Nimesh (Open ERP)" Date: Fri, 2 Nov 2012 11:35:20 +0530 Subject: [PATCH] [ADD] add method to open the invoice in tree or form view accordingly. bzr revid: nco@tinyerp.com-20121102060520-5st9qkxd9p6u5uuy --- addons/purchase/purchase.py | 21 +++++++++++++++++++++ addons/purchase/stock_view.xml | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 6fa752a9f01..0989548d1d1 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -280,6 +280,27 @@ class purchase_order(osv.osv): fiscal_position = supplier.property_account_position and supplier.property_account_position.id or False return {'value':{'pricelist_id': pricelist, 'fiscal_position': fiscal_position}} + def invoice_open(self, cr, uid, ids, context=None): + mod_obj = self.pool.get('ir.model.data') + act_obj = self.pool.get('ir.actions.act_window') + + result = mod_obj.get_object_reference(cr, uid, 'account', 'action_invoice_tree2') + id = result and result[1] or False + result = act_obj.read(cr, uid, [id], context=context)[0] + inv_ids = [] + for po in self.browse(cr, uid, ids, context=context): + inv_ids+= [invoice.id for invoice in po.invoice_ids] + if not inv_ids: + raise osv.except_osv(_('Error!'), _('Please create Invoices.')) + #choose the view_mode accordingly + if len(inv_ids)>1: + result['domain'] = "[('id','in',["+','.join(map(str, inv_ids))+"])]" + else: + res = mod_obj.get_object_reference(cr, uid, 'account', 'invoice_supplier_form') + result['views'] = [(res and res[1] or False, 'form')] + result['res_id'] = inv_ids and inv_ids[0] or False + return result + def view_invoice(self, cr, uid, ids, context=None): ''' This function returns an action that display existing invoices of given sale order ids. It can either be a in a list or in a form view, if there is only one invoice to show. diff --git a/addons/purchase/stock_view.xml b/addons/purchase/stock_view.xml index 4a7c5dfca36..38db2998d54 100644 --- a/addons/purchase/stock_view.xml +++ b/addons/purchase/stock_view.xml @@ -62,7 +62,7 @@