From cf44ee9eb130c1d8acf29e9f211ac753efdc26dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 3 Apr 2012 12:16:43 +0200 Subject: [PATCH] Allow only deleting cancelled workflowed models review317001 --- invoice.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/invoice.py b/invoice.py index dd819b439f..fbba3da294 100644 --- a/invoice.py +++ b/invoice.py @@ -176,6 +176,7 @@ class Invoice(Workflow, ModelSQL, ModelView): 'with account from a different invoice company!', 'same_account_on_line': 'You can not use the same account\n' \ 'as on invoice line!', + 'delete_cancel': 'Invoice "%s" must be cancelled before deletion!', }) self._transitions |= set(( ('draft', 'proforma'), @@ -957,6 +958,11 @@ class Invoice(Workflow, ModelSQL, ModelView): if isinstance(ids, (int, long)): ids = [ids] self.check_modify(ids) + # Cancel before delete + self.cancel(ids) + for invoice in self.browse(ids): + if invoice.state != 'cancel': + self.raise_user_error('delete_cancel', invoice.rec_name) return super(Invoice, self).delete(ids) def write(self, ids, vals):