When using new_doc in stock entry and when you update the item child table it doesn’t update the total amount and you just need to remove the table and to update again what I am implementing is that automatic sets data when button Create Stock Entry.
here is my code
frm.add_custom_button(__(Create DIR), function(){ | ||
---|---|---|
frappe.call({ | ||
method: make_dir, | ||
args: { | ||
dn: frm.doc.name, | ||
dt: frm.doc.doctype, | ||
vehicle: frm.doc.vehicle, | ||
posting_date: frm.doc.posting_date, | ||
no_of_liters: frm.doc.number_of_liters, | ||
remarks: frm.doc.remarks, | ||
}, | ||
callback:function(r){ | ||
if(r.message){ | ||
console.log(r.message); | ||
// r.message.forEach(items => { | ||
// frappe.model.set_value(items.cdt, items.cdn, uom, items.uom); | ||
// frappe.model.set_value(items.cdt, items.cdn, stock_uom, items.stock_uom); | ||
// }) | ||
frappe.model.sync(r.message); | ||
frappe.set_route(Form, r.message.doctype, r.message.name); | ||
} | ||
} | ||
}) | ||
}) |
exist_dir = frappe.get_all(“Stock Entry Detail”, filters = dir_filters, fields=[“parent”])
if len(exist_dir) > 0:
dir_doc = frappe.get_doc(“Stock Entry”, exist_dir[0].parent)
else:
# Make new DIR
item = frappe.get_doc(“Item”, “DIESOLINE”)
dir_doc = frappe.new_doc("Stock Entry")
dir_doc.update({
"company": default_company,
"stock_entry_type": "Diesel Issuance",
"posting_date": args.posting_date,
"custom_target_equipment": args.vehicle,
"custom_reference_document_no": args.dn,
"custom_notes": args.remarks
})
# vt_report = ""
# sched_oil = ""
# if args.dt == 'Vehicle Tracker Report':
# vt_report = args.dn
# elif args.dt == 'Schedule for Change Oil':
# sched_oil = args.dn
# fix stock entry when creating
dir_doc.append("items", {
"s_warehouse": default_s_warehouse,
"item_code": item.name,
"basic_rate": 55,
"qty": args.no_of_liters,
"uom": item.stock_uom,
"stock_uom": item.stock_uom,
})
frappe.response[“message”] = dir_doc.as_dict()