Skip to Content
Menu
This question has been flagged
2 Replies
577 Views

How can I execute a python function when in a One2many I click on the delete button and I still haven't saved the parent form.

Avatar
Discard
Author Best Answer

Hi Jainesh, your solution did not work for me, even if I save the parent form, it doesn't work when I delete either, it doesn't enter the unlink method, I'm in Odoo15 enterprise

Avatar
Discard
Best Answer

Hello Pavel,

You just need to follow below steps to achieve this.

Please Find code in comment. 

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Code :-

Step 1: Pass the custom flag in context.

<field name="o2m_field" context="{'is_from_o2m_field': True}">
<tree>...</tree>
</field>

Step 2: Inherit the relational model of our o2m_field and extend the unlink method like below.

def unlink(self):
if context.get("is_from_o2m_field"):
# write your custom code to call the desired function.
pass
return super().unlink()