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

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

アバター
破棄
最善の回答

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
アバター
破棄
著作者

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

著作者

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']

最善の回答

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.

アバター
破棄
著作者

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

関連投稿 返信 ビュー 活動
1
3月 15
6028
1
3月 15
5687
2
12月 20
4595
1
7月 19
4395
2
4月 19
6341