【问题标题】:How can I get data from external API JSON file in ODOO如何从 ODOO 中的外部 API JSON 文件获取数据
【发布时间】:2021-07-06 08:30:03
【问题描述】:

[{"Id":"605a321e-7c10-49e4-9d34-ba03c4b34f69","Url":"","Type":"INBOUND_OUTBOUND", "ClearCurrentData":true,"FillOutFormFields":true,"RequestProtocol":"HTTP_REQUEST", "FileToSend":"NONE","SendDefaultData":false,"SendDetectionData":false,"ShowDialogMessage":false,"IsActive":false,"SendingTrigger":"MANUALLY","TCPSocketMethod":"","TriggerButtonName" :"获取数据"}]

这是一个外部 API 调用 JSON 文件,请问如何在 ODOO Any Solutions 中获取数据?

上面提到的代码 API JSON 文件 我只有外部 JSON 文件,没有表名和数据库名是否可以在 ODOO 中获取数据

【问题讨论】:

    标签: json postgresql odoo odoo-13


    【解决方案1】:

    为此数据创建一个模型,例如

    class apiCall(models.Model):
        _name = 'apiCall.api'
        id = fields.Char(string='Id')
        url = fields.Char(string='url')
        @api.model
        def call_api(self):
        ### result of calling external api is "result"
        for line of self:
            id =  result[0].Id
            url = result[0].url
    

    【讨论】:

      【解决方案2】:

      您可以在单击按钮时调用方法并访问 json 文件。下面是访问json文件的代码:-

      import json
      def api_call(self):
         
      
         # Opening JSON file
         f = open('file_name.json',)
      
         # returns JSON object as 
         # a dictionary
         data = json.load(f)
      
         # Iterating through the json
         # list
         for i in self:
             print(i)
      
         # Closing file
         f.close()
      

      以下是xml文件中应用的按钮代码:-

      <button name="api_call" type="object" string="Call API" class="oe_highlight" />
      

      通过这种方式你可以在odoo中调用带有外部api的json文件。

      【讨论】:

        猜你喜欢
        • 2021-04-25
        • 2013-11-03
        • 2017-12-31
        • 2013-05-06
        • 1970-01-01
        • 2019-11-14
        • 2019-11-19
        • 2017-07-06
        • 2015-12-07
        相关资源
        最近更新 更多