Odoo Help


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.


How to recall some certain function when click "save" button in "creating form"?

on 7/22/16, 12:35 AM 337 views

I want the module to execute "some command lines" when user clicks the "save" button in "creating form";


Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 7/22/16, 2:54 PM


You can override create and write method for an object.


class MyClass(...):

def create(cr, uid, vals, context=None):
# Your logic goes here or call your method
res_id = super(MyClass, self).create(cr, uid, vals, context=context)
# Your logic goes here or call your method
return res_id

def write(cr, uid, ids, vals, context=None):
# Your logic goes here or call your method
super(MyClass, self).write(cr, uid, ids, vals, context=context)
# Your logic goes here or call your method
return True

Create method will be called when you are creating a new record.

If you are updating any existing record, write method will be called.

your reply is always so wonderful;

Thanks again!

good work, happy life!

on 7/24/16, 9:18 AM
On 7/22/16, 2:41 AM

In odoo 9 ,

            create a button in xml view file,

<button string="details" type="object" class="oe_highlight oe_right" name="save" icon="fa-fire" ></button>


Create a save method in py file


def save(self):

 ... your code...

    a = self._cr

     print a

    if a:

         print "success"


         print "false"

    return a


success: <openerp.sql_db.Cursor object at 0x7f74a07149d0>

edit a form view and change a field value then press a  custom save button after see the log ,success a  message are print in log file 

Thanks for your help;

In the fact I mean the "save" button is not created by us;

I mean when user click the "create" button which exits on every app/module, then the user go into the "form" view and use will get a "save" button which is not created by us but Odoo;

Now I want to execute some certain function when user clicks this "save" button.

on 7/22/16, 3:40 AM
On 7/25/16, 2:20 AM

I am using a compute field for this purpose.

add simply the following in the model

def _perform_compute_action(self):
     # Your Statements


action_compute = fields.Char(compute='_perform_compute_action')

thanks for your reply;

it is ok most time; but it can't work when you set "action_compute" as "readonly"="1";

on 7/25/16, 2:55 AM

The compute field becomes readonly field automatically. The purpose of "action_compute" is only to work the method. You don't use that field for other purpose .

on 7/25/16, 4:42 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)


Asked: 7/22/16, 12:35 AM
Seen: 337 times
Last updated: 7/25/16, 2:20 AM