~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to stock/wizard/wizard_split_track_line.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
5
# $Id$
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import wizard
 
31
import netsvc
 
32
import pooler
 
33
 
 
34
import time
 
35
from osv import osv
 
36
from tools.misc import UpdateableStr
 
37
 
 
38
#FIXME: this is not concurrency-safe !!!
 
39
arch = UpdateableStr()
 
40
fields = {}
 
41
 
 
42
def _get_moves(self, cr, uid, data, context):
 
43
        pick_obj = pooler.get_pool(cr.dbname).get('stock.picking')
 
44
        pick = pick_obj.browse(cr, uid, [data['id']])[0]
 
45
        res = {}
 
46
        fields.clear()
 
47
        arch_lst = ['<?xml version="1.0"?>', '<form string="Track lines">', '<label colspan="4" string="The first field of each line set the number of line this lot will be splitted into. A quantity of zero will not change the line. The second says if this lot should be tracked or not." />']
 
48
        for m in [line for line in pick.move_lines]:
 
49
                quantity = m.product_qty
 
50
                arch_lst.append('<field name="move%s"/><field name="track%s" />\n<newline />' % (m.id, m.id))
 
51
                fields['move%s' % m.id] = {'string' : m.product_id.name, 'type' : 'integer', 'default' : lambda x,y,z: 1}
 
52
                fields['track%s' % m.id] = {'string' : 'Tracking ?', 'type' : 'boolean', 'default' : lambda x,y,z: False}
 
53
                res.setdefault('moves', []).append(m.id)
 
54
        arch_lst.append('</form>')
 
55
        arch.string = '\n'.join(arch_lst)
 
56
        return res
 
57
 
 
58
def _split_lines(self, cr, uid, data, context):
 
59
        track_obj = pooler.get_pool(cr.dbname).get('stock.tracking')
 
60
        move_obj = pooler.get_pool(cr.dbname).get('stock.move')
 
61
        for move in move_obj.browse(cr, uid, data['form']['moves']):
 
62
                if data['form']['move%s' % move.id]:
 
63
                        num_pack = move.product_qty / data['form']['move%s' % move.id] 
 
64
                for idx in range(data['form']['move%s' % move.id]):
 
65
                        update_val = {'product_qty' : num_pack}
 
66
                        if idx:
 
67
                                current_move = move_obj.copy(cr, uid, move.id, {'state' : move.state})
 
68
                        else:
 
69
                                current_move = move.id
 
70
                        if data['form']['track%s' % move.id]:
 
71
                                new_tracking = track_obj.create(cr, uid, {'move_ids' : [(6, 0, [current_move])]})
 
72
                                update_val['tracking_id'] = new_tracking 
 
73
                        move_obj.write(cr, uid, [current_move], update_val)
 
74
        return {}
 
75
 
 
76
class wizard_track_move(wizard.interface):
 
77
        states = {
 
78
                'init': {
 
79
                        'actions': [_get_moves],
 
80
                        'result': {'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('split','Track')]}
 
81
                },
 
82
                'split': {
 
83
                        'actions': [_split_lines],
 
84
                        'result': {'type':'state', 'state':'end'}
 
85
                }
 
86
        }
 
87
 
 
88
wizard_track_move('stock.move.track')
 
89