From 7566c520dba6bda42cf12b66652f74b2cb6b0aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 19 Sep 2008 18:06:15 +0200 Subject: [PATCH] Add check for delete invoice that comes from a purchase --- purchase.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/purchase.py b/purchase.py index fc0e804951..d81e209d8c 100644 --- a/purchase.py +++ b/purchase.py @@ -1433,3 +1433,30 @@ class OpenSupplier(Wizard): return res OpenSupplier() + + +class Invoice(OSV): + _name = 'account.invoice' + + def __init__(self): + super(Invoice, self).__init__() + self._error_messages.update({ + 'delete_purchase_invoice': 'You can not delete invoices ' \ + 'that comes from a purchase!', + }) + + def delete(self, cursor, user, ids, context=None): + if not ids: + return True + if isinstance(ids, (int, long)): + ids = [ids] + cursor.execute('SELECT id FROM purchase_invoices_rel ' \ + 'WHERE invoice IN (' + ','.join(['%s' for x in ids]) + ')', + ids) + if cursor.rowcount: + self.raise_user_error(cursor, 'delete_purchase_invoice', + context=context) + return super(Invoice, self).delete(cursor, user, ids, + context=context) + +Invoice()