Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to override the write method (in the Edit form) ?

By
Hachem Chraiti
on 4/14/14, 4:36 PM 1,702 views

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

1

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 4/14/14, 4:48 PM

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 :..."

Hachem Chraiti
on 4/14/14, 5:01 PM

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

GH Mediacloud, Grover Menacho
on 4/14/14, 5:22 PM

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

Hachem Chraiti
on 4/14/14, 5:35 PM

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

GH Mediacloud, Grover Menacho
on 4/15/14, 10:56 AM
0
silvi
On 4/15/14, 1:30 AM

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???

Hachem Chraiti
on 4/15/14, 11:47 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/14/14, 4:36 PM
Seen: 1702 times
Last updated: 3/16/15, 8:10 AM