Getting "odoo.exceptions.ValidationError: ('Posted journal entry must have an unique sequence number per company'" when changing invoice stat

Getting "odoo.exceptions.ValidationError: ('Posted journal entry must have an unique sequence number per company'" when changing invoice stat

我正在尝试通过参考此文档使用 Web API (Python) 将已创建发票的状态从 'draft' 更改为 'posted':https://www.odoo.com/documentation/13.0/webservices/odoo.html

我正在按如下方式更新发票:

def makeInvoicePosted(invoice_id):

    invoice_ids = []

    invoice_ids.append(invoice_id)

    common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))

    print(common)

    uid = common.authenticate(db, username, password, {})

    print("makeInvoicePosted : Odoo Admin User Id : ", uid)

    models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

    models.execute_kw(db, uid, password, 'account.move', 'write', [[invoice_id], {'state':"posted"}])

但我收到此错误:odoo.exceptions.ValidationError: ('Posted journal entry must have an unique sequence number per company.', None)\n'

这可能是什么原因造成的?请求中是否缺少某些内容?

提前致谢!

我建议在这里通过调用post而不是直接写状态来使用Odoo的工作流和业务逻辑。

models.execute_kw(db, uid, password, 'account.move', 'post', [[invoice_id],])

原因:因为这个方法检查很多,做的事情也很多,可能会漏掉或者做错(发票很复杂)。由于其中的检查,您可能会在执行 post 之前的调用中发现一些错误。