Hi Guys,
How I can insert multi row of child table using db.insert
in my case I have Custom (Parent and child) Doctype and when Click on button that create sales invoice and child table (Custom) is should be insert in Sales invoice items
but I can’t insert multi rows in this way, here I use [0] for just specific row
frappe.ui.form.on('Reservation', {
refresh: function(frm, cdt, cdn) {
if(frm.doc.res_status == "Check In Paid"){
frm.add_custom_button(__("Pay & Renew"), function () {
frappe.db.insert({
'doctype': 'Sales Invoice',
'guest_name': frm.doc.guest,
'customer': 'Guest',
'cost_center': 'Baghdad - BH',
'selling_price_list': 'Per Room',
'docstatus':1,
'is_pos':1,
'payments':[
{
'mode_of_payment': 'نقد',
'amount':frm.doc.reservation_pricing,
'account':'1110 - نقد - BH'
}
],
'sales_partner': frm.doc.company_name,
// here I want pass more than one row, now I use for specific row
'items': [
{
'item_code' : frm.doc.rooms[0].room_number,
'item_name' : frm.doc.rooms[0].room_number,
'qty':frm.doc.number_of_night
}
]
}).then(doc => {
console.log(doc.name);
console.log(cstr(frm.doc.rooms.length));
var row = frappe.model.add_child(frm.doc, "Sales Invoice Reservation", "sales_invoice");
row.sales_invoice = doc.name;
frm.refresh_fields("sales_invoice");
frm.save();
});
}).addClass("btn-danger");
}
}
});