Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
7626 Переглядів

FYI I am aware that one could define default values for any field through the developer mode User Interface.

I would like though to define my default values on my custom module. For the partner object specifically, I presume the way to go is something like:

from openerp.osv import orm, fields

class MyModule(orm.Model):
    _inherit = 'res.partner'
   _defaults = {
       # Not quite sure how to set the default value for country here.
   }
Аватар
Відмінити
Найкраща відповідь

Try using this code - where XX = your country code:

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

    cid = self.pool.get('res.country').search(cr, uid, [('code', '=', 'XX')], context=context)
    if cid: return cid[0]

_defaults = {
    'country_id': _default_country,
}
Аватар
Відмінити
Найкраща відповідь

Refer the below link: http://snippetbucket.com/2013/07/openerp-set-default-country-by-_default/

Аватар
Відмінити
Автор

Your solution works also but I had to slightly change the code " _defaults = { 'country': " with " _defaults = { 'country_id': "

Related Posts Відповіді Переглядів Дія
1
лист. 22
4642
1
черв. 17
12793
1
бер. 15
6601
3
бер. 15
13153
1
бер. 15
3854