From 7b31aa0eaa811a9a759fdf2d2ded19f8f297bb39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 19 Sep 2008 18:07:34 +0200 Subject: [PATCH] Add check for delete invoice that comes from a sale --- sale.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sale.py b/sale.py index 447afcf677..05b619a75a 100644 --- a/sale.py +++ b/sale.py @@ -1369,3 +1369,30 @@ class Move(OSV): return res Move() + + +class Invoice(OSV): + _name = 'account.invoice' + + def __init__(self): + super(Invoice, self).__init__() + self._error_messages.update({ + 'delete_sale_invoice': 'You can not delete invoices ' \ + 'that comes from a sale!', + }) + + 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 sale_invoices_rel ' \ + 'WHERE invoice IN (' + ','.join(['%s' for x in ids]) + ')', + ids) + if cursor.rowcount: + self.raise_user_error(cursor, 'delete_sale_invoice', + context=context) + return super(Invoice, self).delete(cursor, user, ids, + context=context) + +Invoice()