Odoo 10 - 检索发票序列的值

我想覆盖 account.invoice 模型的 unlink 方法。

目前这种方法是:

@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()

如果已分配 move_name(即为此发票指定了有效序列),则它不会让您删除发票。虽然这是一个完美无瑕的会计规则,但它反映了对某些业务的现实世界运营的了解不足,您实际上需要删除发票。

所以我想允许用户删除最后一张发票,即使它被提出。

为此,需要以编程方式(在 python 擦除方法中)执行以下操作:

  1. 识别适用于该发票的序列 ID
  2. 检查 move_name 的值是否与该序列生成的最后一个值匹配
  3. 如果是,删除发票并从序列的下一个值中减去一个

有人可以帮助强调如何实现这三个步骤(特别是第一个步骤)。

谢谢,

普拉维塔五世

这是您的第一个查询的答案:

查询:如何识别适用于该发票的序列号?

代码:

@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:
                print "movename", invoice.move_name
                if invoice.journal_id.sequence_id:
                    sequence_id = invoice.journal_id.sequence_id.id
                    print sequence_id
                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()

我对你的第二和第三个问题有点困惑,因为,考虑到有 5 张发票已验证/处于打开状态,并且你想删除invoice no:3. 因此,根据您的要求,您将检查 move_name 的值是否与标识序列生成的最后一个值匹配,如果匹配,您将从1序列的 next_value 中减去

因此,序列的 next_value 将成为5,当您创建另一个发票时,序列号将被复制,因为invoice no:5这将违反序列的唯一约束。

如果您希望您的用户只删除最后创建的发票,那么没问题。

所以想一想,希望我的回答对你有所帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章