Skip to main content


Showing posts from May, 2017

Odoo: Upload binary images from backend using API

If you want to upload a binary image to Odoo using are the steps: controllers/ # -*- coding: utf-8 -*- from import _ from odoo import http from odoo.http import request from odoo.addons import web from time import strftime import functools import datetime import json import base64 import sys import copy from dateutil import parser import logging from operator import itemgetter logger = logging.getLogger(__name__) def serialize_exception(f):     @functools.wraps(f)     def wrap(*args, **kwargs):         try:             return f(*args, **kwargs)         except Exception, e:             logger.debug("An exception occured during an http request")             #se = _serialize_exception(e)             error = {                 'code': 200,                 'message': "Odoo Server Error",                 'data': str(e)             }             return json.dumps(error)     return wrap class Binary(web.c

Write web services using Odoo controllers

In Odoo you can write web-services for the outside world. Let's discuss how it can be done using controllers. Suppose I need a cross-domain API that will return data in JSON format. For that, we have to enable CORS and have to setup nginx reverse proxy . Example: API to send teachers data from Odoo: # -*- coding: utf-8 -*- from import _ from odoo import http from odoo.http import request import json import sys class odoo_public_data(http.Controller):     @http.route('/get/teachers', type='http', methods=['GET'], auth="public")     def get_teachers(self, **kwargs):         teacher_model = request.env['dps.teacher']         teacher_ids = teacher_model.sudo().search([])         teacher_list = {'status': 1, 'data': []}         try:             if teacher_ids:                 for teacher in teacher_ids:                     vals = {                         'id':,    

Nginx reverse proxy on odoo

Let's discuss how to set nginx reverse proxy in odoo Why we need revese proxy? Odoo runs on 8069 port by default and if you want to route it through other port, say 80 we can use nginx reverse proxy for that. It will also help to handle web services, if any, your odoo instance is providing to outside world. What to do? 1. Install nginx 2. Create virtual host for your website/odoo instance. Let's say you want to run it on Please create config file at location: /etc/nginx/sites-available/ CREATE symbolic link for this at /etc/nginx/sites-enabled/ Following is the code for ssl enabled config file upstream myodoo {     server; } server {         listen 443 default;         server_name;         access_log /var/log/nginx/oddo.access.log;         error_log /var/log/nginx/oddo.error.log;         if ($scheme = http) {                 return 301 https://myodoo.domai