[IMP] issue #585361: give a more explicit error message when a user tries to delete an invoice that has been validated (i.e. assigned a sequence number)

also, replace the old fashioned exceptions with the new implementation (one rock, two birds)

bzr revid: abo@openerp.com-20130215171053-grkz9tkfsy2nkh3y
This commit is contained in:
Antonin Bourguignon 2013-02-15 18:10:53 +01:00
parent fe7dc3d817
commit 81037740e1
1 changed files with 7 additions and 3 deletions

View File

@ -451,11 +451,15 @@ class account_invoice(osv.osv):
context = {}
invoices = self.read(cr, uid, ids, ['state','internal_number'], context=context)
unlink_ids = []
for t in invoices:
if t['state'] in ('draft', 'cancel') and t['internal_number']== False:
unlink_ids.append(t['id'])
if t['state'] not in ('draft', 'cancel'):
raise openerp.exceptions.Warning(_('You cannot delete an invoice which is not cancelled. You should refund it instead.'))
elif t['internal_number'] == False:
raise openerp.exceptions.Warning(_('You cannot delete an invoice after it has been validated (and received a number). You can set it back to "Draft" state and modify its content, then re-confirm it.'))
else:
raise osv.except_osv(_('Invalid Action!'), _('You can not delete an invoice which is not cancelled. You should refund it instead.'))
unlink_ids.append(t['id'])
osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
return True