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 recall some certain function when click "save" button in "creating form"?

By
vx2008
on 7/22/16, 12:35 AM 487 views

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


0

Sudhir Arya (SA)

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

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

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

Hello,

You can override create and write method for an object.

Ex:

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!

vx2008
on 7/24/16, 9:18 AM
3
kirubanidhi
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


@api.multi

def save(self):

 ... your code...

    a = self._cr

     print a

    if a:

         print "success"

    else:

         print "false"

    return a


Output:

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.

vx2008
on 7/22/16, 3:40 AM
1
shameem@axon
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

     pass

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";

vx2008
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 .

shameem@axon
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)

Stats

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