Error inserting new doc

Hi,

on my code :
from future import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _
class SPK(Document):
pass
def validate_new(doc,method):
chk_dupl_itm = []
#frappe.throw(doc)
for d in doc.get(‘sales_order_details’):
if frappe.db.get_value(“SPK”, {“kode_spk”: d.kode_spk}):
frappe.throw((“Kode spk {0} telah terpakai”).format(d.kode_spk))
else :
if d.kode_spk in chk_dupl_itm:
frappe.throw(
(“Kode SPK {0} has been entered twice”).format(d.kode_spk))
else:
chk_dupl_itm.append(d.kode_spk)
if method==“on_submit”:
for d in doc.get(‘sales_order_details’):
record = frappe.get_doc({
“doctype”:“SPK”,
“kode_spk”:d.kode_spk,
“sales_order”:doc.get(“name”),
“order_date”:doc.get(“transaction_date”)
})
record.insert() <<<< this is line 29… that showed error in the logs
record.submit()

i got this error :
Traceback (innermost last):
File “/home/sigma/frappe-bench/apps/frappe/frappe/widgets/form/save.py”, line 18, in savedocs
doc.save()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 216, in save
self.run_post_save_methods()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 445, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 412, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 493, in composer
return composed(self, method, *args, **kwargs)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 478, in runner
add_to_return_value(self, f(self, method, *args, **kwargs))
File “/home/sigma/frappe-bench/apps/manufacture_costing/manufacture_costing/manufacture_costing/doctype/spk/spk.py”, line 29, in validate_new
record.insert()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 145, in insert
self._validate()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 257, in _validate
self._validate_constants()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 343, in _validate_constants
if self.get(fieldname) != values.get(fieldname):
AttributeError: ‘NoneType’ object has no attribute ‘get’

Traceback (innermost last):
File “/home/sigma/frappe-bench/apps/frappe/frappe/app.py”, line 49, in application
response = frappe.handler.handle()
File “/home/sigma/frappe-bench/apps/frappe/frappe/handler.py”, line 66, in handle
execute_cmd(cmd)
File “/home/sigma/frappe-bench/apps/frappe/frappe/handler.py”, line 89, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/sigma/frappe-bench/apps/frappe/frappe/init.py”, line 531, in call
return fn(*args, **newargs)
File “/home/sigma/frappe-bench/apps/frappe/frappe/widgets/form/save.py”, line 18, in savedocs
doc.save()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 216, in save
self.run_post_save_methods()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 445, in run_post_save_methods
self.run_method(“on_submit”)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 412, in run_method
return Document.hook(fn)(self, *args, **kwargs)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 493, in composer
return composed(self, method, *args, **kwargs)
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 478, in runner
add_to_return_value(self, f(self, method, *args, **kwargs))
File “/home/sigma/frappe-bench/apps/manufacture_costing/manufacture_costing/manufacture_costing/doctype/spk/spk.py”, line 29, in validate_new
record.insert()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 145, in insert
self._validate()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/document.py”, line 257, in _validate
self._validate_constants()
File “/home/sigma/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 343, in _validate_constants
if self.get(fieldname) != values.get(fieldname):
AttributeError: ‘NoneType’ object has no attribute ‘get’

please help… i have no idea about this
im inserting this via hooks

Thanks

Uncheck “edit only once” field in your DocType. Its buggy at the moment.

wow thanks … its works…:slight_smile: