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
24 class stock_inventory_line_split(osv.osv_memory):
25 _inherit = "stock.move.split"
26 _name = "stock.inventory.line.split"
27 _description = "Split inventory lines"
30 'line_ids': fields.one2many('stock.inventory.line.split.lines', 'wizard_id', 'Serial Numbers'),
31 'line_exist_ids': fields.one2many('stock.inventory.line.split.lines', 'wizard_exist_id', 'Serial Numbers'),
34 def default_get(self, cr, uid, fields, context=None):
37 record_id = context and context.get('active_id',False)
39 line = self.pool.get('stock.inventory.line').browse(cr, uid, record_id, context=context)
40 if 'product_id' in fields:
41 res.update({'product_id':line.product_id.id})
42 if 'product_uom' in fields:
43 res.update({'product_uom': line.product_uom.id})
45 res.update({'qty': line.product_qty})
48 def split(self, cr, uid, ids, line_ids, context=None):
49 """ To split stock inventory lines according to serial numbers.
51 :param line_ids: the ID or list of IDs of inventory lines we want to split
55 assert context.get('active_model') == 'stock.inventory.line',\
56 'Incorrect use of the inventory line split wizard.'
57 prodlot_obj = self.pool.get('stock.production.lot')
58 ir_sequence_obj = self.pool.get('ir.sequence')
59 line_obj = self.pool.get('stock.inventory.line')
61 for data in self.browse(cr, uid, ids, context=context):
62 for inv_line in line_obj.browse(cr, uid, line_ids, context=context):
63 line_qty = inv_line.product_qty
64 quantity_rest = inv_line.product_qty
67 lines = [l for l in data.line_exist_ids if l]
69 lines = [l for l in data.line_ids if l]
71 quantity = line.quantity
72 if quantity <= 0 or line_qty == 0:
74 quantity_rest -= quantity
76 quantity_rest = quantity
79 'product_qty': quantity,
82 current_line = line_obj.copy(cr, uid, inv_line.id, default_val)
83 new_line.append(current_line)
84 if quantity_rest == 0:
85 current_line = inv_line.id
88 prodlot_id = line.prodlot_id.id
90 prodlot_id = prodlot_obj.create(cr, uid, {
92 'product_id': inv_line.product_id.id},
94 line_obj.write(cr, uid, [current_line], {'prod_lot_id': prodlot_id})
95 prodlot = prodlot_obj.browse(cr, uid, prodlot_id)
99 update_val['product_qty'] = quantity_rest
100 line_obj.write(cr, uid, [inv_line.id], update_val)
104 class stock_inventory_split_lines(osv.osv_memory):
105 _inherit = "stock.move.split.lines"
106 _name = "stock.inventory.line.split.lines"
107 _description = "Inventory Split lines"
109 'wizard_id': fields.many2one('stock.inventory.line.split', 'Parent Wizard'),
110 'wizard_exist_id': fields.many2one('stock.inventory.line.split', 'Parent Wizard'),