Odoo Help


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

on 7/22/16, 12:35 AM 1,828 views

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


Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
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
Odoo Developer
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 .

Odoo Developer
on 7/25/16, 4:42 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


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