From 71269acdc61912358465786eb2bd2c064e4c5b96 Mon Sep 17 00:00:00 2001 From: Avishna Murali Date: Mon, 13 Jan 2025 16:08:46 +0530 Subject: [PATCH] fix:Add custom button 'Go to Quotation' to Raw Material Request form --- .../versa_system/custom_script/quotation.py | 14 +++++ .../raw_material_request.js | 51 +++++++++---------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/versa_system/versa_system/custom_script/quotation.py b/versa_system/versa_system/custom_script/quotation.py index b941847..3297271 100644 --- a/versa_system/versa_system/custom_script/quotation.py +++ b/versa_system/versa_system/custom_script/quotation.py @@ -73,3 +73,17 @@ def filter_approved_items(source, target, source_parent): ) return target_doc + +@frappe.whitelist() +def get_quotations_by_lead(lead_name): + """ + Function to fetch all Quotations associated with a specific Lead. + This method is intended to be called from the client side via an API call + """ + if not lead_name: + frappe.throw(_("Lead name is required")) + return frappe.get_all( + "Quotation", + filters={"party_name": lead_name}, # Use the correct field here + fields=["name"] + ) diff --git a/versa_system/versa_system/doctype/raw_material_request/raw_material_request.js b/versa_system/versa_system/doctype/raw_material_request/raw_material_request.js index 0628492..ab6c87b 100644 --- a/versa_system/versa_system/doctype/raw_material_request/raw_material_request.js +++ b/versa_system/versa_system/doctype/raw_material_request/raw_material_request.js @@ -20,34 +20,33 @@ frappe.ui.form.on('Raw Material Request', { } ); } - - // Add "Go to Quotation" button if all rows are checked - if (all_checked) { - frm.add_custom_button( - __('Go to Quotation'), - function() { - frappe.call({ - method: "frappe.client.get_list", - args: { - doctype: "Quotation", - fields: ["name"] - }, - callback: function(response) { - if (response.message && response.message.length > 0) { - // Navigate to the existing Quotation - frappe.set_route('Form', 'Quotation', response.message[0].name); - } else { - // Create and navigate to a new Quotation - frappe.new_doc('Quotation'); - } - } - }); + // Add a custom button labeled 'Go to Quotation' in the form + if (all_checked){ + frm.add_custom_button(__('Go to Quotation'), function() { + if (!frm.doc.lead) { + frappe.msgprint(__('No Lead is linked to this Raw Material Request.')); + return; + } + frappe.call({ + method: "versa_system.versa_system.custom_script.quotation.get_quotations_by_lead", + args: { + lead_name: frm.doc.lead + }, + callback: function(response) { + if (response.message && response.message.length > 0) { + frappe.set_route("Form", "Quotation", response.message[0].name); + } else { + frappe.msgprint(__('No Quotation is linked to the Lead associated with this Raw Material Request.')); + } } - ); - } + }); + }); + } + if (frm.fields_dict['item_details']) { - frm.fields_dict['item_details'].grid.toggle_display('is_customized', false); - frm.fields_dict['item_details'].grid.toggle_display('is_feasible', false); + frm.fields_dict['item_details'].grid.toggle_display('is_customized', false); // Hide the 'is_customized' column in the child table + frm.fields_dict['item_details'].grid.toggle_display('is_feasible', false); // Hide the 'is_feasible' column in the child table + } } });