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

Hello All,

I have a many2one field from res.s. And for this fields i created three groups Group A, Group B and Group C. For these groups i applied on-change for users related to group. And on-change work well. Now, i want that Group B is default group selected. So, How to fix Group B default on form(group id = 33) ?

My python code:

'group_id':fields.many2one('res.groups', string='Group:')

'assign_to': fields.many2one('res.users','Assigned To:',)

def onchange_assign(self, cr, uid, ids, group_id, context=None):

        if not context:

            context = {}

        res = {}

        groups_obj = self.pool.get('res.groups')

        sunarc_obj = self.pool.get('sun.helpdesk')

        #record_id = context.get('active_id')

        print "g:", group_id

        #data = sunarc_obj.read(cr, uid, record_id)

        #print data

        #group_id = data['group_id'] and data['group_id'][0]

        groups_ids = []

        groups = groups_obj.browse(cr, uid, group_id, context=context)

        print "groups:", groups, groups.users.ids

        if group_id:

            res['domain'] = {'assign_to': [('id', '=', groups.users.ids)]}

        print "group_id"

        return res


XML Code:-

<field name="group_id" on_change="onchange_assign(group_id)"/>                        

<field name="assign_to" options="{'create':false}"/>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello pawan ,

you can try this:

def _get_default_esc(self):
print "yes:", 33
return 33

'group_id' : fields.many2one('res.groups', "Group", change_default=True, default=_get_default_esc),
Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks, Manish it's work for me. But can you tell me how to done this with search method.

Hello Pawan try this

def _get_default_esc(self):

esc_to = self.env['res.groups'].search([('name', '=', 'Group B')], limit=1)

print "Group:"

return esc_to

why don't you add a configure section to select it from there and use it. not to change the code when you want to assign new group as default or install it on new db.

How to do this ?? can you explain in more detail ????

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 20
8563
2
thg 8 22
6865
1
thg 7 19
3271
0
thg 11 17
6657
4
thg 9 17
25464