~sharoonthomas/openerpretail/core

« back to all changes in this revision

Viewing changes to bin/addons/stock/wizard/inventory_merge_zero.py

  • Committer: Sharoon Thomas
  • Date: 2009-07-20 06:25:34 UTC
  • Revision ID: sharoonthomas@teagarden.in-20090720062534-j8jq2nmdy63w9o9c
Initial Release

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) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
 
 
24
import wizard
 
25
import pooler
 
26
from tools.translate import _
 
27
 
 
28
 
 
29
_form = """<?xml version="1.0"?>
 
30
<form string="Set Stock to Zero">
 
31
    <separator colspan="4" string="Set Stocks to Zero" />
 
32
    <field name="location_id"/>
 
33
    <newline/>
 
34
    <label colspan="4" string="Do you want to set stocks to zero ?"/>
 
35
</form>
 
36
"""
 
37
_inventory_fields = {
 
38
    'location_id' : {
 
39
        'string':'Location',
 
40
        'type':'many2one',
 
41
        'relation':'stock.location',
 
42
        'required':True
 
43
        }
 
44
}
 
45
 
 
46
 
 
47
def do_merge(self, cr, uid, data, context):
 
48
    invent_obj = pooler.get_pool(cr.dbname).get('stock.inventory')
 
49
    invent_line_obj = pooler.get_pool(cr.dbname).get('stock.inventory.line')
 
50
    prod_obj =  pooler.get_pool(cr.dbname).get('product.product')
 
51
 
 
52
    if len(data['ids']) <> 1:
 
53
        raise wizard.except_wizard(_('Warning'),
 
54
                                   _('Please select one and only one inventory !'))
 
55
 
 
56
    loc = str(data['form']['location_id'])
 
57
 
 
58
    cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],))
 
59
    inv = cr.fetchall()
 
60
    cr.execute('select distinct product_id from stock_move where (location_dest_id='+loc+') or (location_id='+loc+')')
 
61
    stock = cr.fetchall()
 
62
    for s in stock:
 
63
        if (loc,s[0]) not in inv:
 
64
            p = prod_obj.browse(cr, uid, s[0])
 
65
            invent_line_obj.create(cr, uid, {
 
66
                'inventory_id': data['ids'][0],
 
67
                'location_id': loc,
 
68
                'product_id': s[0],
 
69
                'product_uom': p.uom_id.id,
 
70
                'product_qty': 0.0,
 
71
                })
 
72
    return {}
 
73
 
 
74
 
 
75
class merge_inventory(wizard.interface):
 
76
    states = {
 
77
        'init' : {
 
78
            'actions' : [],
 
79
            'result' : {'type' : 'form',
 
80
                    'arch' : _form,
 
81
                    'fields' : _inventory_fields,
 
82
                    'state' : [('end', 'Cancel'),
 
83
                               ('merge', 'Set to Zero') ]}
 
84
        },
 
85
        'merge' : {
 
86
            'actions' : [],
 
87
            'result' : {'type' : 'action',
 
88
                        'action': do_merge,
 
89
                        'state' : 'end'}
 
90
        },
 
91
    }
 
92
merge_inventory("inventory.merge.stock.zero")
 
93
 
 
94
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
95