[IMP]: mrp: Improvement in change product qty for finished products line
bzr revid: rpa@openerp.co.in-20100223120903-13nn7urdnmik6qg1
This commit is contained in:
+42
-23
@@ -794,7 +794,30 @@ class mrp_production(osv.osv):
|
||||
return True
|
||||
|
||||
def _change_prod_qty(self, cr, uid, ids, new_qty, context={}):
|
||||
move_lines_obj = self.pool.get('stock.move')
|
||||
move_obj = self.pool.get('stock.move')
|
||||
|
||||
def change(product_id, product_qty, qty_vals, qty_vals_done, moves,
|
||||
moves_done, field):
|
||||
if not moves.get(product_id) and moves_done.get(product_id):
|
||||
new_qty = (product_qty - qty_vals_done.get(product_id, 0.0))
|
||||
new_move = move_obj.copy(cr, uid, moves_done.get(product_id), default={'product_qty': new_qty})
|
||||
self.write(cr, uid, prod.id, {field: [(4, new_move)]})
|
||||
return
|
||||
to_add = (product_qty - qty_vals_done.get(product_id, 0.0)) - \
|
||||
qty_vals.get(product_id, 0.0)
|
||||
avail_qty = move_obj.browse(cr, uid, moves[product_id][0]).product_qty
|
||||
new_qty = avail_qty + to_add
|
||||
if new_qty == 0:
|
||||
move_obj.write(cr, uid, moves[product_id][0], {'state': 'draft'})
|
||||
move_obj.unlink(cr, uid, moves[product_id])
|
||||
elif new_qty < 0:
|
||||
avail_qty = move_obj.browse(cr, uid, moves_done[product_id][0]).product_qty
|
||||
move_obj.unlink(cr, uid, moves[product_id][0])
|
||||
move_obj.write(cr, uid, moves_done[product_id][0], {'product_qty': avail_qty + new_qty})
|
||||
else:
|
||||
move_obj.write(cr, uid, moves[product_id][0], {'product_qty': avail_qty + to_add})
|
||||
return
|
||||
|
||||
for id in ids:
|
||||
prod = self.browse(cr, uid, id)
|
||||
self.write(cr, uid, prod.id, {'product_qty' : new_qty})
|
||||
@@ -823,28 +846,24 @@ class mrp_production(osv.osv):
|
||||
moves_done[move.product_id.id].append(move.id)
|
||||
|
||||
for r in res[0]:
|
||||
if not moves.get(r['product_id']) and moves_done.get(r['product_id']):
|
||||
new_qty = (r['product_qty'] - qty_vals_done.get(r['product_id'], 0.0))
|
||||
new_move = move_lines_obj.copy(cr, uid, moves_done.get(r['product_id']), default={'product_qty': new_qty})
|
||||
self.write(cr, uid, prod.id, {'move_lines': [(4, new_move)]})
|
||||
continue
|
||||
to_add = (r['product_qty'] - qty_vals_done.get(r['product_id'], 0.0)) - qty_vals.get(r['product_id'], 0.0)
|
||||
avail_qty = move_lines_obj.browse(cr, uid, moves[r['product_id']][0]).product_qty
|
||||
new_qty = avail_qty + to_add
|
||||
if new_qty == 0:
|
||||
move_lines_obj.write(cr, uid, moves[r['product_id']][0], {'state': 'draft'})
|
||||
move_lines_obj.unlink(cr, uid, moves[r['product_id']])
|
||||
elif new_qty < 0:
|
||||
avail_qty = move_lines_obj.browse(cr, uid, moves_done[r['product_id']][0]).product_qty
|
||||
move_lines_obj.unlink(cr, uid, moves[r['product_id']][0])
|
||||
move_lines_obj.write(cr, uid, moves_done[r['product_id']][0], {'product_qty': avail_qty + new_qty})
|
||||
else:
|
||||
move_lines_obj.write(cr, uid, moves[r['product_id']][0], {'product_qty': avail_qty + to_add})
|
||||
|
||||
# TODO:For Finished Product lines
|
||||
# product_lines_obj = self.pool.get('mrp.production.product.line')
|
||||
# for m in prod.move_created_ids:
|
||||
# move_lines_obj.write(cr, uid,m.id, {'product_qty' : new_qty})
|
||||
change(r['product_id'], r['product_qty'], qty_vals, \
|
||||
qty_vals_done, moves, moves_done, 'move_lines')
|
||||
|
||||
# For Finished Product lines
|
||||
qty_vals = {}
|
||||
qty_vals_done = {}
|
||||
moves = {}
|
||||
moves_done = {}
|
||||
for move in prod.move_created_ids:
|
||||
moves[move.product_id.id] = []
|
||||
qty_vals[move.product_id.id] = qty_vals.get(move.product_id.id, 0.0) + move.product_qty
|
||||
moves[move.product_id.id].append(move.id)
|
||||
for move in prod.move_created_ids2:
|
||||
moves_done[move.product_id.id] = []
|
||||
qty_vals_done[move.product_id.id] = qty_vals_done.get(move.product_id.id, 0.0) + move.product_qty
|
||||
moves_done[move.product_id.id].append(move.id)
|
||||
change(prod.product_id.id, prod.product_qty, qty_vals, \
|
||||
qty_vals_done, moves, moves_done, 'move_created_ids')
|
||||
return {}
|
||||
|
||||
mrp_production()
|
||||
|
||||
@@ -1460,8 +1460,8 @@ class stock_move(osv.osv):
|
||||
uos_qty_rest = split_by_qty / move.product_qty * move.product_uos_qty
|
||||
|
||||
update_val = {
|
||||
'product_qty': split_by_qty,
|
||||
'product_uos_qty': uos_qty,
|
||||
'product_qty': split_by_qty,
|
||||
'product_uos_qty': uos_qty,
|
||||
}
|
||||
for idx in range(int(quantity//split_by_qty)):
|
||||
if idx:
|
||||
@@ -1508,8 +1508,8 @@ class stock_move(osv.osv):
|
||||
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'location_id' : location_id or move.location_id.id,
|
||||
'product_uos_qty': uos_qty,
|
||||
'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)
|
||||
@@ -1545,8 +1545,8 @@ class stock_move(osv.osv):
|
||||
|
||||
default_val = {
|
||||
'product_qty': quantity,
|
||||
'product_uos_qty': uos_qty,
|
||||
'location_dest_id' : location_dest_id,
|
||||
'product_uos_qty': uos_qty,
|
||||
'location_dest_id': location_dest_id,
|
||||
'state': move.state
|
||||
}
|
||||
current_move = self.copy(cr, uid, move.id, default_val)
|
||||
|
||||
Reference in New Issue
Block a user