Open a specific action on “Create” button

If you need to call a specific action on creating a new instance of an object you can do that by adding the attribute “on_create” into the view from which you want to create the new instance.

A good example is the project kanban view definition:

<record model="ir.ui.view" id="view_project_kanban">
<field name="model">project.project</field>
<field name="arch" type="xml">
    <kanban on_create="project.open_create_project"class="oe_background_grey o_kanban_dashboard o_project_kanban" >
    ...
    </kanban>
</field>
</record>
Share the knowledge!

How to change displayed value for relational field in Odoo

If you want to change the displayed value for a relational field in Odoo, the simplest way to do that is to define the “_rec_name” model’s attribute with the name of the field that you want to show.

For example, if you want to add new field “description” in the hr.employee.category model and you want that field to be shown as value for this model the code should look like:

class Employee(models.Model):
    _inherit = 'hr.employee.category'
    _rec_name = 'description'

    description = fields.Char()

Now when you try to search for a new employee tag in the hr.employee view it will search by and display the description of the hr.employee.category model.

Share the knowledge!

Install Odoo addons using pip

I have discovered this functionality at Odoo Experience 2016. If you want to use this feature I would recommend following tutorial.

Share the knowledge!

How to add Chatter to an existing model

A recent issue that I have faced with was adding chatter to the hr.job model. I have found the solution on the Official Odoo Forum and I want to share it with you.

The thing is that you need to inherit the model mail.thread but also to redefine the name of the existing model. In my case it looks like:

class HrJob(models.Model):
    _name = 'hr.job'
    _inherit = ['hr.job', 'mail.thread']

Additionally, one more thing that needs to be done is to update the form view:

<xpath expr="//field[@name='message_follower_ids']" position="after"> 
    <field name="message_ids" widget="mail_thread"/>
</xpath>
Share the knowledge!

How to check if float number is zero

If you need to check if a float value is equal to zero it is recommended to use the method float_is_zero. This method accepts float value as required argument and two additional arguments: “precision_digits” and “precision_rounding”. Important thing is that precision must be given by “precision_digits” or “precision_rounding“, not both. It returns True if the given value is 0 at the given precision.

More about this method you can find into the Odoo repository.

Share the knowledge!

How to inherit from a view without overriding the original view

If you need to create a new view that is very similar to existing one. Instead of creating the whole view you can inherit from the existing view and set the attribute “mode” to “primary“. In that way, the original view will not be changed and all changes in the newly created view will apply only for it.

For example, if you need new crm.lead form view that has new field “mobile“, but this field should be shown only in the new view, not in the original one, the code should look like

<openerp>
    <data>
        <record id="view_crm_lead_form_mobile" model="ir.ui.view">
            <field name="model">crm.lead</field>
            <field name="inherit_id" ref="crm.view_crm_lead_form" />
            <field name="mode">primary</field>
            <field name="arch" type="xml">
                <field name="phone" position="after">
                    <field name="mobile"/>
                </field>
            </field>
        </record>
    </data>
</openerp>
Share the knowledge!

Attributes t-esc and t-raw remove empty lines in text

If you use these two attributes in QWeb templates, you should consider that all empty lines from any type of Char fields rendered with them will be removed.

For example, if you use t-esc attribute to display the “note” field from the sales.order model in your QWeb report  and the current value for it in the form view is:

Lorem ipsum dolor sit amet, wisi meliore scriptorem mea eu, prima porro ei eam.

Dicat perpetua an his.

Elit placerat mea te.

The result in the report will be:

Lorem ipsum dolor sit amet, wisi meliore scriptorem mea eu, prima porro ei eam.
Dicat perpetua an his.
Elit placerat mea te.
Share the knowledge!

How to log all sql queries performed by Odoo

If you want to see all the queries that Odoo execute while it running, you can do that by setting up in the configuration file –log-level=debug_sql. Also, you can do the same when you start the server by adding the argument –log-level debug_sql in the command line.

For example in Odoo v.10 that would look like:

python odoo/odoo-bin --log-level debug_sql
Share the knowledge!

Where can be found the list of defined currencies in Odoo

If you want to have access to the list of currencies in Odoo you need to have the “Multi Currencies” group. This group can be activated by the users with administration privileges in the system and the developer mode activated.
When the group is added to your user you can find the list of currencies in Accounting >> Configuration >> Multi-Currencies >> Currencies

Share the knowledge!

Consume all tours at once in Odoo 10

If you don’t want to go through all tours in Odoo 10 you can consume them at once by activating the developer mode, going to the “Developer Tools” button in the right upper corner, left of the user’s button and click on “Consume Tours“.

Share the knowledge!