diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py
index c8224ee74c5..f22b40ecf60 100644
--- a/addons/mrp/mrp.py
+++ b/addons/mrp/mrp.py
@@ -773,7 +773,6 @@ class mrp_production(osv.osv):
return 1
-
def action_produce(self, cr, uid, production_id, production_qty, production_mode, wiz, context=None):
""" To produce final product based on production mode (consume/consume&produce).
If Production mode is consume, all stock move lines of raw materials will be done/consumed.
@@ -784,6 +783,8 @@ class mrp_production(osv.osv):
@param production_mode: specify production mode (consume/consume&produce).
@return: True
"""
+
+
stock_mov_obj = self.pool.get('stock.move')
production = self.browse(cr, uid, production_id, context=context)
if not production.move_lines and production.state == 'ready':
diff --git a/addons/mrp/stock.py b/addons/mrp/stock.py
index 0d96090b0fb..553b9a6bc3d 100644
--- a/addons/mrp/stock.py
+++ b/addons/mrp/stock.py
@@ -37,7 +37,9 @@ class StockMove(osv.osv):
super(StockMove, self).check_tracking(cr, uid, move, lot_id, context=context)
if move.product_id.track_production and (move.location_id.usage == 'production' or move.location_dest_id.usage == 'production') and not lot_id:
raise osv.except_osv(_('Warning!'), _('You must assign a serial number for the product %s') % (move.product_id.name))
-
+ if move.raw_material_production_id and move.location_dest_id.usage == 'production' and move.raw_material_production_id.product_id.track_production and not move.consumed_for:
+ raise osv.except_osv(_('Warning!'), _('You should not process it like this as both your raw materials and finished product require to track manufacturing. In that case, you should be able to make the link between the raw materials and the finished products and this is not possible with this method. '))
+
def _action_explode(self, cr, uid, move, context=None):
""" Explodes pickings.
@param move: Stock moves
diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py
index 36a2f4bc462..aafd329ac9e 100644
--- a/addons/mrp/wizard/mrp_product_produce.py
+++ b/addons/mrp/wizard/mrp_product_produce.py
@@ -75,14 +75,15 @@ class mrp_product_produce(osv.osv_memory):
if not consumed_data.get(consumed.product_id.id, False):
consumed_data[consumed.product_id.id] = 0
consumed_data[consumed.product_id.id] += consumed.product_qty
-
- print "Consumed data", consumed_data
new_consume_lines = []
+
+ dicts = {}
# Find product qty to be consumed and consume it
for scheduled in production.product_lines:
-
+ if not dicts.get(scheduled.product_id.id):
+ dicts[scheduled.product_id.id] = {}
# total qty of consumed product we need after this consumption
total_consume = ((product_qty + produced_qty) * scheduled.product_qty / production.product_qty)
@@ -104,13 +105,26 @@ class mrp_product_produce(osv.osv_memory):
prefered_domain=[('reservation_id', '=', move.id)], fallback_domain=[('reservation_id', '=', False)], context=context)
for quant in quants:
if quant[0]:
- dict_new = {'product_id': scheduled.product_id.id, 'product_qty': quant[1], 'lot_id': quant[0].lot_id.id}
- new_consume_lines.append([0, False, dict_new])
+ product_id = scheduled.product_id.id
+ lot_id = quant[0].lot_id.id
+ prod_qty = quant[1]
+ if not product_id in dicts.keys():
+ dicts[product_id] = {lot_id : prod_qty}
+ elif lot_id in dicts[product_id].keys():
+ dicts[product_id][lot_id] += prod_qty
+ else:
+ dicts[product_id][lot_id] = prod_qty
qty -= quant[1]
- if qty > 0:
- dict_new = {'product_id': scheduled.product_id.id, 'product_qty': qty}
- new_consume_lines.append([0, False, dict_new])
-
+ if qty > 0:
+ if dicts[product_id][False]:
+ dicts[product_id][False] += qty
+ else:
+ dicts[product_id][False] = qty
+
+ for prod in dicts.keys():
+ for lot in dicts[prod].keys():
+ dict_new = {'product_id': prod, 'product_qty':dicts[prod][lot], 'lot_id': lot}
+ new_consume_lines.append([0, False, dict_new]) #Todo for all qtys
return {'value': {'consume_lines': new_consume_lines}}
@@ -155,6 +169,9 @@ class mrp_product_produce(osv.osv_memory):
'track_production': _get_track,
}
+
+
+
def do_produce(self, cr, uid, ids, context=None):
production_id = context.get('active_id', False)
assert production_id, "Production Id should be specified in context as a Active ID."
diff --git a/addons/mrp/wizard/mrp_product_produce_view.xml b/addons/mrp/wizard/mrp_product_produce_view.xml
index f851cd2b364..01b90433c1b 100644
--- a/addons/mrp/wizard/mrp_product_produce_view.xml
+++ b/addons/mrp/wizard/mrp_product_produce_view.xml
@@ -17,7 +17,7 @@
diff --git a/addons/stock/wizard/stock_move.py b/addons/stock/wizard/stock_move.py
index d230f469036..488e825a361 100644
--- a/addons/stock/wizard/stock_move.py
+++ b/addons/stock/wizard/stock_move.py
@@ -60,6 +60,8 @@ class stock_move_consume(osv.osv_memory):
return res
+
+
def do_move_consume(self, cr, uid, ids, context=None):
""" To move consumed products
@param self: The object pointer.
@@ -115,7 +117,6 @@ class stock_move_scrap(osv.osv_memory):
res.update({'location_id': scrap_location_id[0]})
else:
res.update({'location_id': False})
-
return res
def move_scrap(self, cr, uid, ids, context=None):