Chris Biersbach (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-579232-rgo into 
lp:openobject-addons/6.1.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-579232-rgo/+merge/128202

TO REPLICATE:
1) Visit demo.openerp.com [1]
2) Manufacturing -> Manufacturing Orders, then Open MO/00009
3) Click 'Split in Production Lots' next to one of the products on the Products 
to Consume side of the COnsumed Products tab.
4) Create four new production lots each with a quantity of 1.  Click OK.
5) Manufacturing -> Manufacturing Orders, then Open MO/00009 (so you can see 
the changes).
6) Click ‘Start Production’.
7) Click 'Produce'.
8) Consume & Produce a quantity of 1.  THE USER HAS NO OPTION TO SPECIFY 
WHICH PRODUCTION LOT THEY CONSUME.  Click Confirm.
9) OBSERVE that all 4 of the split products are moved to the Consumed side, but 
only one of the unsplit products to consume is moved.  There are 3 remaining of 
the unsplit product on the Products to Consume side.

This branch fixes this issue.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-579232-rgo/+merge/128202
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-579232-rgo.
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py	2012-07-23 08:44:52 +0000
+++ mrp/mrp.py	2012-10-05 10:00:35 +0000
@@ -27,6 +27,7 @@
 import netsvc
 import time
 import tools
+from operator import attrgetter
 
 
 #----------------------------------------------------------
@@ -737,8 +738,31 @@
                         # we already have more qtys consumed than we need 
                         continue
 
+                    consumed = 0
+
+                    rounding = raw_product[0].product_uom.rounding
+
+                    # search for exact quantity
                     for consume_line in raw_product:
-                        consume_line.action_consume(qty, consume_line.location_id.id, context=context)
+                        if tools.float_compare(consume_line.product_qty, qty, precision_rounding=rounding) == 0:
+                            # consume this line
+                            consume_line.action_consume(qty, consume_line.location_id.id, context=context)
+                            consumed = qty
+                            break
+                            
+                    # sort the list by quantity if we have not consumed yet
+                    if tools.float_compare(consumed, qty, precision_rounding=rounding) == -1:
+                        raw_product.sort(key=attrgetter('product_qty'))
+                    
+                    index = 0  
+                      
+                    # consume the smallest quantity while we have not consumed enough
+                    while tools.float_compare(consumed, qty, precision_rounding=rounding) == -1 and index < len(raw_product):
+                        consume_line = raw_product[index]
+                        to_consume = min(consume_line.product_qty, qty - consumed) 
+                        consume_line.action_consume(to_consume, consume_line.location_id.id, context=context)
+                        consumed += to_consume
+                        index += 1
 
         if production_mode == 'consume_produce':
             # To produce remaining qty of final product

=== modified file 'mrp/mrp_view.xml'
--- mrp/mrp_view.xml	2012-02-16 16:29:09 +0000
+++ mrp/mrp_view.xml	2012-10-05 10:00:35 +0000
@@ -661,6 +661,7 @@
                                     <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"
@@ -684,10 +685,14 @@
                                        <field name="product_id" readonly="1"/>
                                        <field name="product_qty" readonly="1" string="Qty"/>
                                        <field name="product_uom" readonly="1" string="UOM"/>
-                                       <field name="prodlot_id" context="{'product_id': product_id}"/>
+                                       <field name="prodlot_id" attrs="{'readonly': False}" context="{'product_id': product_id}"/>
                                        <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"

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to