[MERGE] OPW 579232: mrp: better handle partial consumption of raw products that were split in production lots
- System will no longer consume every line of raw product after a split - If a raw product line with the exact quantity to consume is present, only this one will be consumed - If no raw product line matches the quantity to consume, the system will consume the available lines (starting with smallest quantities first) until it attains the required quantity, possibly splitting one line further if no combination of the existing lines gives the right quantity. - The production lot column and the split button will now be available on both sides of the production order form, allowing fine control of the production lots that were consumed, in case the defaults do not match what was used in reality. bzr revid: odo@openerp.com-20121005104447-3vn0nu9spvdxypqr
This commit is contained in:
+22
-1
@@ -27,6 +27,7 @@ from tools.translate import _
|
||||
import netsvc
|
||||
import time
|
||||
import tools
|
||||
from operator import attrgetter
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
@@ -737,8 +738,28 @@ class mrp_production(osv.osv):
|
||||
# we already have more qtys consumed than we need
|
||||
continue
|
||||
|
||||
consumed = 0
|
||||
rounding = raw_product[0].product_uom.rounding
|
||||
|
||||
# sort the list by quantity, to consume smaller quantities first and avoid splitting if possible
|
||||
raw_product.sort(key=attrgetter('product_qty'))
|
||||
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
@@ -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,9 +685,13 @@
|
||||
<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"
|
||||
|
||||
Reference in New Issue
Block a user