Greetings everyone,
I am trying to create a custom doc(tool) that will allow me to bulk create or update a document.
however, when i click the execute button, I get no prompt and the new record is not save even though the record name is returned. Also when the record is existing and the child is not, the child is not added or saved.
sample code:
def make_doc(dt,dn):
customdoc = frappe.get_doc(dt, dn)
for emp in customdoc.employees:
new_doc = 0
employee_doc = frappe.get_all(“doc”, filters={‘status’: ‘draft’,“employee”:emp.employee}, fields=[“*”])
time_log_ctr = 0
if not employee_doc:
new_doc = 1
doc = frappe.new_doc("doc")
doc.company = doc.company
doc.status = "draft"
doc.employee = emp.employee
doc.start_date = doc.for_date
if not doc:
frappe.throw(_("Unable to create doc "))
elif employee_doc:
doc = frappe.get_doc("doc",employee_doc[0].name)
doc.doc_childs = frappe.get_all("doc Detail", filters={'parent': doc.name}, fields=["*"])
doc_childs = doc.doc_childs
a_doc_child = doc.get_doc_child(doc.name,doc.var1,emp.varaa)
if not a_doc_child and emp.varaa > 00:
doc.append("doc_childs",{"var1":1,"varb":emp.varaa})
b_doc_child = doc.get_doc_child(doc.name,doc.var1,emp.varab)
if not b_doc_child and emp.varab > 00:
doc.append("doc_childs",{"var1":1,"varb":emp.varab})
c_doc_child = doc.get_doc_child(doc.name,doc.var1,emp.varac)
if not c_doc_child and emp.varac > 00:
doc.append("doc_childs",{"var1":1,"varb":emp.varac})
if new_doc == 1:
doc.insert()
#else:
# doc.insert()
by the way, I was able to create a new doc record with a child. It will work if I comment out the if-condition block and add “doc.append(“doc_childs”,{“var1”:1,“varb”:emp.varaa})” below the “doc.start_date” line.