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.

4

How to trigger function on object write?

By
Allison
on 3/12/13, 12:36 PM 5,721 views

I want to send a message to the salesperson assigned to an Account when that account is edited by another user. How to I tie into the ORM to trigger my function on object save? The closest I have gotten is the on_change method on specific fields; I don't want to add this per field.

3

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/12/13, 1:14 PM

You can override the write() method of the desired object (e.g. account.account).

def write(self, cr, uid, ids, vals, context=None):
    my_custom_send_mail_function()
    res = super(my_class, self).write(cr, uid, ids, vals, context=context)
    return res

But this is a very deep intrusion into the system and may have side effects.

Mabye you can also use Automated Actions for this purpose. See menu "Settings / Technical / Automated Actions".

Exactly, it's the best answer +1

Yug Faa
on 3/12/13, 1:17 PM

Thanks Andreas..If we need to add many2one field (that data need to load after function trigger )

ex : select * from hr_department where xxxxxx then how to get them in my that field .?

priyankahdp
on 3/23/13, 8:27 AM

If you want to set a certain value when an object is written, you can use the provided function and update the vals dict before the call of the write().

Andreas Brueckl
on 3/24/13, 8:10 AM
1

Fabien Pinckaers (fp)

--Fabien Pinckaers (fp)--
6598
| 6 8 8
fsdsdfsdf, Belgium
--Fabien Pinckaers (fp)--

Odoo Founder & CEO

Fabien Pinckaers (fp)
On 5/24/14, 4:20 AM

You should not develop custom modules for such customizations. Use the base_action_rule module that allows to create such a rule in just a few clicks.

Is it possible to use Automated Actions to trigger client-side wizards/popups? For example, I'm trying to add the ability to detect potential duplicate Partners as a new one is entered (rather than relying on deduplication after the face). You can't trigger a wizard from inside an onchange() where this functionality would be the most useful, but I might be able to trigger a popup when the user attempts to Save a record that could be a duplicate. I've attempted to test this by using Automated Actions to link Partner Create or Write with the Deduplicate Contacts action, but nothing seems to happen.

Justin
on 2/2/15, 1:19 AM
0
gayathiri
On 5/24/14, 4:06 AM

Thanks Andreas, that's the solution I found too - was hoping to not have to go there. I'll look into the Automated Actions.

0
Allison
On 3/12/13, 1:15 PM

The solution I found is overwriting the object in questions write() function. I was hoping there was a flag or setting instead, but this does the trick too.

def write(self, cr, uid, ids, vals, context=None):
    # Function calls and such here
    return super(sale_order, self).write(cr, uid, ids, vals, context=context)

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

2 follower(s)

Stats

Asked: 3/12/13, 12:36 PM
Seen: 5721 times
Last updated: 3/16/15, 8:10 AM