Odoo Help
Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM
|
e-Commerce
|
Accounting
|
Inventory
|
PoS
|
Project management
|
MRP
|
etc.
odoo9: why default value does not work
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.
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
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
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??
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
About This Community
This platform 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.
RegisterOdoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.
Test it nowQuestion tools
Stats
Asked: 4/22/16, 4:35 AM |
Seen: 883 times |
Last updated: 7/27/16, 8:11 AM |