~credativ/credativ-openerp/addons-6.1

« back to all changes in this revision

Viewing changes to stock_unassign_wizard/stock.py

  • Committer: Craig Gowing (credativ)
  • Date: 2013-08-28 15:29:38 UTC
  • mto: This revision was merged to the branch mainline in revision 205.
  • Revision ID: craig.gowing@credativ.co.uk-20130828152938-jl07urf28zs492p6
[ADD] Stock Unassign Wizard module which allows unassigning stock moves when checking availability of a picking

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2013 credativ ltd (<http://www.credativ.co.uk>). All Rights Reserved
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License as published by
 
9
#    the Free Software Foundation, either version 3 of the License, or
 
10
#    (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 General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from osv import osv, fields
 
23
from tools.translate import _
 
24
 
 
25
class stock_picking(osv.osv):
 
26
    _inherit = 'stock.picking'
 
27
 
 
28
    def action_assign(self, cr, uid, ids, context=None):
 
29
        if context == None:
 
30
            context = {}
 
31
        res = super(stock_picking, self).action_assign(cr, uid, ids, context)
 
32
        if len(ids) == 1: # Checks to make sure we should show the wizard
 
33
            pick = self.browse(cr, uid, ids)[0]
 
34
            move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed']
 
35
            if move_ids: # Some are still confirmed, generate and show the wizard
 
36
                if context.get('skip_stock_unassign_wizard', False):
 
37
                    return False
 
38
                mod_obj = self.pool.get('ir.model.data')
 
39
                wiz_obj = self.pool.get('stock.unassign.wizard')
 
40
                wiz_id = wiz_obj.create(cr, uid, {'picking_id': pick.id,}, context=context)
 
41
                model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'view_stock_unassign_wizard')], context=context)
 
42
                resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
 
43
                return {
 
44
                    'name': _('Stock Unassign Wizard'),
 
45
                    'res_id': wiz_id,
 
46
                    'view_type': 'form',
 
47
                    'view_mode': 'form',
 
48
                    'res_model': 'stock.unassign.wizard',
 
49
                    'view_id': False,
 
50
                    'target': 'new',
 
51
                    'views': [(resource_id, 'form')],
 
52
                    'context': context,
 
53
                    'type': 'ir.actions.act_window',
 
54
                }
 
55
        return res
 
56
 
 
57
stock_picking()
 
58
 
 
59
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: