首页 文章

如何将静态文件夹添加到我的Odoo自定义模块?

提问于
浏览
1

如何添加一个静态文件夹,其中包含某些SOAP客户端所需的wsdl和xsd文件,以及它与我的Odoo 11自定义模块的相关路径?

------------ ---------更新

我在我的模块中创建了一个静态文件夹,其中包含src文件夹,其中包含我想要的文件 . 需要从我的控制器访问这些文件的正确完整路径是什么?我应该在使用之前在任何地方添加路径吗?

这是我的控制器,我试图使用这些文件:

Check the path given to the client(zeep_test/static/src/uhud/Uhud.wsdl)

from zeep import Client, Settings, xsd
import datetime
from odoo import http
from lxml.etree import tostring

class WaseelCrm(http.Controller):
   @http.route('/test/zeep', type='json', methods=['POST'], auth="public", website=True, csrf=False)
   def test_zeep(self):
       settings = Settings(strict=False, xml_huge_tree=True)
       client = Client('zeep_test/static/src/uhud/Uhud.wsdl', settings=settings)

       factory = client.type_factory('ns0')

       transaction = factory.TransactionCT('1.1', 'NEW', None, None, 'REQUEST')
       user = factory.UserCT('admin', 'admin', 'Ahmed Yasser')
       interaction = factory.InteractionCT(None, 102, 2260, 101)

       timestamp = datetime.datetime.combine(datetime.datetime.now(), datetime.time(10, 23))

       cmh = factory.MessageHeaderCT(transaction, interaction, user, timestamp)

       member = factory.MemberCT('0020693108', '20693101', '158')
       visitInfo = factory.visitInfoCT(timestamp, 7, 'NEW')
       eligibilityRequest = factory.EligibilitySubmissionRequestCT(member, visitInfo)

       with client.settings(raw_response=False):
           response = client.service.submitSchema(CommonMessageHeader=cmh,
                                                  EligibilitySubmissionRequest=eligibilityRequest)

       return response

This is where these files exist Folder's Path

3 回答

  • 1

    好吧我不知道所有的答案是否正确但是如果你想找到你的costum模块的路径是这样的 .

    # you need http this
            import os
            from odoo import http
            # from openerp import http
    
    
    
           # in your method to find the path of your costum module
           file_path = http.addons_manifest['zeep_test']['addons_path'] # I really forget the key but you can check controllers in web module you find plenty of examples there
           # now you can join this file path with your static folder use os for this to handle multi platform
           file_path = os.path.join('zeep_test', 'static', 'src', 'uhud','Uhud.wsdl')
           # and now file_path have the right path for your file
    

    添加addons_manifest插件的一件事必须有静态文件夹 . 你不应该有这个问题,因为你有这个 .

    如果你只是在python中访问这些文件,有一件事就是将它们从静态文件夹中删除以保护它们

  • 0

    感谢您使用更具体的详细信息和代码更新问题 . 您正在尝试从Odoo Python代码访问wsdl,而不是外部作为Odoo发布的静态http内容 .

    我看到你有四种可能的方法来解决这个问题:

    • 使用相对路径访问wsdl并修改代码以使其成为可能 . 这是首选方式 . 此代码在控制器中运行,或在模块根目录下一级别的任何其他目录中的python代码中运行 .
    wsdlpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../zeep_test/static/src/uhud/Uhud.wsdl')
    client = Client(wsdlpath, settings=settings)
    
    • 使用绝对路径访问wsdl . 更新代码以在zeep客户端调用中包含完整的绝对路径 . 在此选项中,您需要对绝对路径进行硬编码 . 这有效但不好 .
    client = Client('/mnt/extra-addons/zeep_test/static/src/uhud/Uhud.wsdl', settings=settings)
    
    • 通过带有http地址的Odoo http服务访问wsdl . 在此解决方案中,您需要在Odoo服务器看到它时对您的Odoo地址进行硬编码 .
    client = Client('http://localhost:8069/zeep_test/static/src/uhud/Uhud.wsdl', settings=settings)
    
    • 直接从SOAP服务提供者访问wsdl . 有了这个,你需要从服务提供商访问wsdl . 这样你就不需要本地的wsdl了 .
    client = Client('https://serviceprovider.com/xx/yy/Uhud.wsdl', settings=settings)
    

    目前,您将wsdl放在公共可用的静态文件夹中 . 你真的想在你的Odoo中发布这个吗?如果你没有特别的意图,我会考虑不发表这个 . 如果您使用内部地址(案例1和2)从代码中引用此文件,则无需发布它 .

  • 0

    您可以构建一个Odoo模块,并将静态wsdl和xsd包含在名为static的模块文件夹中 . 您可以从以下资源中找到有关创建模块的更多信息和帮助:

    如果您无法从Odoo参考资源中找到特定编程挑战的答案,那么在创建模块时,请考虑在Stack Overflow中询问 . 对于Stack Overflow问题,请提供准确且可重现的问题代码,以便人们可以帮助您 . 您可以在https://stackoverflow.com/help/how-to-ask找到有关好问题的说明 . 欢迎来到Stack Overflow,Zatar .

相关问题