How to call python function from QWeb

.xml code

<t t-foreach="o._get_purchase_mrn_details(o.origin,pack_operation.product_id)" t-as="purchase_line">
   <td class="text-right"><span t-esc="purchase_line['price_unit']"/></td>                            
   <td class="text-right"><span t-esc="purchase_line['taxes_id']"/></td>   
<span t-if ="o.get_issuenote_title() == 'Issue'">ISSUE NOTE</span> 

.py code

    def _get_purchase_mrn_details(self,origin,product_id):
        if origin and product_id:
            purchase_data = []
            purchase_order_obj = self.env['purchase.order'].search([('name','=',origin)])
            order_line_ids = purchase_order_obj.order_line.mapped('product_id')
            for line in purchase_order_obj.order_line:
                if ==
                    purchase_data.append ({
                        'price_unit': line.price_unit,
                        'taxes_value': line.taxes_id.amount,
            return purchase_data
    def get_issuenote_title(self):
        if  self.location_id.usage == 'supplier' and self.location_dest_id.is_central_stock:
            return "Issue"

        if  self.location_id.is_central_stock and not self.location_dest_id.is_central_stock:
            return "Issue"

        if not self.location_id.is_central_stock  and not self.location_dest_id.is_central_stock:
            return "Site Issue"

How to Reset Encrypted Password for Admin User in Odoo v8, v9, v10 and v11?

Login as postgres user:

sudo su postgres;

Switch to the database in question:

psql <databaseName>;

List all users with their passwords:

select * from res_users;

Now copy the password and use it in the following command:

update res_users set password_crypt = ‘<copiedPasswordFromAbove>’ where id = ‘1’;

That’s it. Go and login with username admin and password you used to register the user in the first place.

If it helped you… don’t forget to share this post on your wall. It may be helpful to someone else.

VirtualBox can’t find host-only adapters on Windows 10

I get the same results when using the command lines tools. The creation of new interfaces works without problems:

C:\> VBoxManage.exe hostonlyif create
Interface 'VirtualBox Host-Only Ethernet Adapter #5' was successfully created

But VirtualBox can’t find the adapters, as the following command does not return any output:

$ VBoxManage.exe list hostonlyifs

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)})


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 🙂