Reputation: 13
How to add a static folder, which contains wsdl and xsd files needed for some SOAP client,and its related path to my Odoo 11 custom Module?
------------Update---------
I created a static folder in my module with src folder inside it which holds the files I want. Need to access these files from my controller what is the right full path? Should i add the path anywhere before using it?
This is my controller where am trying to use the files:
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
Upvotes: 1
Views: 1929
Reputation: 3610
You can build an Odoo module and include your static wsdl and xsd in the module folder named static. You can find more information and help for creating a module from these resources:
Upvotes: 0
Reputation: 3610
Thanks for updating the question with more specific details and code. You are trying to access the wsdl from Odoo Python Code, not externally as a static http content published by Odoo.
I see you have four possible ways to solve this:
Access the wsdl with relative path and modify your code to make this possible. This is the preferred way. This code works in controllers, or in python code in any other directory one level below module root directory.
wsdlpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../zeep_test/static/src/uhud/Uhud.wsdl')
client = Client(wsdlpath, settings=settings)
Access the wsdl with an absolute path. Update your code to include full absolute path in zeep Client call. In this option you need to hard code your absolute path. This works but is not good.
client = Client('/mnt/extra-addons/zeep_test/static/src/uhud/Uhud.wsdl', settings=settings)
Access the wsdl via Odoo http service with http address. In this solution you need to hard code your Odoo address as your Odoo server sees it.
client = Client('http://localhost:8069/zeep_test/static/src/uhud/Uhud.wsdl', settings=settings)
Access the wsdl directly from the SOAP service provider. With this you need to have the wsdl accessible from the service provider. This way you would not need the wsdl locally.
client = Client('https://serviceprovider.com/xx/yy/Uhud.wsdl', settings=settings)
Currently you have your wsdl in a publicly available static folder. Do you really want to publish this in your Odoo? I would consider not publishing this if you do not specially have that intent. If you refer to this file from your code with internal address (cases 1 and 2), you do not need to publish it.
Upvotes: 1