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

Hi everyone, How can i override the write method in the edit form??

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

You've to do this:

def write(self, cr, uid, ids, vals, context=None):

    #code
    res = super(class_name, self).write(cr, uid, ids, vals, context=context) #res stores the result of the write function
    #code
    return res
Ảnh đại diện
Huỷ bỏ
Tác giả

im doing lik this : def write(self, cr, user, ids, vals, context=None): res1=super(pos_methode1, self).write(cr, user , ids, {'firstname': vals['firstname'] ,'lastname': vals['lastname']}, context=context) return res1 this goes right only when i change both of the 2 field values ,but if change only when an error occured :"Key error :..."

what do you mean with 2 fields? Please post your entire code related to this please. Thanks

Tác giả

class pos_methode def write(self, cr, user, ids, vals, context=None): res1=super(pos_methode1, self).write(cr, user , ids, {'firstname': vals['firstname'] ,'lastname': vals['lastname']}, context=context) return res1 it goes right only when i change all of the 2 fileds value,but if update only one i get an error

What silvi said it's true. if you say vals['lastname'] it's not going to work if you are not sending ['lastname'] so you use vals.get('lastname') beside vals['lastname']

Câu trả lời hay nhất

When you try to change one field only, you ll get an error. The reason is you are trying to fetch value from vals dict which is actually not there. Say, you have changed first name only and in write you are updating lastname name as well which is actually not there in vals dict.

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

so what can i do to have the possiblity of updating both values or even one???

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
6162
1
thg 3 15
5791
2
thg 12 20
4708
1
thg 7 19
4485
2
thg 4 19
6464