콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4644 화면

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



아바타
취소

Your module should depends on base module.

베스트 답변

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.
아바타
취소
작성자

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.

관련 게시물 답글 화면 활동
1
3월 15
3665
1
8월 25
248
1
2월 16
4518
2
5월 24
6631
1
4월 24
1824