[IMP] Make sure the propagation of moves cancels procurements where necessary + manufacture and purchase cancel is not propagated by default

bzr revid: jco@openerp.com-20140423141700-60gbuxb4atp1z6ek
This commit is contained in:
Josse Colpaert 2014-04-23 16:17:00 +02:00
parent 8015980e33
commit 7a8222631e
4 changed files with 20 additions and 2 deletions

View File

@ -679,6 +679,11 @@ class mrp_production(osv.osv):
move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids])
move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines])
self.write(cr, uid, ids, {'state': 'cancel'})
# Put related procurements in exception
proc_obj = self.pool.get("procurement.order")
procs = proc_obj.search(cr, uid, [('production_id', 'in', ids)], context=context)
if procs:
proc_obj.write(cr, uid, procs, {'state': 'exception'}, context=context)
return True
def action_ready(self, cr, uid, ids, context=None):
@ -704,6 +709,10 @@ class mrp_production(osv.osv):
for production in self.browse(cr, uid, ids):
self._costs_generate(cr, uid, production)
write_res = self.write(cr, uid, ids, {'state': 'done', 'date_finished': time.strftime('%Y-%m-%d %H:%M:%S')})
# Check related procurements
proc_obj = self.pool.get("procurement.order")
procs = proc_obj.search(cr, uid, [('production_id', 'in', ids)], context=context)
proc_obj.check(cr, uid, procs, context=context)
return write_res
def test_production_done(self, cr, uid, ids):

View File

@ -227,7 +227,7 @@ class stock_warehouse(osv.osv):
'route_id': manufacture_route_id,
'action': 'manufacture',
'picking_type_id': warehouse.int_type_id.id,
'procure_method': 'make_to_order',
'propagate': False,
'warehouse_id': warehouse.id,
}

View File

@ -116,7 +116,7 @@ class stock_warehouse(osv.osv):
'route_id': buy_route_id,
'action': 'buy',
'picking_type_id': warehouse.in_type_id.id,
'procure_method': 'make_to_order',
'propagate': False,
'warehouse_id': warehouse.id,
}

View File

@ -2144,6 +2144,14 @@ class stock_move(osv.osv):
#cancel chained moves
if move.propagate:
self.action_cancel(cr, uid, [move.move_dest_id.id], context=context)
# If we have a long chain of moves to be cancelled, it is easier for the user to handle
# only the last procurement which will go into exception, instead of all procurements
# along the chain going into exception
if move.procurement_id:
proc = move.procurement_id
if all([x.state == 'cancel' for x in proc.move_orig_ids]):
procurement_obj.write(cr, uid, [proc.id], {'state': 'cancel'})
elif move.move_dest_id.state == 'waiting':
self.write(cr, uid, [move.move_dest_id.id], {'state': 'confirmed'}, context=context)
return self.write(cr, uid, ids, {'state': 'cancel', 'move_dest_id': False}, context=context)
@ -2360,6 +2368,7 @@ class stock_move(osv.osv):
'restrict_lot_id': restrict_lot_id,
'restrict_partner_id': restrict_partner_id,
'split_from': move.id,
'move_dest_id': move.move_dest_id.id,
}
if context.get('source_location_id'):
defaults['location_id'] = context['source_location_id']