This question has been flagged
3 Replies
5752 Views

Hello, I want to modify the actions in the system when the user presses "Save" in the Pricelist Item form. (The ID is product.pricelist.item.form) in Odoo 8.

I learn the view, but there isn't a <button> element so I don't know what is the method called when the user presses "Save". How can I know that? So then, have I to override this method?

Thanks!

Avatar
Discard
Best Answer

It is the method "write" and "create".  Save button is not part of the view.

Avatar
Discard
Best Answer

If you want your save button to do something you should write the below function in your module becozz this function is called when ever save button is clicked....

def create(self, cr, user, vals, context=None):

       ###### something you want#####
        return osv.osv.create(self, cr, user, vals, context=context)

Avatar
Discard

Sorry Anand your code breaks inheritance as it calls osv.osv.create directly. The proper call would be return super(class_name, self).create(cr, user, vals, context=context) on v7.

yes... you are right... thanks....Ivan

Author Best Answer

Ok, thanks. In what case have I to override "write" and in what case "create"?

Avatar
Discard

write will be executed when an existing record is updated. Note that for write the vals in the method's argument will only contain those data that are updated. So, you might want to read/browse first if you need those data. Also write operates on multiple records (ids in the argument). create is called when a new record is created, the vals argument will contain all fields that are to be written and no ids in the arguments.

Author

You are very clear. I have understand perfectly. Thanks!

Author

Sorry, in the case of write, why the ids are a collection? If I am updating a single record

It is just the way Odoo is written Jose. write expects a list for ids arguments. If you just updates one record, you put it in a list. pool.write(cr, uid, [id], vals, context=context). That'll do.