Skip to Content
Menu
This question has been flagged
4 Replies
8683 Views

Hi ! please can someone tell me how to parse an WSDL file in python and how to display the result in a tree view ?

Avatar
Discard

Hello, I think your question is too short, you should describle your problem in more details like: How is your WSDL file got read by Odoo? is it in your server file system? To display data in a tree view, after parsing wsdl file, you may create a set of records and display it like other models.

Author

Hi Thanh Loyal ! Thank you for your response : ) so I connect to the url of my WSDL with the suds library (Python 2.7.9) and this is the code : import suds from suds.client import Client from suds.transport.https import WindowsHttpAuthenticated ntlm = WindowsHttpAuthenticated(username='xxxxx', password='yyyyy') url = 'http://xxxxxxx' client = Client(url, transport=ntlm) print (client) # this will return the methods and types available from the codeunit result = client.service.ReadMultiple() client.service.ReadMultiple() return an array that contain objects and I want to display this list of object in a tree view, that's why I create a new class which its attributs are computed fields that contain the fields of the object returned by the web service . Code : class ProductImpo(models.Model): _name = 'product.impo' ...... Serial_No = fields.Char(string="N° de série", compute='_compute_serial_no') ....... And the function code is : @api.multi def _compute_serial_no(self): i=-1 for record in self: i=i+1 record.Serial_No=result.Stock_Vehicule[i].Serial_No And the view : product.impo.tree product.impo ..... .... For this exemple the array returned contain 14 rows so those 14 rows are displayed in the tree view only if I create manually 14 rows empty just with ID in the table ProductImpo in PostgreSQL so my question is how to create a new row in the table by using python adding rows = len(result.Stock_Vehicule) PS : Stock_Vehicule is the arry returned which is 14 in this example

Best Answer

Hi,

Your question is clearer now.

I dont know when your first python code section runs? I usually write functions in a model class or in a controller.

And I think you may follow these steps:

1. Retrieve the model

   1.1 In case of a model class

     product_impo = self.env['product.impo']

   1.2 In case of a controller:

     product_impo = http.request.env['product.impo']


2. Write data that your client retrieved to DB using the above model:

     # for each row in 14 rows

   product_impo.sudo().write({   # think more about sudo() for more secure

     'Serial_No': self.Serial_No # If your method is in a Model class

  })


OR


   product_impo.sudo().write({

     'Serial_No': row.Serial_No # If your method is in a controller

  })

Avatar
Discard
Author Best Answer

Hi Thanh Loyal ! Thank you for your response : ) so I connect to the url of my WSDL with the suds library (Python 2.7.9) and this is the code :

import suds

from suds.client import Client

from suds.transport.https import WindowsHttpAuthenticated

 ntlm = WindowsHttpAuthenticated(username='xxxxx', password='yyyyy')

url = 'http://xxxxxxx'

client = Client(url, transport=ntlm)

print (client) # this will return the methods and types available from the codeunit

result = client.service.ReadMultiple()

client.service.ReadMultiple() return an array that contain objects and I want to display this list of object in a tree view, that's why I create a new class which its attributs are computed fields that contain the fields of the object returned by the web service . Code :

class ProductImpo(models.Model):

_name = 'product.impo'

......

Serial_No = fields.Char(string="N° de série", compute='_compute_serial_no')

.......

and the function code is :

@api.multi

def _compute_serial_no(self):

i=-1

for record in self:

i=i+1

record.Serial_No=result.Stock_Vehicule[i].Serial_No

and the view :

<record id="product_impo_tree_view" model="ir.ui.view">

<field name="name">product.impo.tree</field>

<field name="model">product.impo</field>

<field name="arch" type="xml">

<tree string="Disponibilité">

.....

<field name="Serial_No"/>

....

</tree>

</field>

</record>

For this exemple the array returned contain 14 rows so those 14 rows are displayed in the tree view only if I create manually 14 rows empty just with ID in the table ProductImpo in PostgreSQL so my question is how to create a new row in the table by using python adding rows = len(result.Stock_Vehicule)

PS : Stock_Vehicule is the arry returned which is 14 in this example

Avatar
Discard
Author

when I try to retrieve the model I obtain this error : impo_obj = self.env['product.impo'] NameError: name 'self' is not defined and this is the code : class ProductImpo(models.Model): _name = 'product.impo' ..... Serial_No = fields.Char(string="N° de série", compute='_compute_serial_no') ...... impo_obj = self.env['product.impo'] ...... When I try to put it in a function like : def _tester(self): impo_obj = self.env['product.impo'] ...... after that when I call the function self still inknown

Related Posts Replies Views Activity
1
Jul 19
2786
3
Aug 23
8898
1
Jan 16
2715
1
Nov 15
5259
0
Feb 16
2393