Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
7492 Lượt xem

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.
   }
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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,
}
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
4509
1
thg 6 17
12648
1
thg 3 15
6509
3
thg 3 15
13012
1
thg 3 15
3768