问题描述
我正在尝试通过参考以下文档,使用Web API(Python)将已创建的发票的状态从“草稿”更改为“已过帐”: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,'account.move','write',[[invoice_id],{'state':"posted"}])
但是我遇到了这个错误: odoo.exceptions.ValidationError :(“张贴的日记帐分录必须具有每个公司的唯一序列号。”,无)\ n'
这可能是什么原因造成的?请求中是否缺少某些内容?
谢谢!
解决方法
我建议在这里通过调用post
而不是直接编写状态来使用Odoo的工作流和业务逻辑。
models.execute_kw(db,uid,password,'account.move','post',[[invoice_id],])
为什么:因为用此方法进行了很多检查,并且还完成了很多事情,所以您可能会错过或做错了(发票非常复杂)。由于进行了检查,您可能会在进行post
之前就在呼叫中发现一些错误。