[IMP] Add test and moves state should only be recalculated after the quants have been moved

bzr revid: jco@openerp.com-20140418083539-njjh3kqwhdmiqcv5
This commit is contained in:
Josse Colpaert 2014-04-18 10:35:39 +02:00
parent 00708946e6
commit 6ea8251efb
2 changed files with 15 additions and 11 deletions

View File

@ -368,35 +368,32 @@ class stock_quant(osv.osv):
to_move_quants.append(quant)
quants_reconcile.append(quant)
if to_move_quants:
self.recalculate_other_move_states(cr, uid, to_move_quants, move, context=context)
other_moves = [x.reservation_id for x in to_move_quants if x.reservation_id and x.reservation_id.id != move.id]
self.move_quants_write(cr, uid, to_move_quants, move, location_to, dest_package_id, context=context)
self.recalculate_other_move_states(cr, uid, other_moves, context=context)
if location_to.usage == 'internal':
if self.search(cr, uid, [('product_id', '=', move.product_id.id), ('qty','<', 0)], limit=1, context=context):
for quant in quants_reconcile:
quant.refresh()
self._quant_reconcile_negative(cr, uid, quant, move, context=context)
def recalculate_other_move_states(self, cr, uid, quants, move, context=None):
def recalculate_other_move_states(self, cr, uid, other_moves, context=None):
move_obj = self.pool.get("stock.move")
other_moves = [x.reservation_id for x in quants if x.reservation_id and x.reservation_id.id != move.id]
for o_move in other_moves:
vals = {}
o_move.refresh()
reserved_quant_ids = o_move.reserved_quant_ids
if len(reserved_quant_ids) > 0 and not o_move.partially_available:
# Partially available is true
vals['partially_available'] = True
if len(reserved_quant_ids) == 0 and o_move.partially_available:
vals['partially_available'] = False
if o_move.state == 'assigned':
if move_obj.find_move_ancestors(cr, uid, move, context=context):
if move_obj.find_move_ancestors(cr, uid, o_move, context=context):
vals['state'] = 'waiting'
else:
vals['state'] = 'confirmed'
if vals:
move_obj.write(cr, uid, [o_move.id], vals, context=context)
def move_quants_write(self, cr, uid, quants, move, location_dest_id, dest_package_id, context=None):
vals = {'location_id': location_dest_id.id,
@ -1746,7 +1743,10 @@ class stock_move(osv.osv):
if move.state in ('done', 'cancel'):
raise osv.except_osv(_('Operation Forbidden!'), _('Cannot unreserve a done move'))
quant_obj.quants_unreserve(cr, uid, move, context=context)
self.write(cr, uid, [move.id], {'state': 'confirmed'}, context=context)
if self.find_move_ancestors(cr, uid, move, context=context):
self.write(cr, uid, [move.id], {'state': 'waiting'}, context=context)
else:
self.write(cr, uid, [move.id], {'state': 'confirmed'}, context=context)
def _prepare_procurement_from_move(self, cr, uid, move, context=None):
origin = (move.group_id and (move.group_id.name + ":") or "") + (move.rule_id and move.rule_id.name or "/")

View File

@ -95,7 +95,6 @@
pack_ids2 = [x.id for x in picking2.pack_operation_ids]
stock_pack.write(cr, uid, pack_ids1, {'picking_id': picking2.id})
stock_pack.write(cr, uid, pack_ids2, {'picking_id': picking1.id})
picking1.refresh()
-
Process this picking
-
@ -107,6 +106,11 @@
!python {model: stock.quant}: |
reco_id = self.search(cr ,uid , [('product_id','=',ref('product_wise')), ('qty', '<', 0.0)], context=context)
assert len(reco_id) == 0, 'This should not have created a negative quant'
-
Check the other delivery order has changed its state back to partially available
-
!python {model: stock.picking}: |
assert self.browse(cr, uid, ref('delivery_order_wise2')).state == 'partially_available', "Delivery order 2 should be back in confirmed state"
-
Process the second picking
-
@ -117,4 +121,4 @@
-
!python {model: stock.quant}: |
reco_id = self.search(cr ,uid , [('product_id','=',ref('product_wise'))], context=context)
assert all([x.location_id.id==ref('stock_location_customers') and x.qty > 0.0 for x in self.browse(cr, uid, reco_id)]), "Negative quant or wrong location detected"
assert all([x.location_id.id==ref('stock_location_customers') and x.qty > 0.0 for x in self.browse(cr, uid, reco_id)]), "Negative quant or wrong location detected"