i have a very simple thing how to get child table field data in python because i am facing issue in that also how to set doc_name in stock_entry_vouher i had check the data throught frappe.msgprint
doc = frappe.get_doc({
‘doctype’: ‘Stock Entry’,
‘Purpose’: ‘Material Transfer’,
‘posting_date’: doc.create_date,
“stock_entry_type”: “Material Transfer”,
‘items’: [{
‘item_code’: “100GSM Disperce Print-RED-245CM-C”,
‘qty’: 1,
“s_warehouse”: “Stores - T”,
‘from_warehouse’: “Stores - T”,
‘to_warehouse’: “Work In Progress - T”,
“t_warehouse”: “Work In Progress - T”,
}]
})
doc.insert()
if doc.name:
stock_entry_voucher = doc.name
frappe.msgprint("Stock Entry has been created: " + stock_entry_voucher)
else:
frappe.msgprint(“Failed to create Stock Entry.”)
NCP
May 30, 2024, 10:38am
2
Please check the sample code (tested):
stock_entry = frappe.get_doc({
'doctype': 'Stock Entry',
'purpose': 'Material Transfer',
'posting_date': "'2024-05-30'",
'stock_entry_type': 'Material Transfer',
'from_warehouse': 'Stores - FT',
'to_warehouse': 'Finished Goods - FT',
'items': [{
'item_code': 'RM 1',
'qty': 1,
's_warehouse': 'Stores - FT',
't_warehouse': 'Finished Goods - FT',
}]
})
stock_entry.insert()
# Accessing child table fields
for item in stock_entry.items:
frappe.msgprint(f"Item Code: {item.item_code}, Quantity: {item.qty}, Source Warehouse: {item.s_warehouse}")
stock_entry_voucher = stock_entry.name
frappe.msgprint("Stock Entry has been created: " + stock_entry_voucher)
Ok Thanks bro i have a question how i dynamically set the value of child table means i have a doctype name gate pass and child table field name is item and field name is item how you i get dynamic in child table parameter
also i want to save the document name of stock entry in gate pass doctype in stock entry voucher field
test = frappe.db.set_value(“Outward Gate Pass”, doc.name , “stock_entry_voucher” , stock_entry.name)
i used the aboove line but does not worked
NCP
May 31, 2024, 4:44am
6
Please check the syntax. Something like this will have to be applied (Not tested).
gate_pass = doc
stock_entry_items = []
for item in gate_pass.items:
stock_entry_items.append({
'item_code': item.item_code,
'qty': item.qty,
's_warehouse': item.s_warehouse,
'from_warehouse': item.from_warehouse,
'to_warehouse': item.to_warehouse,
't_warehouse': item.t_warehouse
})
stock_entry = frappe.get_doc({
'doctype': 'Stock Entry',
'purpose': 'Material Transfer',
'posting_date': gate_pass.posting_date,
'stock_entry_type': 'Material Transfer',
'items': stock_entry_items
})
stock_entry.insert()
frappe.msgprint(f"Stock Entry has been created: {stock_entry.name}")
outward_gate_pass = doc
frappe.msgprint(1)
stock_entry_items =
for item in outward_gate_pass.item:
stock_entry_items.append({
‘item_code’: item.item_code,
‘qty’: item.qty,
‘s_warehouse’: item.s_warehouse,
‘from_warehouse’: item.from_warehouse,
‘to_warehouse’: item.to_warehouse,
‘t_warehouse’: item.t_warehouse
})
frappe.msgprint(1)
stock_entry = frappe.get_doc({
‘doctype’: ‘Stock Entry’,
‘purpose’: ‘Material Transfer’,
‘posting_date’: outward_gate_pass.posting_date,
‘stock_entry_type’: ‘Material Transfer’,
‘items’: stock_entry_items
})
stock_entry.insert()
frappe.msgprint(f"Stock Entry has been created: {stock_entry.name}")
tihs code is not working
outward_gate_pass = doc
frappe.msgprint(1)
stock_entry_items =
for item in outward_gate_pass.item:
stock_entry_items.append({
# ‘item_code’: “100GSM Disperce Print-GRE-254CM-C”,
‘item_code’: item.item,
‘qty’: item.qty,
‘s_warehouse’: “Finished Goods - T”,
‘from_warehouse’: “Stores - T”,
‘to_warehouse’: “Finished Goods - T”,
‘t_warehouse’: “Stores - T”,
})
frappe.msgprint(1)
stock_entry = frappe.get_doc({
‘doctype’: ‘Stock Entry’,
‘purpose’: ‘Material Transfer’,
‘posting_date’: outward_gate_pass.posting_date,
‘stock_entry_type’: ‘Material Transfer’,
‘items’: stock_entry_items
})
stock_entry.insert()
frappe.msgprint(f"Stock Entry has been created: {stock_entry.name}")
frappe.errprint(outward_gate_pass.item)
Worked @NCP Thank you for the coorporation
NCP
June 1, 2024, 6:50pm
11
You have to check the field name and configure that according to the scenario.