コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7483 ビュー

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': "

関連投稿 返信 ビュー 活動
1
11月 22
4506
1
6月 17
12641
1
3月 15
6505
3
3月 15
13008
1
3月 15
3765