controller authentication cross site – Odoo

import requests
from requests import Request,Session
import json

b_url = ""
# or "" (or whatever the ip is)
url = "{}/web/session/authenticate".format(b_url)

passwd = "<YOURPASSWORD>"

s = Session()

data = {
    'params': {
        'context': {},
        'db': db,
        'login': user,
        'password': passwd,

headers = {
    'Content-type': 'application/json'

req = Request('POST',url,data=json.dumps(data),headers=headers)

prepped = req.prepare()

resp = s.send(prepped)

session_id = json.loads(resp.text)['result']['session_id']


res = requests.get(b_url + "/your/controller/path",cookies={'session_id':str(session_id)})


redirect to view using python – odoo

    def redirect_opportunity_view(self):
        # Get opportunity views
        form_view = self.env.ref('crm.crm_case_form_view_oppor')
        tree_view = self.env.ref('crm.crm_case_tree_view_oppor')
        return {
            'name': _('Opportunity'),
            'view_type': 'form',
            'view_mode': 'tree, form',
            'res_model': 'crm.lead',
            'domain': [('type', '=', 'opportunity')],
            'view_id': False,
            'views': [
                (, 'form'),
                (, 'tree'),
                (False, 'kanban'),
                (False, 'calendar'),
                (False, 'graph')
            'type': 'ir.actions.act_window',
            'context': {'default_type': 'opportunity'}

merge same product id one2many odoo (group by dictionary python) – odoo

input = [
{'product_id': '001', 'location_id': 'NISR', 'qty': 100, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '001', 'location_id': 'NISR', 'qty': 200, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '001', 'location_id': 'NISR', 'qty': 300, 'uom_id': 'roll', 'cost' :50, 'categ_id': 'ALL'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 400, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 500, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '002', 'location_id': 'NISR', 'qty': 600, 'uom_id': 'roll', 'cost' :20, 'categ_id': 'ALL/SUB'},
{'product_id': '003', 'location_id': 'NISR', 'qty': 700, 'uom_id': 'roll', 'cost' :30, 'categ_id': 'ALL'},

grouper = itemgetter("product_id", "location_id", "uom_id" ,"cost")
result = []
for key, grp in groupby(sorted(input, key = grouper), grouper):
    temp_dict = dict(zip(["product_id", "location_id","uom_id", "cost"], key))
    temp_dict["categ_id"]=  (list(set(item["categ_id"] for item in grp))[0])
    temp_dict["qty"] = sum(item["qty"] for item in grp)
    temp_dict["amount"] =  temp_dict["cost"] * temp_dict["qty"]
from pprint import pprint

[{'amount': 0,
  'categ_id': 'ALL',
  'cost': 50,
  'location_id': 'NISR',
  'product_id': '001',
  'qty': 0,
  'uom_id': 'roll'},
 {'amount': 0,
  'categ_id': 'ALL/SUB',
  'cost': 20,
  'location_id': 'NISR',
  'product_id': '002',
  'qty': 0,
  'uom_id': 'roll'},
 {'amount': 0,
  'categ_id': 'ALL',
  'cost': 30,
  'location_id': 'NISR',
  'product_id': '003',
  'qty': 0,
  'uom_id': 'roll'}]

Mysql crashed and won’t start up

  1. Stop mysqld.
  2. Backup /var/lib/mysql/ib*
  3. Add the following line into /etc/my.cnf

innodb_force_recovery = 1 (they suggest 4, but its best to start with 1 and increment if it won’t start)

  1. Restart mysqld.
  2. Dump all tables:# mysqldump -A > dump.sql
  3. Drop all databases which need recovery.
  4. Stop mysqld.
  5. Remove /var/lib/mysql/ib*
  6. Comment out innodb_force_recovery in /etc/my.cnf
  7. Restart mysqld. Look at mysql error log. By default it should be /var/lib/mysql/server/ to see how it creates new ib* files.
  8. Restore databases from the dump:mysql < dump.sql

How to add custom font to qweb report

1). Create font folder under “module_name/static/src/fonts/”

2). create .css file (ref :

@font-face {
    font-family: 'calibri';
    src: url('../fonts/Calibri.eot'); /* IE9 Compat Modes */
    src: url('../fonts/Calibri.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
         url('../fonts/Calibri.woff2') format('woff2'), /* Super Modern Browsers */
         url('../fonts/Calibri.woff') format('woff'), /* Pretty Modern Browsers */
         url('../fonts/Calibri.ttf')  format('truetype'), /* Safari, Android, iOS */
         url('../fonts/Calibri.svg#Calibri') format('svg'); /* Legacy iOS */
    font:normal 12px calibri !important;
    text-align: center !important;
    color: #000000 !important;
    padding-top: 5px !important;

3). Add your new style sheet

<?xml version="1.0" encoding="UTF-8"?>
    <template inherit_id="report.minimal_layout" id="minimal_layout_inherit">
      <xpath expr="//head" position="inside">
             <link rel='stylesheet' href="/feag_header_footer/static/src/css/feag_layout_style.css"/>
             <link rel='stylesheet' href="/feag_header_footer/static/src/css/feag_report_style.css"/>

4). now you can use the class in HTML tags. eg.

Odoo PyCharm Templates

Templates for Odoo in PyCharm

This Templates can help you to develop Odoo Modules Faster and with no Typing Errors

Download odoo.xml file and place in pycharm template folder




If You are using a linux distribution you can save the XML file in PyCharm files, Just find the path:


MacOs X users, look for the templates folder here:


and save the XML file there. Enjoy your time developing great Odoo Modules 🙂

odoo 10 custom css for report

STEP 1: Create CSS file:-

We have to create CSS file in the following directory:

STEP 2: Give path of your CSS file:-

Now put the following code in the xml file of the report.
In this code I have inherited the “minimal_layout” template of the
layout.xml file of the report module and gave path of the CSS file.

<template id="minimal_layout_inherit" inherit_id="report.minimal_layout">
<xpath expr="//head" position="inside">
	<link rel='stylesheet' href="/<module_name>/static/src/css/<file_name>.css"/>

Setting up a Sharp network Printer on Ubuntu

Add below line on ppd file before you install

*OpenGroup: Authentication
*% Base JCL key code option 
*OpenUI JCLPasscode/Key Code: PickOne
*OrderDependency: 10 JCLSetup *JCLPasscode
*DefaultJCLPasscode: None
*JCLPasscode None/No Code: ""
*JCLPasscode 1111: "@PJL SET ACCOUNTNUMBER = \"1111\""
*JCLPasscode 2222: "@PJL SET ACCOUNTNUMBER = \"2222\""
*JCLPasscode 3333: "@PJL SET ACCOUNTNUMBER = \"3333\""
*CloseUI: *JCLPasscode
*% Custom JCL key code option 
*CustomJCLPasscode True: "@PJL SET ACCOUNTNUMBER = \"\1\""
*ParamCustomJCLPasscode Code/Key Code: 1 passcode 1 8
*CloseGroup: Authentication

go to ubuntu pc localhost:631/printers

Add new printer with ppd file.