Autofill batch in stock entry when finish Manufacturing

I write code for insert last batch number in stock entry.
All normail - but it’s work only after i press F5 (Refresh) page. if not refresh and press aprove - have mistake
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 53, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 935, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 12, in savedocs
doc = frappe.get_doc(json.loads(doc))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 634, in get_doc
return frappe.model.document.get_doc(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 68, in get_doc
return controller(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 19, in init
super(AccountsController, self).init(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 112, in init
super(Document, self).init(kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 53, in init
self.update(d)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 76, in update
self.set(key, value)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 123, in set
self.extend(key, value)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 151, in extend
self.append(key, v)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 137, in append
value = self._init_child(value, key)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 166, in _init_child
value = get_controller(value[“doctype”])(value)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 112, in init
super(Document, self).init(kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 53, in init
self.update(d)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 76, in update
self.set(key, value)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 123, in set
self.extend(key, value)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 151, in extend
self.append(key, v)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 145, in append
"Document attached to child table must be a dict or BaseDocument, not " + str(type(value))[1:-1]
ValueError: Document attached to child table must be a dict or BaseDocument, not type ‘list’

How to fix it??

Debug your code and use the information from the stack trace. Frappe is getting a list instead of dict or Document object

I found mistake. Thanks.