在 Odoo 17 中使用 API 调用创建发票附件

问题描述 投票:0回答:1

我目前正在使用 Odoo 17 API 从 Node.js 服务器通过电子邮件发送发票。我已经成功处理了大部分任务,但在尝试通过电子邮件发送发票时遇到了问题。发票不是作为附件发送,而是作为链接包含在电子邮件中。

了解要将发票附加为 PDF 文件,我需要进行如下 API 调用:

{
    "jsonrpc": "2.0",
    "method": "call",
    "params": {
        "service": "object",
        "method": "execute_kw",

        "args": [
            "{{db}}",
            "{{uid}}",
            "{{password}}",
            "ir.attachment",
            "create",
          [{
        "name": "Invoice.pdf", 
        "type": "binary",  
        "res_model": "account.move",
        "datas": "base64 data",
        "res_id": 17, 
        "mimetype": "application/pdf" 
      }]
        ]
    }
}

但首先我需要以某种方式将数据编码为 Base64 格式。是否有 Odoo API 方法可以直接对文件进行编码?或者也许 Odoo 中有一个设置可以在创建发票时自动将发票添加为附件,而不是通过 API 手动处理附件?

提前致谢!

odoo odoo-17
1个回答
0
投票

我想我可以只使用电子邮件模板。然后附件就会自动添加。 API调用的主体如下:

{ "jsonrpc": "2.0", "method": "call", "params": { "service": "object", "method": "execute_kw", "args": [ "{{db}}", "{{uid}}", "{{password}}", "mail.template", "send_mail", [12, 50], { "force_send": "True" } ] }, "id": 5 }

© www.soinside.com 2019 - 2024. All rights reserved.