[FIX] Improved Ravi's patch, new algorithm for selecting lines to consume
bzr revid: cbi@openerp.com-20121005074757-4yrzgv2mahsn6pdb
This commit is contained in:
+34
-13
@@ -737,21 +737,42 @@ class mrp_production(osv.osv):
|
||||
# we already have more qtys consumed than we need
|
||||
continue
|
||||
|
||||
qty_remained = 0
|
||||
qty_tobe_consumed = qty
|
||||
consumed = 0
|
||||
|
||||
# search for exact quantity
|
||||
for consume_line in raw_product:
|
||||
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:
|
||||
if consume_line.product_qty == qty:
|
||||
# consume this line
|
||||
consume_line.action_consume(qty, consume_line.location_id.id, context=context)
|
||||
consumed = qty
|
||||
break
|
||||
|
||||
# using the quick sort algorithm
|
||||
def _sort_quantity(raw_product):
|
||||
if len(raw_product) <= 1:
|
||||
return raw_product
|
||||
pivot = raw_product[0]
|
||||
smaller = _sort_quantity([x for x in raw_product[1:] if x.product_qty < pivot.product_qty])
|
||||
bigger = _sort_quantity([x for x in raw_product[1:] if x.product_qty >= pivot.product_qty])
|
||||
return smaller + [pivot] + bigger
|
||||
|
||||
# sort the list by quantity if we have not consumed yet
|
||||
if consumed < qty:
|
||||
raw_product = _sort_quantity(raw_product)
|
||||
|
||||
index = 0
|
||||
# consume the smallest quantity while we have not consumed enough
|
||||
while consumed < qty and index < len(raw_product):
|
||||
consume_line = raw_product[index]
|
||||
# we don't need to split
|
||||
if consume_line.product_qty <= (qty - consumed):
|
||||
consume_line.action_consume(consume_line.product_qty, consume_line.location_id.id, context=context)
|
||||
consumed += consume_line.product_qty
|
||||
# we need to split
|
||||
else:
|
||||
consume_line.action_consume(qty - consumed, consume_line.location_id.id, context=context)
|
||||
consumed += qty - consumed
|
||||
index += 1
|
||||
|
||||
if production_mode == 'consume_produce':
|
||||
# To produce remaining qty of final product
|
||||
|
||||
@@ -685,7 +685,7 @@
|
||||
<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
|
||||
|
||||
@@ -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', help="Production lot is used to put a serial number on the production", select=True),
|
||||
'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),
|
||||
'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'),
|
||||
|
||||
Reference in New Issue
Block a user