Odoo 10-覆盖取消链接方法 [英] Odoo 10 - Overriding unlink method

查看:125
本文介绍了Odoo 10-覆盖取消链接方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重写account.invoice的取消链接方法,以允许删除上次提出的发票.

I am overriding unlink method from account.invoice to allow delete last raised 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:

My specific question is on the last line, when I ran this code flows goes so no UserErrors are raised in this ROUTINE, but then it runs super(AccountInvoice, self).unlink() and it executes the old code form 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()

哪个会引发错误,我应该如何重写此取消链接方法,以免发生这种情况?

Which raises an error, how should I rewrite this unlink method so this does not happen?

推荐答案

不知道这项工作是否可以尝试.

Don't know if this work try it.

将发票的超级称呼为自己.

Call the super of invoice it self.

           super(invoice.AccountInvoice, self).unlink()

别忘了先导入发票.

这篇关于Odoo 10-覆盖取消链接方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆