This question has been flagged
4 Replies
24166 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.

Avatar
Discard
Best Answer

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

Avatar
Discard

Exactly, it's the best answer +1

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

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().

Best Answer

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.

Avatar
Discard

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.

Best Answer

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

Avatar
Discard
Author Best Answer

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)
Avatar
Discard