Odoo Help

Welcome!

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.

0

odoo9: why default value does not work

By
Drees Far
on 4/22/16, 4:35 AM 430 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.

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 4/22/16, 5:30 AM

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

0
kirubanidhi
On 7/27/16, 8:11 AM

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

0

Prakash Sharma

--Prakash Sharma--
815
| 2 1 4
Delhi, India
--Prakash Sharma--

I like to surround myself with brave, creative people.

My motivation for learning different technologies and algos drive me. I love challenges of a steep learning curve which I believe makes me a better learner. I have a strong desire to learn different technologies, which would enable me to become a full stack developer.

Prakash Sharma
On 4/22/16, 5:01 AM

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


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

Drees Far
on 4/22/16, 5:03 AM

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

Prakash Sharma
on 4/22/16, 5:06 AM

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

Prakash Sharma
on 4/22/16, 5:09 AM

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

Drees Far
on 4/22/16, 5:13 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)

Stats

Asked: 4/22/16, 4:35 AM
Seen: 430 times
Last updated: 7/27/16, 8:11 AM