+ def action_cancel(self, cr, uid, ids, context={}):
+ ok = True
+ purchase_order_line_obj = self.pool.get('purchase.order.line')
+ for purchase in self.browse(cr, uid, ids):
+ for pick in purchase.picking_ids:
+ if pick.state not in ('draft','cancel'):
+ raise osv.except_osv(
+ _('Could not cancel purchase order !'),
+ _('You must first cancel all packings attached to this purchase order.'))
+ for pick in purchase.picking_ids:
+ wf_service = netsvc.LocalService("workflow")
+ wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_cancel', cr)
+ inv = purchase.invoice_id
+ if inv and inv.state not in ('cancel','draft'):
+ raise osv.except_osv(
+ _('Could not cancel this purchase order !'),
+ _('You must first cancel all invoices attached to this purchase order.'))
+ if inv:
+ wf_service = netsvc.LocalService("workflow")
+ wf_service.trg_validate(uid, 'account.invoice', inv.id, 'invoice_cancel', cr)
+ self.write(cr,uid,ids,{'state':'cancel'})
+ return True
+