Import translation in Odoo 10

Hello guys ^^
Today’s article will show you how to translate your modules in Odoo 10.

For our tutorial we will work with the module:”hr_expense” that has some few missing translated words and we will explain to you, step by step, how to import the translation into this module.

We will try to translate it in french.
To do so:

1-Activate the developer mode: Setting -> Activate developer mode

developer mode in odoo

2- Install the module “hr_expenses”:

you will notice that some few words are not translated in french.

hr_expenses module

3- Go to addons/hr_expense/i18n/fr.po:

– Open the file “fr.po”, you will notice that some few words are not translated

https://drive.google.com/file/d/0B09HNye3F974dnZwd3FQLTNXcHM/view?usp=sharing

– Save this file

-Add necessary  translation to your file and save it. For our case, we translated the following words:

  • “Expenses to Submit”, “Refused Expenses”, “Expense Reports”

translation odoo 10

3-Import Translation:
Go to : Setting-> Translation-> import/export-> Import translation
Screenshot 2017-04-11 15:20:16

4- This window will appear:
Screenshot 2017-04-11 15:21:14

5- Add your file “fr.po” and click import:
Screenshot 2017-04-11 15:21:55

6- Restart your navigator: 

You will notice that the translation has been successfully added.

translated words

Please find here a video that shows all the steps of importing translation in Odoo 10 described above :

 

Hope you guys like it ^^
Best of luck

Field of type Reference in Odoo, how to use it ?

Reference field type in Odoo

The main use of this field type is to make a reference with a specific model and then a specific recordset of this model.

By using the reference field type, the first thing you will choose is the model:

field reference

And by choosing the model you will be asked the choose one of the recordset of the chosen Model

field reference recordset

Structure of the reference field in Odoo (New API)

A field of type reference is declared as below :

ref = fields.Reference(string='Reference', selection='_get_document_types')

Selection attribute : We define the method that will determine which models will be showed, and from which we can choose

In our example we used this method :

method selection field reference

@api.model
    def _get_document_types(self):
        records = self.env['ir.model'].search(['|', ('model', '=', 'sale.order'), '|', ('model', '=', 'account.invoice'), '|', ('model', '=', 'stock.picking'), ('model', '=', 'purchase.order')])
        return [(record.model, record.name) for record in records] + [('', '')]

In this example, we specified that we want to choose from [ Sale Order, Account Invoice, Stock Picking, Purchase Order ] models

Hope it was useful for you
Good luck !!

Odoo : SQL Query Tips

In this article we will show some useful tips that will help you work with SQL Queries in python/Odoo.

How to execute queries in Odoo 10 ?

you should use the self.env.cr to run a sql query

cr = self.env.cr
cr.execute("SELECT a, b, c FROM [your_table] WHERE [condition]")
cr.fetchall()

It’s highly recommended to use the double quotes ” ” instead of single quotes ‘ ‘

What’s the query can returns ?

cr.dictfetchall() : will give you all the matching records in the form of the list of dictionary containing key, value [{'': ''}, {'': ''}, ...].
cr.dictfetchone : works same as cr.dictfetchall() except it returns only a single record {'': ''}.
cr.fetchall() : will give you all the matching records in the form of the list of tuple [(''), (''), ...].
cr.fetchone() : works same way as cr.fetchall() except it returns only single record ('').

SQL Queries with variables

You can execute Queries with variables using %s like:

cr.execute("SELECT a, b, c FROM [your_table] AS a WHERE a.id = %s AND a.field = %s", (first_value, second_value))

Hope it was useful for you
Good luck !!