From 521c21bf7f7772a7a3e258ab565039090ef7299f Mon Sep 17 00:00:00 2001 From: Jay Patel Date: Thu, 4 Dec 2014 12:34:29 +0530 Subject: [PATCH] [IMP] MRP: Press green arrow to consume product qty more than before consumed create new line Avoid creating negative stock move and do basically the same as would have been done when using the Produce wizard --- addons/mrp/wizard/stock_move.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/addons/mrp/wizard/stock_move.py b/addons/mrp/wizard/stock_move.py index 8ab75a7836b..8bad002b28a 100644 --- a/addons/mrp/wizard/stock_move.py +++ b/addons/mrp/wizard/stock_move.py @@ -20,6 +20,7 @@ ############################################################################## from openerp.osv import fields, osv +from openerp.tools import float_compare from openerp.tools.translate import _ import openerp.addons.decimal_precision as dp @@ -58,13 +59,27 @@ class stock_move_consume(osv.osv_memory): context = {} move_obj = self.pool.get('stock.move') uom_obj = self.pool.get('product.uom') + production_obj = self.pool.get('mrp.production') move_ids = context['active_ids'] - for data in self.browse(cr, uid, ids, context=context): - if move_ids and move_ids[0]: - move = move_obj.browse(cr, uid, move_ids[0], context=context) - qty = uom_obj._compute_qty(cr, uid, data['product_uom'].id, data.product_qty, data.product_id.uom_id.id) - move_obj.action_consume(cr, uid, move_ids, - qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id, - context=context) - return {'type': 'ir.actions.act_window_close'} + move = move_obj.browse(cr, uid, move_ids[0], context=context) + production_id = move.raw_material_production_id.id + production = production_obj.browse(cr, uid, production_id, context=context) + precision = self.pool['decimal.precision'].precision_get(cr, uid, 'Product Unit of Measure') + for data in self.browse(cr, uid, ids, context=context): + qty = uom_obj._compute_qty(cr, uid, data['product_uom'].id, data.product_qty, data.product_id.uom_id.id) + remaining_qty = move.product_qty - qty + #check for product quantity is less than previously planned + if float_compare(remaining_qty, 0, precision_digits=precision) >= 0: + move_obj.action_consume(cr, uid, move_ids, qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id, context=context) + else: + consumed_qty = min(move.product_qty, qty) + new_moves = move_obj.action_consume(cr, uid, move_ids, consumed_qty, data.location_id.id, restrict_lot_id=data.restrict_lot_id.id, context=context) + #consumed more in wizard than previously planned + extra_more_qty = qty - consumed_qty + #create new line for a remaining qty of the product + extra_move_id = production_obj._make_consume_line_from_data(cr, uid, production, data.product_id, data.product_id.uom_id.id, extra_more_qty, False, 0, context=context) + move_obj.write(cr, uid, [extra_move_id], {'restrict_lot_id': data.restrict_lot_id.id}, context=context) + move_obj.action_done(cr, uid, [extra_move_id], context=context) + + return {'type': 'ir.actions.act_window_close'} \ No newline at end of file