From 04cdfb2cd5a7195e5c365670cb9dcb1b1a67c044 Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Wed, 7 Nov 2012 17:03:16 +0530 Subject: [PATCH] [FIX]: Open invoice view directly from incomming shipment wizard bzr revid: atp@tinyerp.com-20121107113316-9gl01qojb32bmex6 --- addons/purchase/stock.py | 48 +++++++++++++++++++ addons/purchase/stock_view.xml | 12 +++++ addons/stock/wizard/stock_partial_picking.py | 20 -------- .../wizard/stock_partial_picking_view.xml | 1 - 4 files changed, 60 insertions(+), 21 deletions(-) diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 3ed3987fbb3..af2abc91f20 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -127,6 +127,54 @@ class stock_partial_picking(osv.osv_memory): 'currency': move.picking_id.purchase_id.pricelist_id.currency_id.id} return super(stock_partial_picking, self)._product_cost_for_average_update(cr, uid, move) + + def create_invoice(self, cr, uid, ids, context=None): + if context is None: + context = {} + picking_pool = self.pool.get('stock.picking') + active_ids = context.get('active_ids', []) + active_picking = picking_pool.browse(cr, uid, context.get('active_id',False), context=context) + inv_type = picking_pool._get_invoice_type(active_picking) + context['inv_type'] = inv_type + res = picking_pool.action_invoice_create(cr, uid, active_ids, + type = inv_type, + context=context) + return res + + def open_invoice(self, cr, uid, ids, context=None): + """Launch Create invoice wizard. + """ + if context is None: context = {} + data_pool = self.pool.get('ir.model.data') + result = self.do_partial(cr, uid, ids, context=context) + partial = self.browse(cr, uid, ids[0], context=context) + context.update(active_model='stock.picking', + active_ids=[partial.picking_id.id]) + if partial.picking_id.invoice_state == '2binvoiced': + invoice_ids = [] + res = self.create_invoice(cr, uid, ids, context=context) + invoice_ids += res.values() + inv_type = context.get('inv_type', False) + action_model = False + action = {} + if not invoice_ids: + raise osv.except_osv(_('Error!'), _('Please create Invoices.')) + if inv_type == "out_invoice": + action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree1") + elif inv_type == "in_invoice": + action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree2") + elif inv_type == "out_refund": + action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree3") + elif inv_type == "in_refund": + action_model,action_id = data_pool.get_object_reference(cr, uid, 'account', "action_invoice_tree4") + if action_model: + action_pool = self.pool.get(action_model) + action = action_pool.read(cr, uid, action_id, context=context) + action['domain'] = "[('id','in', ["+','.join(map(str,invoice_ids))+"])]" + return action + return {'type': 'ir.actions.act_window_close'} + + # Redefinition of the new field in order to update the model stock.picking.in in the orm # FIXME: this is a temporary workaround because of a framework bug (ref: lp996816). It should be removed as soon as # the bug is fixed diff --git a/addons/purchase/stock_view.xml b/addons/purchase/stock_view.xml index 188baeccd69..1a050e6f1ca 100644 --- a/addons/purchase/stock_view.xml +++ b/addons/purchase/stock_view.xml @@ -37,6 +37,18 @@ + + + stock.partial.picking.form.inherit + stock.partial.picking + + + +