This question has been flagged
2 Replies
4504 Views

I am using odoo 9. I am working in a view with a one2many field. The one2many field tree view list, there is a trash icon on the left of each row. When I click on the  trash icon, I would like to intercept record deletion and perform some custom action.

I tried to override unlink method but it does not break into the break point set inside the unlink so I think odoo is not calling unlink.  Any idea?

The view is view_pack_operation_lot_form. Here is my method:

@api.multi
def unlink(self): 
    res=super(myclass, self).unlink()
    # do my stuff
   return res


Avatar
Discard
Best Answer

It is not clear from you question whether you are calling the Unlink method of Child or Parent object.

Anyways In case of One2many, Deleting depends on the record's storage mode, i.e

  1. deletion upon saved lines (physical records)

  2. deletion upon unsaved records (cache records)


Hence when you calling Unlink method of Child Object, this will work well w.r.t Physical Records, but not on Cache records, which are not saved to the database.

So the alternate solution would be to deal with the One2many field values which you will receive in the Write Values of Parent Object.




Avatar
Discard
Author

Sorry, originally I put the unlink method in the child class (stock.pack.operation.lot) which I realize is not correct. It should be in the parent class (stock,pack.operation). So I override the parent (stock.pack.operation) unlink method. Upon deleting the row, it still does not trigger the parent class' unlink method.

In my case, it is the cache scenario since the rows are not saved yet. I cannot wait until "write" is called when clicking on the "Save" button though since I need to perform some operation on the cached rows before saving to the db.

I would like to know which method is called when the trash can icon is clicked. Then I can try to intercept and override that, I cannot locate the codes in the source. If you have ideas, please share with me. Thanks.

Best Answer

Hello, 

Did you find any solution for this?

Avatar
Discard