[FIX] mrp: Manufacturing Order Consumes too many products when they are split. ...
authorRavi Gohil (Open ERP) <rgo@tinyerp.com>
Thu, 4 Oct 2012 13:16:13 +0000 (18:46 +0530)
committerRavi Gohil (Open ERP) <rgo@tinyerp.com>
Thu, 4 Oct 2012 13:16:13 +0000 (18:46 +0530)
bzr revid: rgo@tinyerp.com-20121004131613-f9cosqejhdt0zhr7

addons/mrp/mrp.py
addons/mrp/mrp_view.xml
addons/stock/stock.py

index a6ce212..8faf759 100644 (file)
@@ -737,8 +737,21 @@ class mrp_production(osv.osv):
                         # we already have more qtys consumed than we need 
                         continue
 
+                    qty_remained = 0
+                    qty_tobe_consumed = qty
                     for consume_line in raw_product:
-                        consume_line.action_consume(qty, consume_line.location_id.id, context=context)
+                        if consume_line.prodlot_id and consume_line.product_id.id==scheduled.product_id.id:
+                            if qty_remained:
+                                qty = qty_remained
+                            if consume_line.product_qty >= qty:
+                                consume_line.action_consume(qty, consume_line.location_id.id, context=context)
+                                break
+                            else:
+                                qty_tobe_consumed += consume_line.product_qty
+                                consume_line.action_consume(qty_tobe_consumed, consume_line.location_id.id, context=context)
+                                qty_remained = qty - consume_line.product_qty
+                        else:
+                            consume_line.action_consume(qty, consume_line.location_id.id, context=context)
 
         if production_mode == 'consume_produce':
             # To produce remaining qty of final product
index 9c3fd6e..25b9ca0 100644 (file)
                                     <field name="product_qty"  string="Qty"/>
                                     <field name="product_uom"  string="UOM"/>
                                     <field name="location_id"  string="Source Loc."/>
+                                    <field name="prodlot_id" string="Production Lot"/>
                                     <field name="state" invisible="1"/>
                                     <button name="%(stock.move_consume)d"
                                         string="Consume Products" type="action"
                                        <field name="state" invisible="1"/>
                                        <field name="scrapped" invisible="1"/>
                                        <button
+                                           name="%(stock.track_line)d"
+                                           string="Split in production lots"
+                                           type="action" icon="gtk-justify-fill"/>
+                                       <button
                                            name="%(stock.move_scrap)d"
                                            string="Scrap Products" type="action"
                                            icon="gtk-convert"
index dd52404..1742873 100644 (file)
@@ -1585,7 +1585,7 @@ class stock_move(osv.osv):
         'location_dest_id': fields.many2one('stock.location', 'Destination Location', required=True,states={'done': [('readonly', True)]}, select=True, help="Location where the system will stock the finished products."),
         'address_id': fields.many2one('res.partner.address', 'Destination Address ', states={'done': [('readonly', True)]}, help="Optional address where goods are to be delivered, specifically used for allotment"),
 
-        'prodlot_id': fields.many2one('stock.production.lot', 'Production Lot', states={'done': [('readonly', True)]}, help="Production lot is used to put a serial number on the production", select=True),
+        'prodlot_id': fields.many2one('stock.production.lot', 'Production Lot', help="Production lot is used to put a serial number on the production", select=True),
         'tracking_id': fields.many2one('stock.tracking', 'Pack', select=True, states={'done': [('readonly', True)]}, help="Logistical shipping unit: pallet, box, pack ..."),
 
         'auto_validate': fields.boolean('Auto Validate'),