frappe.ui.form.on('Quotation', {
refresh(frm) {
// Query for child customers where parent_customer is customer_name
frappe.db.get_list("Customer", {
filters: { 'parent_customer': frm.doc.customer_name },
fields: ['name', 'customer_name']
}).then(child_customers => {
// Include the parent customer in the list of customers to be queried for addresses
let all_customers = [frm.doc.customer_name].concat(child_customers.map(c => c.name));
// Fetch all addresses (no need to check is_group here)
frappe.db.get_list("Address", {
fields: ['name', 'address_line1', 'address_line2', 'city', 'state', 'country', 'customer']
}).then(addresses => {
// Filter the addresses to include only those related to our customers
let filtered_addresses = addresses.filter(address =>
all_customers.includes(address.customer) // Filter by customer names
);
// Prepare the addresses for the 'customer_address' field
let address_options = filtered_addresses.map(address => {
return {
value: address.name,
label: `${address.address_line1}, ${address.address_line2}, ${address.city}, ${address.state}, ${address.country}`
};
});
// Update the 'customer_address' field with the filtered addresses
frm.set_df_property('customer_address', 'options', address_options);
// Optionally, set the first address as the default value
if (filtered_addresses.length > 0) {
frm.set_value('customer_address', filtered_addresses[0].name); // Set default address if available
}
}).catch(err => {
console.error("Error fetching addresses:", err);
});
}).catch(err => {
console.error("Error fetching child customers:", err);
});
}
});
I change the customer doctype to a tree structure to able it to hold subsidiaries.
Now I am trying to create a new set of addresses in customer address from quotation doctype. Those address will be consists of the parent customer and the child customer. but I got an error stating Field not permitted in query: customer.
Can anyone help me with this?