这是我为奥多v.12找到答案的唯一方法。在我的头不断地撞在砖墙上之后。我的示例编程语言是Python 3,而不是C#,但我相信您可以修改它。
odoo_url_host = "https://company.odoo.com"
访问令牌
invoice_id = 1234
models = xmlrpcclient.ServerProxy('{}/xmlrpc/2/object'.format(odoo_url_host))
invoice = models.execute_kw(db, uid, password, "account.invoice", read, [[invoice_id]])
如果你找到一张发票,你可以使用这样的回复:
print(invoice["access_token"])
download_url = "%s/%s/my/invoices/%d?report_type=pdf&download=true&access_token=%s" % (odoo_url_host, invoice_id, invoice["access_token"])
如果您只是想自动下载,可以这样做:
import urllib.request
pdf_destination = "./invoices/invoice-%d.pdf" % invoice_id
urllib.request.urlretrieve(download_url, pdf_destination)
您需要更改为Python2.7编写的方式。
另外,请确保单击发票上的“共享”(在odoo中),因为有时不会为该发票生成访问令牌,否则返回false。
ctx = {'active_model': 'account.invoice', 'active_id': invoice_id}
print(models.execute_kw(db, uid, password, 'portal.share', 'default_get',[{}],{'context': ctx}))
这将使您获得整个文档的共享链接,但您只需要生成访问令牌。如果您愿意,可以从JSON响应中的share_link值中提取access_令牌。无论如何:)快乐的编码。