How to change the number of decimal places in Odoo

In Odoo there is an option to change the number of decimal places for already defined decimal.precision objects: “Product Price“, “Discount“, “Stock Weight“, “Payment Terms“, “Product Unit of Measure“, “Payroll” and “Payroll Rate“.

You can do that by going to Settings >> Technical >> Database Structure >> Decimal Accuracy, choosing one of the defined objects and updating the field “Digits“.

Also, you can create a new decimal.precision object. In such a case you need to update the backend code with it.

Share the knowledge!

Happy New Year

Happy New Year to all of you who followed me through this journey. I hope that 2017 will be your year.
This year you can expect a lot more new tips from me, but also new things that will help you in your process of working with Odoo.

Cheers!

Share the knowledge!

How to edit address format on reports for different countries

In case you need different address format on your QWeb reports for different countries, you can do that by firstly enabling the developer mode and after that going to Sales >> Configuration >> Localization >> Countries >> Address Format(field).
For example, if you need for Germany the zip code to be shown before the city the formatting should look like:

%(street)s
%(street2)s
%(zip)s %(city)s
%(country_name)s
Share the knowledge!

Every QWeb report needs to have div with class “page”

The PDF body for every QWeb report that you create needs to be inside a div with a class “page”. That means if you don’t have such class in your report its body will be a blank page.

For Example, the following report will show the text “Sales Order” and its name.

<div class="page">
    <h2>Sales Order <span t-field="o.name"/></h2>
</div>
Share the knowledge!

Calling objects in widgets

If you see in your console warning message such “Use new syntax for ‘<span t-tag=”span”/>” you need to remove the quotes from the objects in your widgets.

For example, if you want to display amount_total field in your new report with monetary widget the value for the display_currency parametar should be o.currency_id instead of “o.currency_id”

<span t-field="o.amount_total" t-options='{"widget": "monetary", "display_currency": o.currency_id'/>
Share the knowledge!

How to compare two float numbers in Odoo

If you need to compare two float numbers in Odoo you should use the method float_compare. This method allows you to have more accurate results in your calculation. Except for the values that need to be compared this method as arguments receives precision_digits and precision_rounding. You need to choose only one of these arguments because the precision must be by digits or rounding.

For example, if you want to compare 8.945 and 8,946 with precision_digits 2 the return result will be 0 that means both values are same. In a case when precision_digits is 3 the return value will be -1 that means the second value is bigger than the first.

# Odoo 9
from openerp.tools import float_compare

# Odoo 10
from odoo.tools import float_compare

>>> float_compare(8.945, 8.946, precision_digits=2)
>>> 0

>>> float_compare(8.945, 8.946, precision_digits=3)
>>> -1

>>> float_compare(8.946, 8.945, precision_digits=3)
>>> 1

You can find more how this method works in the Github Odoo repository

Share the knowledge!

How to use one database per domain

If you want your users to have access only to a particular database, you can do that by naming the database same as your domain and setting up the dbfilter parameter in the configuration file to dbfilter = ^%d$

For Example, If your domain is mypersonalodoo.com and you want your users to have access only to one database, then the database name should be “mypersonalodoo“.

Share the knowledge!

Issue with not loading Odoo enterprise

If you want to use enterprise version of Odoo, after you download it to your server or PC, you need to add the enterprise addons to the addons path. It is very important enterprise addons to be the first in the addons path in order everything to work fine.

For example if you use Odoo 9 Enterprise and the enterprise addons are in the following location /home/odoo/enterprise the addons_path configuration should look like:

addons_path = /home/odoo/enterprise,/home/odoo/odoo/openerp/addons,/home/odoo/odoo/addons
Share the knowledge!

How to format date in QWeb report

If you need specific formatting for the date shown on your QWeb report, you can achieve that by defining the attribute t-field-options with value {“format”: “<formating type>”}
For example, if you need the Invoice Date to be shown as 14.11.2016 the code would look like:

<span t-field="o.date_invoice" t-field-options='{"format": "%d.%m.%Y"}'/>
Share the knowledge!

Product price that includes tax

If you want the price use on the product to include the selected tax you need to check the field “Included in Price” for the particular tax. This field can be found in Accounting >> Configuration >> Taxes >> Tax (Form View) >> Advanced Options (Tab)

Share the knowledge!