From 34ce5acd01dc0d444957731597c8712f32ecdb12 Mon Sep 17 00:00:00 2001 From: "ksa (Open ERP)" Date: Tue, 15 Feb 2011 17:36:58 +0530 Subject: [PATCH] [FIX]: production lot does not work lp bug: https://launchpad.net/bugs/718685 fixed bzr revid: ksa@tinyerp.co.in-20110215120658-48kkt5li2431esc1 --- .../wizard/stock_inventory_line_split.py | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/addons/stock/wizard/stock_inventory_line_split.py b/addons/stock/wizard/stock_inventory_line_split.py index 11a6a2da323..2e8b93ad52b 100644 --- a/addons/stock/wizard/stock_inventory_line_split.py +++ b/addons/stock/wizard/stock_inventory_line_split.py @@ -29,65 +29,68 @@ class stock_inventory_line_split(osv.osv_memory): _name = "stock.inventory.line.split" _description = "Split inventory lines" - + def default_get(self, cr, uid, fields, context=None): - """ To check the availability of production lot. + """ To check the availability of production lot. @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in - @param fields: List of fields for which we want default values - @param context: A standard dictionary - @return: A dictionary which of fields with values. - """ + @param fields: List of fields for which we want default values + @param context: A standard dictionary + @return: A dictionary which of fields with values. + """ if context is None: context = {} record_id = context and context.get('active_id',False) res = {} - line = self.pool.get('stock.inventory.line').browse(cr, uid, record_id, context=context) + line = self.pool.get('stock.inventory.line').browse(cr, uid, record_id, context=context) if 'product_id' in fields: res.update({'product_id':line.product_id.id}) if 'product_uom' in fields: res.update({'product_uom': line.product_uom.id}) if 'qty' in fields: - res.update({'qty': line.product_qty}) + res.update({'qty': line.product_qty}) return res - + def split(self, cr, uid, ids, line_ids, context=None): """ To split stock inventory lines according to production lot. @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in - @param ids: the ID or list of IDs if we want more than one + @param ids: the ID or list of IDs if we want more than one @param line_ids: the ID or list of IDs of inventory lines we want to split - @param context: A standard dictionary - @return: - """ + @param context: A standard dictionary + @return: + """ prodlot_obj = self.pool.get('stock.production.lot') ir_sequence_obj = self.pool.get('ir.sequence') line_obj = self.pool.get('stock.inventory.line') - new_line = [] + new_line = [] for data in self.browse(cr, uid, ids, context=context): for inv_line in line_obj.browse(cr, uid, line_ids, context=context): line_qty = inv_line.product_qty - quantity_rest = inv_line.product_qty - new_line = [] + quantity_rest = inv_line.product_qty + new_line = [] if data.use_exist: lines = [l for l in data.line_exist_ids if l] else: - lines = [l for l in data.line_ids if l] + lines = [l for l in data.line_ids if l] for line in lines: quantity = line.quantity if quantity <= 0 or line_qty == 0: continue - quantity_rest -= quantity - if quantity_rest <= 0: + quantity_rest -= quantity + if quantity_rest < 0: quantity_rest = quantity break default_val = { - 'product_qty': quantity, + 'product_qty': quantity, } - current_line = line_obj.copy(cr, uid, inv_line.id, default_val) - new_line.append(current_line) + if quantity_rest > 0: + current_line = line_obj.copy(cr, uid, inv_line.id, default_val) + new_line.append(current_line) + if quantity_rest == 0: + current_line = inv_line.id prodlot_id = False if data.use_exist: prodlot_id = line.prodlot_id.id @@ -97,13 +100,13 @@ class stock_inventory_line_split(osv.osv_memory): 'product_id': inv_line.product_id.id}, context=context) line_obj.write(cr, uid, [current_line], {'prod_lot_id': prodlot_id}) - prodlot = prodlot_obj.browse(cr, uid, prodlot_id) - + prodlot = prodlot_obj.browse(cr, uid, prodlot_id) + update_val = {} - if quantity_rest > 0: - update_val['product_qty'] = quantity_rest + if quantity_rest > 0: + update_val['product_qty'] = quantity_rest line_obj.write(cr, uid, [inv_line.id], update_val) - + return new_line stock_inventory_line_split()