콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7596 화면

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
4599
1
6월 17
12734
1
3월 15
6563
3
3월 15
13121
1
3월 15
3827