Skip to Content
Menu
This question has been flagged
1 Reply
3726 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?


EDIT:

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:

res_currency.py

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'})

res_currency.xml

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

__openerp__.py

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

__init__.py

import res_currency



Avatar
Discard

Your module should depends on base module.

Best Answer

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).

EDIT:

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.
Avatar
Discard
Author

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.

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

Related Posts Replies Views Activity
1
Mar 15
2720
1
Feb 16
3569
2
May 24
4959
1
Apr 24
326
2
Jan 24
535