Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


V9 - Enable a currency when installing a module

Mathieu Laflamme
on 1/5/16, 5:08 PM 417 views

We're developing modules for our company and since we use CAD currency I want to enable it in the system. How can I do that from a module?


I can believe this is taking so long to accomplish this little task!

I get the following error:

ParseError: "Invalid field 'name' in leaf "<osv.ExtendedLeaf: ('name', '=', 'CAD') on res_currency (ctx: )>"" while parsing file:///C:/Users/laflammm/Desktop/GitHub/addons_tc/canadian_data/data/res_currency.xml:4, near
<function model="res.currency" name="_enable_currencies"/>

I don't get it... when I check the fields of res.currency, I only see those:

'create_uid': <openerp.osv.fields.many2one object at 0x0000000009A8D138>,
'create_date': <openerp.osv.fields.datetime object at 0x0000000009A8C3C8>,
'id': <openerp.osv.fields.integer object at 0x0000000009A8C588>,
'write_date': <openerp.osv.fields.datetime object at 0x0000000009A8C4A8>,
'write_uid': <openerp.osv.fields.many2one object at 0x0000000009A8D228>

Where are the name, rounding, symbol, position and active fields?? In the fields from res.currency are from the base modules. What's going on??

I have the following files:


from import openerp models

class Currency(models.Model):
_name = "res.currency"

def _enable_currencies(self, cr, uid, ids=Nonecontext=None, ):
cad_currency_ids = self.search(cr, uid, [('name', '=', 'CAD')])

if cad_currency_ids:
self.write(cr, uid, cad_currency_ids, {'active' : 'True'})


<function model="res.currency" name="_enable_currencies"/>


'name' :"Canadian data" ,
'description':"Create the canadian provinces and territories plus activate CAD currency." ,
'author' :"Transcontinental" ,
'category' :'' ,
'version' :'1.1' ,
'depends' : [],
'data' : [
'auto_install': False,
'installable': True,


import res_currency

See my updated answer.

Serpent Consulting Services Pvt. Ltd.
on 1/7/16, 4:15 AM

Your module should depends on base module.

Serpent Consulting Services Pvt. Ltd.
on 1/7/16, 6:37 AM

Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 1/6/16, 2:40 AM

Hello Mathieu,

In v9, all other currencies are DE-activated by default (active=False).

So from your code, first you have to search for your currency based on currency code and then enable that currency (active=True). Now, update currency_id field in Company and set your currency in that field.

#TIP: If you want to show Currency menu to user, you have to assign "Multi Currencies" group to your user(s).


I can see there is a problem in your code.

Instead of _inherit, you have used _name which consider as a new object and will have only those fields which you have defined in your class.
Try this:

class res_currency(...):
_inherit = 'res.currency' # use _inherit to extend the functionality of the object
Hope this helps you.

Thanks but I wonder where I should write that code. I tried making an xml to change the data but since the original data was imported with noupdate it doesn't work (I don't get why they use noupdate here!). There should be a way to run code at installation time.

Mathieu Laflamme
on 1/6/16, 9:33 AM

Yes that will work if you call the function from XML and will follow the steps we mentioned in the answer.

Serpent Consulting Services Pvt. Ltd.
on 1/7/16, 2:58 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 1/5/16, 5:08 PM
Seen: 417 times
Last updated: 1/7/16, 9:38 AM