Odoo Ayuda

0

1
6 Respuestas
1
Avatar

Fernando La Chica Mera España

--Fernando La Chica Mera--
6540
| 6 2 6
San José de La Rinconada, España
--Fernando La Chica Mera--

Soy programador con más de 15 años de experiencia. Casi toda mi carrera profesional ha girado entorno al mundo de los ERP. Conozco el modelo de desarrollo de Openbravo, de openXpertya y Libertya pero el método que propone Odoo es el que más me gusta.

I am a programmer with over 15 years of experience where most of my professional career revolved around the world of ERP . I know the Openbravo development model of openXpertya and Libertya but that Odoo method proposed is the one I like.

Fernando La Chica Mera España
23/3/16 8:45

I managed to consume the XML-RPC service from a Web App. I use https://github.com/timheap/jquery-xmlrpc

To make it work I had to modify the file <Odoo> /openerp/service/wsgi_server.py in the following procedures


def xmlrpc_return(start_response, service, method, params, string_faultcode=False):

"""

Helper to call a service's method with some params, using a wsgi-supplied

``start_response`` callback.

This is the place to look at to see the mapping between core exceptions

and XML-RPC fault codes.

"""

# Map OpenERP core exceptions to XML-RPC fault codes. Specific exceptions

# defined in ``openerp.exceptions`` are mapped to specific fault codes;

# all the other exceptions are mapped to the generic

# RPC_FAULT_CODE_APPLICATION_ERROR value.

# This also mimics SimpleXMLRPCDispatcher._marshaled_dispatch() for

# exception handling.

try:

result = openerp.http.dispatch_rpc(service, method, params)

response = xmlrpclib.dumps((result,), methodresponse=1, allow_none=False, encoding=None)

except Exception, e:

if string_faultcode:

response = xmlrpc_handle_exception_string(e)

else:

response = xmlrpc_handle_exception_int(e)

start_response("200 OK", [

('Content-Type','text/xml'),('Content-Length', str(len(response))),

('Access-Control-Allow-Origin','*'),

('Access-Control-Allow-Methods','POST, GET, OPTIONS'),

('Access-Control-Max-Age',1000),

('Access-Control-Allow-Headers','origin, x-csrftoken, content-type, accept'),

]

)

return [response]

def wsgi_xmlrpc(environ, start_response):

""" Two routes are available for XML-RPC

/xmlrpc/<service> route returns faultCode as strings. This is a historic

violation of the protocol kept for compatibility.

/xmlrpc/2/<service> is a new route that returns faultCode as int and is

therefore fully compliant.

"""

if environ['REQUEST_METHOD'] == "OPTIONS":

response = werkzeug.wrappers.Response('OPTIONS METHOD DETECTED')

response.headers['Access-Control-Allow-Origin'] = '*'

response.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'

response.headers['Access-Control-Max-Age'] = 1000

# note that '*' is not valid for Access-Control-Allow-Headers

response.headers['Access-Control-Allow-Headers'] = 'origin, x-csrftoken, content-type, accept'

return response(environ, start_response)

if environ['REQUEST_METHOD'] == 'POST' and environ['PATH_INFO'].startswith('/xmlrpc/'):

length = int(environ['CONTENT_LENGTH'])

data = environ['wsgi.input'].read(length)

# Distinguish betweed the 2 faultCode modes

string_faultcode = True

if environ['PATH_INFO'].startswith('/xmlrpc/2/'):

service = environ['PATH_INFO'][len('/xmlrpc/2/'):]

string_faultcode = False

else:

service = environ['PATH_INFO'][len('/xmlrpc/'):]

params, method = xmlrpclib.loads(data)

return xmlrpc_return(start_response, service, method, params, string_faultcode)



Would you know tell me how to take these changes into an installable module? Would I have to go into the core?

2 Comentarios
El mehdi EL OUALI Marruecos
15/8/19 19:00

hi Fernando

I want to make ionic app to get data from odoo 12 server and i have been blocked by CORS policy, you have any solution for my issue

Fernando La Chica Mera España
16/8/19 5:48

I'm sorry I can't help you. This solution I implemented was used in older versions of Odoo and I don't think it works in a current one. Surely someone knows what settings they should apply to not be blocked by CORS. If not, doing something similar should serve you.

0
Avatar

Ravi Gadhia India

--Ravi Gadhia--

8504
| 2 2 5
Gandhinagar, India
--Ravi Gadhia--


Ravi Gadhia India
13/9/19 1:37

Hi

To enable CORS for a particular route/endpoint you can pass cors params on a route like

@http.route('/my/route', type='json', auth='none', cors='*')  

def my_route(self):      

        ........

if you want to enable CORS for all the routes(not recommended) here are few options​

  • override werkzeug Response wrapper class ref \https://github.com/odoo/odoo/blob/12.0/odoo/http.py#L1245  

  • Nginx configuration can enable CORS

  • you can create werkzeug middleware for it

0
Carlos España
12/9/19 8:06

I Want to make the same in Angular 7 i need somthing to avoid cors ¿any help?

Realizar una pregunta
Keep Informed
1 seguidor(es)
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