Skip to Content
Menu
This question has been flagged
1 Reply
6022 Views

Hi, Im making a customize delete button for my model in form view like this


But after the delete, the browser goes blank:


I want it to return an existing record that is there in my model, so how can I fix it? This is my delete button's code:

def delete_linked_user(self):
for rec in self:
holder = rec.user_id.partner_id
print(rec.user_id,' ',holder)
view = rec.user_id.unlink()
holder.unlink()
return {'type': 'ir.actions.client', 'tag': 'reload', }
Avatar
Discard
Best Answer

Hello,

        While returning you can try to include 'action' and call your act window or you can give a try with 'type' : 'ir.actions.act_window'

Avatar
Discard
Author

Hi Karthikeyan

I tried ur way too but didn't actually work, can you give me a specific example?

best regard

Hey Duy le,

Please can you be more specific?? I guess your requirement is to delete only the User and Partner that is linked with the current record and return the form view of current record. Is your model hr.employee or a customized one.??

Hi,

Your code works perfectly fine for me and i have tested in my local database too.

As your requirement, the User and its related Partner gets deleted and returns the current employee.

But the only con is it takes around one minute to delete and return the record.

Maybe due to lack of your server speed i.e cpu limit time you are not getting your record refreshed.

Try running your server with these in order to increase your cpu time limit

--limit-time-cpu=9999999999 --limit-time-real=99999999

Author

thanks Karthikeyan, I appreciate your help very much

My problem is that I want my button to work just like the normal delete (unlink) action. When the record is deleted, I want to show onto the client a record in form view belong to my model, not just a blank space.

Again, thank you very much for your help ^^

Hello Duy le,

The blank page appears only when you return a record which does not exist or the page that has not refreshed properly. Say you have 10 records and you are deleting the first one and you want to return the form view of second record? Is this your need ??

Author

yes that's right!!! You got me!

I want browser to display another record but still don't know how to do it with action :D

Hey Duy le,

I just now noticed that, you are not deleting your current record itself, you are deleting only the partner and user . The current record model is different from Partner and User.

In order to delete your current record you should add rec.unlink() as below,

def delete_linked_user(self):

for rec in self:

holder = rec.user_id.partner_id

print(rec.user_id,' ',holder)

view = rec.user_id.unlink()

holder.unlink()

rec.unlink()

return {'type': 'ir.actions.client', 'tag': 'reload', }

Author

Thank you very much for your enthusiastic support ^^

I tried ur way too, but the problem is this:

At first, I have a record with id 14 and in this url

http://localhost:8070/web?#id=14&action=243&model=bsmart.employee&view_type=form&cids=&menu_id=252

But after deletion, when I triggered the {'type': 'ir.actions.client', 'tag': 'reload'}, it loaded the same record (which is deleted now) so it still went blank

How can I redirect this action to load an other record then?

Hey Duy le,

@api.multi

def delete_linked_user(self):

action = self.env.ref('hr.open_view_employee_list_my').read()[0]

for rec in self:

holder = rec.user_id.partner_id

view = rec.user_id.unlink()

holder.unlink()

rec.unlink()

return action

In action mention your required module and your act window id

This works perfectly for me.

Thanks.

Author

Hi, sorry for the late reply, your solution works nicely ^^ Maybe not as I thought how it would be but finest so far, thanks a lot Karthikeyan ^^

Hi ,

Thanks for your vote, Glad to help.

Related Posts Replies Views Activity
3
Dec 23
2427
1
Jun 22
12786
4
Sep 21
15800
1
Sep 21
3262
1
Aug 21
7264