Fetching items from product bundle and displaying the items in quotation doctype




According to my usecase i want to fetch items that are in a product bundle and then display those in the item table in quotation doctype when i click the get items from button in the dialog that i have created.

@abdulaziz Did you create the dialog throw a Client Script? If so, then you need to get the value of the bundle product and then you can get the Items of that product bundle.

Posting your Client Script will be helpful to fully understand your situation.

@kid1194
This is the client script that i wrote for the dialog.

@abdulaziz Try adding the following code inside the primary_action method, below or above d.hide().
If the code didn’t work, please send me the results that will be appearing in the console, but if it did work, remove all the console.log and mark this post as the solution as a reference for other users.
I apologize for not being able to test the code myself at the moment.

frappe.db.get_doc('Product Bundle', values.new_item_code)
.then(doc => {
    console.log(doc, doc.items);
    $.each(doc.items, function(i, item) {
        frm.add_child('items, item);
    });
});

@kid1194
Although the console is showing the items but nothing in being auto populated in the item table of new quotation. I want the items of my product bundle to be auto populated in the item table of new quotation . You can see from the attached photo

@abdulaziz I made a mistake in the code, there is a missing '. Here is the modified code.

frappe.db.get_doc('Product Bundle', values.new_item_code)
.then(doc => {
    $.each(doc.items, function(i, item) {
        frm.add_child('items', item);
    });
});

And if it still doesn’t work, please try this one.

frappe.db.get_doc('Product Bundle', values.new_item_code)
.then(doc => {
    $.each(doc.items, function(i, item) {
        frm.add_child('items', item);
    });
    frm.refresh_field('items');
});