[IMP]: mrp: Solved problem of already consumed products
bzr revid: rpa@openerp.co.in-20100223112402-ptardjdgq679pglm
This commit is contained in:
+11
-11
@@ -589,13 +589,17 @@ class mrp_production(osv.osv):
|
||||
def action_production_end(self, cr, uid, ids, qty=0.0, mode=None):
|
||||
move_ids = []
|
||||
finished = []
|
||||
qty_rest = 0.0
|
||||
move_obj = self.pool.get('stock.move')
|
||||
for production in self.browse(cr, uid, ids):
|
||||
done = 0.0
|
||||
qty_rest = 0.0
|
||||
for move in production.move_created_ids2:
|
||||
done += move.product_qty
|
||||
qty_operate = production.product_qty - done
|
||||
if qty > production.product_qty:
|
||||
# Is it required??
|
||||
raise osv.except_osv(_('Error'), _("Couldn't produce more quantity"))
|
||||
elif qty == production.product_qty:
|
||||
elif qty == qty_operate:
|
||||
for res in production.move_lines:
|
||||
for move in production.move_created_ids:
|
||||
#XXX must use the orm
|
||||
@@ -604,17 +608,13 @@ class mrp_production(osv.osv):
|
||||
(res.id, move.id))
|
||||
move_ids.append(res.id)
|
||||
finished += [x.id for x in production.move_created_ids]
|
||||
elif qty < production.product_qty:
|
||||
qty_rest = production.product_qty - qty
|
||||
# Needs other field to store value of already consumed products
|
||||
# self.write(cr, uid, ids, {'product_qty': qty_rest})
|
||||
elif qty < qty_operate:
|
||||
qty_rest = qty_operate - qty
|
||||
moves = map(lambda x: x.id, production.move_lines)
|
||||
moves_created = map(lambda x: x.id, production.move_created_ids)
|
||||
if mode == 'consume':
|
||||
temp = move_obj.consume_moves(cr, uid, moves, qty)
|
||||
temp1 = move_obj.consume_moves(cr, uid, moves_created, qty)
|
||||
move_ids += temp
|
||||
finished += temp1
|
||||
move_ids += move_obj.consume_moves(cr, uid, moves, qty)
|
||||
finished += move_obj.consume_moves(cr, uid, moves_created, qty)
|
||||
elif mode == 'consume_produce':
|
||||
for move in move_obj.browse(cr, uid, moves):
|
||||
move_obj.write(cr, uid, move.id, {'product_qty': qty})
|
||||
@@ -633,7 +633,7 @@ class mrp_production(osv.osv):
|
||||
{'date_finnished': time.strftime('%Y-%m-%d %H:%M:%S')})
|
||||
move_obj.action_done(cr, uid, finished)
|
||||
move_obj.action_done(cr, uid, move_ids)
|
||||
if mode == 'consume_produce' and not qty_rest and not finished:
|
||||
if mode == 'consume_produce' and not qty_rest:
|
||||
move_obj.check_assign(cr, uid, finished)
|
||||
self._costs_generate(cr, uid, production)
|
||||
self.write(cr, uid, ids, {'state': 'done'})
|
||||
|
||||
@@ -36,7 +36,10 @@ class stock_move_produce(osv.osv_memory):
|
||||
def _get_product_qty(self, cr, uid, context):
|
||||
prod = self.pool.get('mrp.production').browse(cr, uid,
|
||||
context['active_id'], context=context)
|
||||
return prod.product_qty
|
||||
done = 0.0
|
||||
for move in prod.move_created_ids2:
|
||||
done += move.product_qty
|
||||
return (prod.product_qty - done) or prod.product_qty
|
||||
|
||||
_defaults = {
|
||||
'product_qty': _get_product_qty,
|
||||
|
||||
@@ -1488,7 +1488,7 @@ class stock_move(osv.osv):
|
||||
self.write(cr, uid, [current_move], update_val)
|
||||
return new_move
|
||||
|
||||
def consume_moves(self, cr, uid, ids, quantity, location_id, context=None):
|
||||
def consume_moves(self, cr, uid, ids, quantity, location_id=None, context=None):
|
||||
new_move = []
|
||||
if not context:
|
||||
context = {}
|
||||
@@ -1509,7 +1509,7 @@ class stock_move(osv.osv):
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'location_id' : location_id,
|
||||
'location_id' : location_id or move.location_id.id,
|
||||
}
|
||||
if move.product_id.track_production:
|
||||
new_move = self.split_lines(cr, uid, [move.id], quantity, split_by_qty=1, context=context)
|
||||
|
||||
Reference in New Issue
Block a user