【发布时间】:2017-08-19 14:37:53
【问题描述】:
我正在覆盖 account.invoice 中的取消链接方法以允许删除最后一张发票。
这是我的代码:
class AccountInvoice(models.Model):
_inherit = "account.invoice"
@api.multi
def unlink(self):
for invoice in self:
if invoice.state not in ('draft', 'cancel'):
raise UserError(('You cannot delete an invoice which is not draft or cancelled. You should refund it instead.'))
elif invoice.move_name:
if invoice.journal_id.sequence_id:
sequence_id = invoice.journal_id.sequence_id
last_assigned_number = sequence_id.next_number_do_not_increase() - 1
last_assigned_number_text = sequence_id.get_next_char(last_assigned_number)
if last_assigned_number_text == invoice.move_name:
invoice.journal_id.sequence_id.write({'number_next': last_assigned_number})
else:
raise UserError(('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.'))
return super(AccountInvoice, self).unlink()
到目前为止一切顺利,
我的具体问题在最后一行,当我运行此代码流时,因此在此 ROUTINE 中没有引发 UserErrors,但随后它运行 super(AccountInvoice, self).unlink() 并执行旧代码形式 account_invoice .py:
@api.multi
def unlink(self):
for invoice in self:
if invoice.state not in ('draft', 'cancel'):
raise UserError(_('You cannot delete an invoice which is not draft or cancelled. You should refund it instead.'))
elif invoice.move_name:
raise UserError(_('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.'))
return super(AccountInvoice, self).unlink()
这会引发错误,我应该如何重写这个 unlink 方法以免发生这种情况?
【问题讨论】:
-
您能在问题中附上错误吗?