[FIX] purchase_requisition: duplicated stock moves

When a purchase requisition is created from a procurement order, a first stock move is created, not associated to any purchase orders
Then, on purchase order creation and confirmation, in the purchase requisition, new stock moves are created, associated to the purchase order.
The existing stock move issued from the procurement order which created the purchase requisition remained untouched, leading to wrong inventory values
To fix this, the destination location of the stock move of the procurement order is written on the source location
A proper fix should be to use a dedicated workflow for puchase requisition, but this can't be done in 7.0, it has to be done in master/trunk
This commit is contained in:
Denis Ledoux 2014-06-25 12:00:14 +02:00
parent 4bfcbb2a48
commit dee969929a
1 changed files with 6 additions and 2 deletions

View File

@ -73,7 +73,7 @@ class purchase_requisition(osv.osv):
if str(purchase_id.state) in('draft'):
purchase_order_obj.action_cancel(cr,uid,[purchase_id.id])
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', 'in', ids)], context=context)
self.pool['procurement.order'].write(cr, uid, procurement_ids, {'state': 'cancel'}, context=context)
self.pool['procurement.order'].action_done(cr, uid, procurement_ids)
return self.write(cr, uid, ids, {'state': 'cancel'})
def tender_in_progress(self, cr, uid, ids, context=None):
@ -84,7 +84,7 @@ class purchase_requisition(osv.osv):
def tender_done(self, cr, uid, ids, context=None):
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', 'in', ids)], context=context)
self.pool['procurement.order'].write(cr, uid, procurement_ids, {'state': 'done'}, context=context)
self.pool['procurement.order'].action_done(cr, uid, procurement_ids)
return self.write(cr, uid, ids, {'state':'done', 'date_end':time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
def _planned_date(self, requisition, delay=0.0):
@ -218,6 +218,10 @@ class purchase_order(osv.osv):
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'purchase.order', order.id, 'purchase_cancel', cr)
po.requisition_id.tender_done(context=context)
if po.requisition_id and all(purchase_id.state in ['draft', 'cancel'] for purchase_id in po.requisition_id.purchase_ids if purchase_id.id != po.id):
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', '=', po.requisition_id.id)], context=context)
for procurement in proc_obj.browse(cr, uid, procurement_ids, context=context):
procurement.move_id.write({'location_id': procurement.move_id.location_dest_id.id})
return res
purchase_order()