10 Useful Odoo Tips and Tricks (Best Practices)

In this article, we’ll discuss Odoo tips and tricks (best practices). These all Odoo tips and tricks help you to increase your level. As we all know, Odoo is widely popular for its functionality. Because Odoo offers all in one web-based business software. All most all business manage and handle in single Odoo App. Every year Odoo release community version, and enterprise version. Odoo community version is the free, open-source version while enterprise version extends some commercial features and services.

Recently Odoo offers a completely free Odoo Education program, which is allowed to teachers and students to create an Odoo database for academic or learning purposes. Let’s move to start Odoo tips and tricks that must have to know.

Odoo Tips and Tricks

1. Odoo QWeb loops

Odoo QWeb is an XML template engine that generates HTML piece of code for Odoo pages. Furthermore, QWeb has an foreach iteration to iterate every item. Here, you can do more in this iteration to perform any unique operation like as_first, as_last, as_index. For example first iterate item we have to print something, print index number of every iterate item. As we see real-life scenario, we have to use when we add carousel slider in Odoo. Hence, you have not to need to define QWeb variable and check over iteration.

<t t-foreach="[1, 2, 3, 4, 5]" t-as="item">
    <p t-if="item_first">
        Start
    </p>
    <p>
        Index <t t-esc="item_index"/> and value <t t-esc="item"/>
    </p>
    <p t-if="item_last">
        End
    </p>
</t>
Result

Start
Index 0 and value 1
Index 1 and value 2
Index 2 and value 3
Index 3 and value 4
Index 4 and value 5
Stop

2. Odoo Get Host URL

Sometimes you need to get the hostname, host URL, base URL, remote address. You can get this all parameters from httprequest object. httprequest object is python object you can print all value using __dict__ at the end.

request.httprequest.host        // localhost:8069 

request.httprequest.host_url    // http://localhost:8069/

request.httprequest.url         // http://localhost:8069/web/dataset/call_button

request.httprequest.base_url    // http://localhost:8069/web/dataset/call_button

request.httprequest.remote_addr // 127.0.0.1 

3. Update Context

When you try to update context, and you will get “frozendict” error message. Because frozendict is a dictionary that can not modify after being created. As a result, you are unable to update context is not update. However, you can update your context using the following Odoo tricks.

context = request.env.context.copy()
context.update({'email_send': True})
request.env.context = context

4. Debug QWeb Template

You can put t-debug="pdb" in your XML template for debugging your template code. Ultimately it is call set_trace() method. As well as you need to enable --log-level=debug in your terminal. Later you can debug XML template same as python pdb.

<t t-debug="pdb"/>

5. Odoo Command line

Following, you will find some of the useful tips and tricks for Odoo command line interface.

$ ./odoo.py --help                         // Show all command line option

$ ./odoo.py -i module_name -d db_name      // Install module
$ ./odoo.py -u module_name -d db_name      // Update module

$ ./odoo.py --addons-path=ADDONS_PATH      // Specify one or more addons path separated by comma

$ ./odoo.py --xmlrpc-port=8070             // Specify port number to run Odoo server, default port 8069

Specify the log file where Odoo store logging output.

$ ./odoo.py --logfile=/var/log/odoo/odoo12-server.log

Specify the level of the logging. Accepted value: debug, error, info, debug_rpc, warn, test, debug_sql.

$ ./odoo.py --log-level=LOG_LEVEL

Enable developer mode using below command. You can specify one or more option separated by comma. Accepted value: all, pdb, reload, qweb, werkzeugxml.

$ ./odoo.py --dev=DEV_MODE

6. Menu and Submenu create in Odoo Website

Odoo introduces a multi-website concept in Odoo 12. For the reason that, create menu and submenu you need to specify website id. Explore the following example to create menu and submenu in Odoo Website. You need to focus on the parent_id field for parent menu.

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="1">
    <record id="menu_parent" model="website.menu">
        <field name="name">Parent Menu</field>
        <field name="url"></field>
        <field name="parent_id" search="[('parent_id', '=', False), ('website_id', '=', obj().env.ref('website.default_website').id)]"/>
        <field name="sequence" type="int">10</field>
        <field name="website_id" ref="website.default_website"/>
    </record>
    <record id="menu_child1" model="website.menu">
        <field name="name">Child Menu 1</field>
        <field name="url">/child1</field>
        <field name="parent_id" ref="menu_parent" />
        <field name="sequence" type="int">10</field>
        <field name="website_id" ref="website.default_website"/>
    </record>
    <record id="menu_child2" model="website.menu">
        <field name="name">Child Menu 2</field>
        <field name="url">/child2</field>
        <field name="parent_id" ref="menu_parent" />
        <field name="sequence" type="int">20</field>
        <field name="website_id" ref="website.default_website"/>
    </record>
</data>
</odoo>

7. Activate System/OdooBot User

Odoo 12 introduces a new System/OdooBot User. You can activate superuser. You need to enable developer mode to visible developer tools. Click on “become superuser” to activate superuser.

Odoo become superuser (Odoo Tips and Tricks)

8. Image store in file store instead of Database

This Odoo trick helps you to store an image in a file store folder instead of a database. You just need to define attachment=True in a binary field.

photo = fields.Binary('Photo', attachment=True)

9. Inline Tree View Hide Column

This tricks apply on One2many or Many2many type field. You can use column_invisible attribute to hide column from inline tree view. For example. sale order line tree view.

<field
    name="qty_delivered"
    attrs="{'column_invisible': [('parent.state', 'not in', ['sale', 'done'])]}"
/>

10. Use watchdog To Auto Reload

Whenever you modify python file, you need to restart the server every time. But we can do these automatically. You need to install watchdog. So whenever you save changes to any of the python files under watch, the server will be auto restarted.

sudo pip3 install watchdog

Finally, add dev=reload parameter in your server .conf file. Similarly, you can directly use in command-line terminal.

./odoo-bin --dev=reload

Final Thoughts

This article walked you through the Odoo tips and tricks. Some Odoo tips are new in Odoo 12 that you must have to know. Even more, if you know any Odoo tips and tricks you can share here below a comment box.

We hope you have found this article helpful. Let us know your questions or feedback if any through the comment section in below. You can subscribe our newsletter and get notified when we publish new WordPress articles for free. Moreover, you can explore here other Odoo related articles.

Odoo Tips and Tricks

OpenERP Tricks

Odoo Tutorials, Tips & Tricks

Odoo tips of the Month

If you like our article, please consider buying a coffee for us.
Thanks for your support!

Support us on Buy me a coffee! Buy me a coffee!



4 Responses Leave a Comment

  1. Thanks for sharing these Odoo tricks.

  2. All tricks are awesome but watchdog is my favorite one as it helps to make your task much easier and speed up my work. Keep up the great work.

  3. Nice tricks thank you.

  4. great tricks thanks a lot

Join the Discussion.