Skip to Content
Menu
This question has been flagged
7 Replies
5112 Views

Hello everybody!!!

I want to put a value by defaut in the currency_id of res_ompany model.

SO i have tried this but nothing appears in odoo.

 def _get_default_currency(self, cr, obj ,context=None):

print('----------------CURRENCY--------------------')

currency_obj = self.pool.get('res.currency')

print ('test1')

print currency_obj

currency_ids = currency_obj.search(cr, obj, [('name','=','DTN')])

print currency_ids

currency_res = currency_obj.read(cr,obj,currency_ids,['id'],context=context)

print currency_res

for v in currency_res :

print v['id']

currency_id = v['id']

return currency_id


_defaults = {'currency_id' : _get_default_currency}

Can anyone help please.

Thanks a lot in advvance.

Best Regards.

Avatar
Discard
Author Best Answer

I have understand what happened.

In fact, currency_id field have a default value which is coming from _get_euro function so that i have to override this function and everything will work fine.

 def _get_euro(self, cr, obj ,context=None):

print('----------------CURRENCY--------------------')

currency_obj = self.pool.get('res.currency')

print ('test1')

print currency_obj

currency_ids = currency_obj.search(cr, obj, [('name','=','DTN')])

print currency_ids

currency_res = currency_obj.read(cr,obj,currency_ids,['id'],context=context)

print currency_res

for v in currency_res :

print v['id']

currency_id = v['id']

return currency_id

Avatar
Discard
Best Answer

In odoo9, 

     We use for this code this helpful for you,

currency_id = fields.Many2one('res.currency', string='Currency',default=lambda self: self.env['res.currency'].search([('name','=','USD')]))

Avatar
Discard
Best Answer

Please Open this link /web#id=3&view_type=form&model=res.currency ,and

check that DTN is  available in res.currency or not ,

By default there is no as currency name DTN.

I am posting the code that i have used, it's work for me  .

def _get_default_currency(self, cr, uid ,context=None):

currency_obj = self.pool.get('res.currency')

currency_id=None

currency_ids = currency_obj.search(cr, uid, [('name','=','USD')],limit=1)

currency_res = currency_obj.read(cr,uid,currency_ids,['id'],context=context)

for v in currency_res :

currency_id = v['id']

return currency_id


Avatar
Discard
Author

Thanks for the answer friend ;) But, i have added this currency in the table res.currency and it does exist

just place a logger before return and check currency_id is None or not

+check the indentation _defaults = {} , it's is in the class body or not??

Author

i have inherited the class and make the default value in the second class. I have cheked the result and i got what i want

Related Posts Replies Views Activity
5
May 24
12339
1
Feb 24
728
1
Oct 22
26740
2
Oct 22
3330
3
Feb 21
15056