Document has been modified error while trying in interactive using socket

Error: Document has been modified after you have opened it (2023-12-29 12:21:36.533403, 2023-12-29 12:21:42.550091). Please refresh to get the latest document.

I trying to interactive CRM using **socket** In existing CRM Module of erpnext.

Where I have two doctypes Lead and ToDo.

From Lead I create Todo’s. And from ToDo, I create another Todo doc and I update that in Lead.

image

It’s a HTML template. I updated this by using socket.

using:

frappe.publish_realtime('update_htmls')
frappe.realtime.on('update_htmls', ()=>{
    new Promise(resolve => setTimeout(updates(), 20000));
    function updates(){
        cur_frm.reload_doc()
    }
    });

Here I tried to update the closed todo’s and add the newly created todo in an open todo using socket. where I tried cur_frm.reload_doc() it reload the whole page. When i close the todo. It’s updating but when i create another todo.

I get this error.

Error: Document has been modified after you have opened it (2023-12-29 12:21:36.533403, 2023-12-29 12:21:42.550091). Please refresh to get the latest document.

But UI is updated. I am able to see the new todo’s in open tasks list. still i got this error.

Version:

Erpnext -14
frappe -14

OS - ubuntu

python version - 3.10

How to solve this problem? Or can I achieve this in any other way?

Thank you in advance…