1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21 ##############################################################################
29 from tools.translate import _
31 track_form = '''<?xml version="1.0"?>
32 <form string="Tracking a move">
33 <field name="tracking_prefix"/>
35 <field name="quantity"/>
40 'string': 'Tracking prefix',
45 'string': 'Quantity per lot',
51 def _track_lines(self, cr, uid, data, context):
54 pool = pooler.get_pool(cr.dbname)
55 prodlot_obj = pool.get('stock.production.lot')
56 move_obj = pool.get('stock.move')
57 # production_obj = pool.get('mrp.production')
58 ir_sequence_obj = pool.get('ir.sequence')
60 sequence = ir_sequence_obj.get(cr, uid, 'stock.lot.serial')
62 raise wizard.except_wizard(_('Error!'), _('No production sequence defined'))
63 if data['form']['tracking_prefix']:
64 sequence=data['form']['tracking_prefix']+'/'+(sequence or '')
66 move = move_obj.browse(cr, uid, [move_id])[0]
67 quantity=data['form']['quantity']
68 if quantity <= 0 or move.product_qty == 0:
70 uos_qty=quantity/move.product_qty*move.product_uos_qty
72 quantity_rest = move.product_qty%quantity
73 uos_qty_rest = quantity_rest/move.product_qty*move.product_uos_qty
76 'product_qty': quantity,
77 'product_uos_qty': uos_qty,
81 for idx in range(int(move.product_qty//quantity)):
83 # current_move = move_obj.copy(cr, uid, move.id, {'state': move.state, 'production_id': move.production_id.id})
84 current_move = move_obj.copy(cr, uid, move.id, {'state': move.state})
85 new_move.append(current_move)
87 current_move = move.id
88 new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id})
89 update_val['prodlot_id'] = new_prodlot
90 move_obj.write(cr, uid, [current_move], update_val)
91 # production_ids = production_obj.search(cr, uid, [('move_lines', 'in', [move.id])])
94 idx = int(move.product_qty//quantity)
95 update_val['product_qty']=quantity_rest
96 update_val['product_uos_qty']=uos_qty_rest
98 # current_move = move_obj.copy(cr, uid, move.id, {'state': move.state, 'production_id': move.production_id.id})
99 current_move = move_obj.copy(cr, uid, move.id, {'state': move.state})
100 new_move.append(current_move)
102 current_move = move.id
103 new_prodlot = prodlot_obj.create(cr, uid, {'name': sequence, 'ref': '%d'%idx}, {'product_id': move.product_id.id})
104 update_val['prodlot_id'] = new_prodlot
105 move_obj.write(cr, uid, [current_move], update_val)
107 # products = production_obj.read(cr, uid, production_ids, ['move_lines'])
109 # for new in new_move:
110 # if new not in p['move_lines']:
111 # p['move_lines'].append(new)
112 # production_obj.write(cr, uid, [p['id']], {'move_lines': [(6, 0, p['move_lines'])]})
116 class wizard_track_move(wizard.interface):
120 'result': {'type': 'form', 'arch': track_form, 'fields': fields, 'state': [('end', 'Cancel', 'gtk-cancel'), ('track', 'Ok', 'gtk-ok')]},
123 'actions': [_track_lines],
124 'result': {'type':'state', 'state':'end'}
128 wizard_track_move('stock.move.track')
131 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: