Technical

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>
   
</t>

.py code

@api.multi
    def _get_purchase_mrn_details(self,origin,product_id):
        if origin and product_id:
            self.ensure_one()
            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 line.product_id.id == product_id.id:
                    purchase_data.append ({
                        'price_unit': line.price_unit,
                        'taxes_value': line.taxes_id.amount,
                        'taxes_id': line.taxes_id.name,
                    })
            return purchase_data
Advertisements

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
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
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 = "http://yourodooserver.com"
# or "http://201.100.100.12:8069" (or whatever the ip is)
url = "{}/web/session/authenticate".format(b_url)

db = "<YOURDBNAME>"
user = "<YOURUSERNAME>"
passwd = "<YOURPASSWORD>"

s = Session()

data = {
    'jsonrpc':'2.0',
    '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']

# NOW MAKE REQUESTS AND PASS YOUR SESSION ID

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

print(res.text)

redirect to view using python – odoo


@api.multi
    def redirect_opportunity_view(self):
        self.ensure_one()
        # 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')],
            'res_id': self.id,
            'view_id': False,
            'views': [
                (form_view.id, 'form'),
                (tree_view.id, '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"]
    result.append(temp_dict)
    
from pprint import pprint
pprint(result)

output
[{'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/hostname.com.err 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 :https://css-tricks.com/snippets/css/using-font-face/)


@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 */
}
.footer_text
{
    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"?>
<openerp>
    <data>
    <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"/>
      </xpath>
    </template>
    </data>
</openerp>

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

https://github.com/ananthukrishna/odoo-pycharm-templates/blob/master/Odoo.xml

Configuration:

Windows

C:\Users\user\.PyCharmCE2016.3\config\templates

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

~/.PyCharm*/config/templates

MacOs X users, look for the templates folder here:

~/Library/Preferences/PyCharm*/templates

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