[MERGE] forward port of branch 8.0 up to c825d05
[odoo/odoo.git] / addons / stock_invoice_directly / stock_invoice_directly.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp import api
23 from openerp.osv import osv
24 from openerp.tools.translate import _
25
26
27 class stock_picking(osv.osv):
28     _inherit = 'stock.picking'
29
30     @api.cr_uid_ids_context
31     def do_transfer(self, cr, uid, picking_ids, context=None):
32         """Launch Create invoice wizard if invoice state is To be Invoiced,
33           after processing the picking.
34         """
35         if context is None:
36             context = {}
37         res = super(stock_picking, self).do_transfer(cr, uid, picking_ids, context=context)
38         pick_ids = [p.id for p in self.browse(cr, uid, picking_ids, context) if p.invoice_state == '2binvoiced']
39         if pick_ids:
40             context = dict(context, active_model='stock.picking', active_ids=pick_ids)
41             return {
42                 'name': _('Create Invoice'),
43                 'view_type': 'form',
44                 'view_mode': 'form',
45                 'res_model': 'stock.invoice.onshipping',
46                 'type': 'ir.actions.act_window',
47                 'target': 'new',
48                 'context': context
49             }
50         return res
51
52 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: