Odoo Aide

0

1
11 Answers
1
Avatar

Axel Mendoza

--Axel Mendoza--
13583
| 8 8 10
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
29/07/2015 12:02

You could use something like this(this is an api test model that I create):

from openerp.osv import fields, osv
import requests

class solt_http_test(osv.osv): _name = 'solt.http.test' _columns = { 'name': fields.char('URL', size=1024), 'method': fields.selection([('post', 'POST'), ('get', 'GET'), ('put', 'PUT'), ('patch', 'PATCH'), ('delete', 'DELETE')], string='HTTP Method'), 'user': fields.char('User', size=64), 'password': fields.char('Password', size=64), 'content': fields.text('Content'), 'response': fields.text('Response'), } def action_request(self, cr, uid, ids, context=None): for test in self.browse(cr, uid, ids,context): auth = None if test.user and test.password: auth = (test.user,test.password) headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} result = getattr(requests, test.method)(test.name, test.content, auth=auth, headers=headers) test.write({'response':result.text}) return True solt_http_test()

Modify this for your convenience. Here is the views, action and menu i use:

        <record id="solt_http_test_form_view" model="ir.ui.view">
<field name="name">solt.http.test.form</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<form string="HTTP Test" version="7.0">
<header>
<button name="action_request" string="Test" type="object" icon="gtk-go-forward"/>
</header>
<sheet layout="auto">
<group colspan="6">
<field name="name"/>
<field name="method"/>
<field name="user"/>
<field name="password"/>
</group>
<group>
<field name="content"/>
</group>
<group>
<field name="response"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="solt_http_test_tree_view" model="ir.ui.view">
<field name="name">solt.http.test.model.tree</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<tree string="HTTP Test" version="7.0">
<field name="name"/>
<field name="method"/>
</tree>
</field>
</record>
<record id="solt_http_test_action" model="ir.actions.act_window">
<field name="name">HTTP Tests</field>
<field name="res_model">solt.http.test</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="API Tests" id="solt_rest_weaver_menu" parent="base.menu_administration" sequence="5"/> 
<menuitem name="HTTP Tests" id="solt_http_test_submenu" parent="solt_rest_weaver_menu" action="solt_http_test_action" sequence="2"/>



7 Comments
Odoo
18/08/2015 07:58

Hi All, What information I can pass in this fields ,I mean URL HTTP Method User Password Content Response 'name': fields.char('URL', size=1024), 'method': fields.selection([('post', 'POST'), ('get', 'GET'), ('put', 'PUT'), ('patch', 'PATCH'), ('delete', 'DELETE')], string='HTTP Method'), 'user': fields.char('User', size=64), 'password': fields.char('Password', size=64), 'content': fields.text('Content'), 'response': fields.text('Response'),

Odoo
18/08/2015 07:59

Can you explain with an example?

Axel Mendoza
18/08/2015 12:10

Just install it packaged in a module and use it throw the view, for example with url like http://google.com, and method get

Odoo
20/08/2015 01:55

I got this Error result = getattr(requests, test.method)(test.name, test.content, auth=auth, headers=headers) TypeError: get() takes exactly 1 argument (4 given)

Odoo
20/08/2015 01:56

When I try using GET Method ...

Odoo
20/08/2015 01:58

I try with google.com, and method is GET ,but i got above error also here what is the username=? and password=? Need a help...........Axel

Axel Mendoza
20/08/2015 02:16

The error of get that takes 1arg and received 4 is related to the version that you are using of requests. You need to adjust to the http methods signature of your requests version. The username and password refers to http basic auth

0
stanislav ploschansky
02/07/2018 10:30

Alex,  thank you for posting this. I'm a newbie in Odoo and need to integrate auto action to our system (asap as usually:) 
I'm stucked currently with initial step:
    import requests
It gives me following error:
   Odoo Server Error - Validation Error: forbidden opcode(s) in 'import Requests': IMPORT_NAME.

Could someone give me a hint how to enable using "requests"?

8 Comments
Axel Mendoza
02/07/2018 10:57

requests is this library at: http://docs.python-requests.org

you need to install it first,

pip install requests

should works

eSystems Nordic Oy, stanislav ploschansky
02/07/2018 11:01

Thank you for answer! But ... is that possible to do for free edition of Odoo? Is there some kind of sandbox to install external modules?

Axel Mendoza
02/07/2018 11:06

Yes, of course, Odoo is Open Core so as long as you know what you do you could do anything

eSystems Nordic Oy, stanislav ploschansky
02/07/2018 11:13

that's cool! But i'm using Odoo like https://my.odoo.com, so where is console to install module? Or should I use Install Model from UI menu (which expect ZIP file) and prepare it first from docs.python-requests.org?

Axel Mendoza
02/07/2018 11:22

No way then to do it, since you don't have the permissions to do the required installs and customizations

eSystems Nordic Oy, stanislav ploschansky
02/07/2018 11:35

arg... bad news. Could you recommend some else way to have automated actions for integration purpose? I need to setup some trigger on changes in Odoo and hit another system then. Or only the way is have own installation of Odoo?

Axel Mendoza
02/07/2018 11:47

Your issue doesn't seems to be with requests, since that library is included as a python dependency in requirements.txt

The issue seems to be in the place where your code is located or the way it's loaded. Maybe it's because you are importing the module or something. Maybe you need to install on promise or on own your cloud server vps

eSystems Nordic Oy, stanislav ploschansky
02/07/2018 11:53

OK, thank you once again! I'll try find a way to continue.

0
Yves Goldberg
15/08/2015 03:40

Thank you Axel

Poser une question
Writer
Étiquettes
Keep Informed
3 Abonné(e)s
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now