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 osv import fields, osv
24 from tools.translate import _
27 class stock_inventory_line_split(osv.osv_memory):
28 _inherit = "stock.move.split"
29 _name = "stock.inventory.line.split"
30 _description = "Split inventory lines"
33 def default_get(self, cr, uid, fields, context=None):
34 """ To check the availability of production lot.
35 @param self: The object pointer.
36 @param cr: A database cursor
37 @param uid: ID of the user currently logged in
38 @param fields: List of fields for which we want default values
39 @param context: A standard dictionary
40 @return: A dictionary which of fields with values.
44 record_id = context and context.get('active_id',False)
46 line = self.pool.get('stock.inventory.line').browse(cr, uid, record_id, context=context)
47 if 'product_id' in fields:
48 res.update({'product_id':line.product_id.id})
49 if 'product_uom' in fields:
50 res.update({'product_uom': line.product_uom.id})
52 res.update({'qty': line.product_qty})
55 def split(self, cr, uid, ids, line_ids, context=None):
56 """ To split stock inventory lines according to production lot.
57 @param self: The object pointer.
58 @param cr: A database cursor
59 @param uid: ID of the user currently logged in
60 @param ids: the ID or list of IDs if we want more than one
61 @param line_ids: the ID or list of IDs of inventory lines we want to split
62 @param context: A standard dictionary
65 prodlot_obj = self.pool.get('stock.production.lot')
66 ir_sequence_obj = self.pool.get('ir.sequence')
67 line_obj = self.pool.get('stock.inventory.line')
69 for data in self.browse(cr, uid, ids, context=context):
70 for inv_line in line_obj.browse(cr, uid, line_ids, context=context):
71 line_qty = inv_line.product_qty
72 quantity_rest = inv_line.product_qty
75 lines = [l for l in data.line_exist_ids if l]
77 lines = [l for l in data.line_ids if l]
79 quantity = line.quantity
80 if quantity <= 0 or line_qty == 0:
82 quantity_rest -= quantity
84 quantity_rest = quantity
87 'product_qty': quantity,
90 current_line = line_obj.copy(cr, uid, inv_line.id, default_val)
91 new_line.append(current_line)
92 if quantity_rest == 0:
93 current_line = inv_line.id
96 prodlot_id = line.prodlot_id.id
98 prodlot_id = prodlot_obj.create(cr, uid, {
100 'product_id': inv_line.product_id.id},
102 line_obj.write(cr, uid, [current_line], {'prod_lot_id': prodlot_id})
103 prodlot = prodlot_obj.browse(cr, uid, prodlot_id)
106 if quantity_rest > 0:
107 update_val['product_qty'] = quantity_rest
108 line_obj.write(cr, uid, [inv_line.id], update_val)
111 stock_inventory_line_split()
113 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: