@@ -498,6 +498,8 @@ def action_cancel_draft(self, cr, uid, ids, context=None):
498
498
if not len (ids ):
499
499
return False
500
500
self .write (cr , uid , ids , {'state' :'draft' ,'shipped' :0 })
501
+ for purchase in self .browse (cr , uid , ids , context = context ):
502
+ self .pool ['purchase.order.line' ].write (cr , uid , [l .id for l in purchase .order_line ], {'state' : 'draft' })
501
503
for p_id in ids :
502
504
# Deleting the existing instance of workflow for PO
503
505
self .delete_workflow (cr , uid , [p_id ]) # TODO is it necessary to interleave the calls?
@@ -593,6 +595,8 @@ def action_cancel(self, cr, uid, ids, context=None):
593
595
_ ('You must first cancel all receptions related to this purchase order.' ))
594
596
self .pool .get ('account.invoice' ) \
595
597
.signal_invoice_cancel (cr , uid , map (attrgetter ('id' ), purchase .invoice_ids ))
598
+ self .pool ['purchase.order.line' ].write (cr , uid , [l .id for l in purchase .order_line ],
599
+ {'state' : 'cancel' })
596
600
self .write (cr ,uid ,ids ,{'state' :'cancel' })
597
601
598
602
self .signal_purchase_cancel (cr , uid , ids )
@@ -903,6 +907,8 @@ def copy_data(self, cr, uid, id, default=None, context=None):
903
907
def unlink (self , cr , uid , ids , context = None ):
904
908
procurement_ids_to_cancel = []
905
909
for line in self .browse (cr , uid , ids , context = context ):
910
+ if line .state not in ['draft' , 'cancel' ]:
911
+ raise osv .except_osv (_ ('Invalid Action!' ), _ ('Cannot delete a purchase order line which is in state \' %s\' .' ) % (line .state ,))
906
912
if line .move_dest_id :
907
913
procurement_ids_to_cancel .extend (procurement .id for procurement in line .move_dest_id .procurements )
908
914
if procurement_ids_to_cancel :
0 commit comments