1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
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 Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields, osv
23 from openerp.tools.translate import _
24 import openerp.addons.decimal_precision as dp
26 class stock_split_into(osv.osv_memory):
27 _name = "stock.split.into"
28 _description = "Split into"
30 'quantity': fields.float('Quantity',digits_compute=dp.get_precision('Product Unit of Measure')),
33 'quantity': lambda *x: 0,
36 def split(self, cr, uid, data, context=None):
40 inventory_id = context.get('inventory_id', False)
41 rec_id = context and context.get('active_ids', False)
42 move_obj = self.pool.get('stock.move')
43 track_obj = self.pool.get('stock.tracking')
44 inventory_obj = self.pool.get('stock.inventory')
45 quantity = self.browse(cr, uid, data[0], context=context).quantity or 0.0
46 for move in move_obj.browse(cr, uid, rec_id, context=context):
47 quantity_rest = move.product_qty - quantity
48 #if move.tracking_id :
49 # raise osv.except_osv(_('Error!'), _('The current move line is already assigned to a pack, please remove it first if you really want to change it ' \
50 # 'for this product: "%s" (id: %d)') % \
51 # (move.product_id.name, move.product_id.id,))
52 if quantity > move.product_qty:
53 raise osv.except_osv(_('Error!'), _('Total quantity after split exceeds the quantity to split ' \
54 'for this product: "%s" (id: %d).') % \
55 (move.product_id.name, move.product_id.id,))
57 move_obj.setlast_tracking(cr, uid, [move.id], context=context)
58 move_obj.write(cr, uid, [move.id], {
59 'product_qty': quantity,
60 'product_uos_qty': quantity,
61 'product_uos': move.product_uom.id,
65 quantity_rest = move.product_qty - quantity
66 tracking_id = track_obj.create(cr, uid, {}, context=context)
68 move_obj.write(cr, uid, [move.id], {'tracking_id': tracking_id}, context=context)
71 'product_qty': quantity_rest,
72 'product_uos_qty': quantity_rest,
73 'tracking_id': tracking_id,
75 'product_uos': move.product_uom.id
77 current_move = move_obj.copy(cr, uid, move.id, default_val, context=context)
78 if inventory_id and current_move:
79 inventory_obj.write(cr, uid, inventory_id, {'move_ids': [(4, current_move)]}, context=context)
82 return {'type': 'ir.actions.act_window_close'}
85 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: