How to get data from URL with a controller in Odoo 9

Create under your module a folder controller, then in that folder create a file and then link your new file in, don’t forget to link your new folder in the at the root folder of your module. code bellow will make available the URL, random_variable value will be stored in values dictionary on key variable.

import openerp.http as http
from openerp.http import request
import logging
_logger = logging.getLogger(__name__)

class Controller(http.Controller):

                type='http', auth="user", methods=['GET'], website=True)
    def view(self, **kwargs):
        values = dict(kwargs)
        object_ids = request.env[''].search([('your_field','=', values['variable'])])
        values['object_ids'] = object_ids
        values['customer'] = object_ids[0]
        return request.render('module.template_id', values)

in folder view of your module create the file template.xml

	<template id="template_id" name="template Name">
			<meta charset="utf-8" />
			<meta http-equiv="X-UA-Compatible" content="IE=edge" />
			<meta name="viewport" content="width=device-width, initial-scale=1" />
                <div class="container">
				<span t-field="variable" />

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.