1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
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
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.
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.
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.
28
##############################################################################
36
from tools.misc import UpdateableStr
38
#FIXME: this is not concurrency-safe !!!
39
arch = UpdateableStr()
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]
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)
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}
67
current_move = move_obj.copy(cr, uid, move.id, {'state' : move.state})
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)
76
class wizard_track_move(wizard.interface):
79
'actions': [_get_moves],
80
'result': {'type':'form', 'arch':arch, 'fields':fields, 'state':[('end','Cancel'),('split','Track')]}
83
'actions': [_split_lines],
84
'result': {'type':'state', 'state':'end'}
88
wizard_track_move('stock.move.track')