Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
5997 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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

Autore

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

Autore

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', }

Autore

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.

Autore

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.

Post correlati Risposte Visualizzazioni Attività
3
dic 23
2406
1
giu 22
12770
4
set 21
15780
1
set 21
3244
1
ago 21
7237