I want the module to execute "some command lines" when user clicks the "save" button in "creating form";
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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!
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.
I am using a compute field for this purpose.
add simply the following in the model
def _perform_compute_action(self):
# Your Statementspass
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";
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 .
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up