From 49a79cdb36b8a31828b2e144c96d8f755b344fc9 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Wed, 14 May 2025 19:57:09 +0530 Subject: [PATCH] fix: added products table in crm lead (cherry picked from commit 26c892c2a046a576311a5ca309d61e878201556c) --- crm/fcrm/doctype/crm_deal/crm_deal.js | 18 ++----- crm/fcrm/doctype/crm_lead/crm_lead.js | 64 +++++++++++++++++++++++++ crm/fcrm/doctype/crm_lead/crm_lead.json | 46 +++++++++++++++++- 3 files changed, 111 insertions(+), 17 deletions(-) diff --git a/crm/fcrm/doctype/crm_deal/crm_deal.js b/crm/fcrm/doctype/crm_deal/crm_deal.js index a7f26fb5..3526767a 100644 --- a/crm/fcrm/doctype/crm_deal/crm_deal.js +++ b/crm/fcrm/doctype/crm_deal/crm_deal.js @@ -12,20 +12,10 @@ frappe.ui.form.on("CRM Deal", { frm.doc.products.forEach((d) => { total += d.amount; total_qty += d.qty; - net_total += d.net_amount || d.amount; + net_total += d.net_amount; }); - if (total) { - frappe.model.set_value(frm.doctype, frm.docname, "total", total); - } - if (total_qty) { - frappe.model.set_value( - frm.doctype, - frm.docname, - "total_qty", - total_qty - ); - } + frappe.model.set_value(frm.doctype, frm.docname, "total", total); frappe.model.set_value( frm.doctype, frm.docname, @@ -44,9 +34,7 @@ frappe.ui.form.on("CRM Products", { }, product_code: function (frm, cdt, cdn) { let d = frappe.get_doc(cdt, cdn); - if (!d.product_name) { - frappe.model.set_value(cdt, cdn, "product_name", d.product_code); - } + frappe.model.set_value(cdt, cdn, "product_name", d.product_code); }, rate: function (frm, cdt, cdn) { let d = frappe.get_doc(cdt, cdn); diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.js b/crm/fcrm/doctype/crm_lead/crm_lead.js index 0a9d57e1..af944f40 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.js +++ b/crm/fcrm/doctype/crm_lead/crm_lead.js @@ -5,4 +5,68 @@ frappe.ui.form.on("CRM Lead", { refresh(frm) { frm.add_web_link(`/crm/leads/${frm.doc.name}`, __("Open in Portal")); }, + update_total: function (frm) { + let total = 0; + let total_qty = 0; + let net_total = 0; + frm.doc.products.forEach((d) => { + total += d.amount; + total_qty += d.qty; + net_total += d.net_amount; + }); + + frappe.model.set_value(frm.doctype, frm.docname, "total", total); + frappe.model.set_value( + frm.doctype, + frm.docname, + "net_total", + net_total || total + ); + } }); + +frappe.ui.form.on("CRM Products", { + products_add: function (frm, cdt, cdn) { + frm.trigger("update_total"); + }, + products_remove: function (frm, cdt, cdn) { + frm.trigger("update_total"); + }, + product_code: function (frm, cdt, cdn) { + let d = frappe.get_doc(cdt, cdn); + frappe.model.set_value(cdt, cdn, "product_name", d.product_code); + }, + rate: function (frm, cdt, cdn) { + let d = frappe.get_doc(cdt, cdn); + if (d.rate && d.qty) { + frappe.model.set_value(cdt, cdn, "amount", d.rate * d.qty); + } + frm.trigger("update_total"); + }, + qty: function (frm, cdt, cdn) { + let d = frappe.get_doc(cdt, cdn); + if (d.rate && d.qty) { + frappe.model.set_value(cdt, cdn, "amount", d.rate * d.qty); + } + frm.trigger("update_total"); + }, + discount_percentage: function (frm, cdt, cdn) { + let d = frappe.get_doc(cdt, cdn); + if (d.discount_percentage && d.amount) { + discount_amount = (d.discount_percentage / 100) * d.amount; + frappe.model.set_value( + cdt, + cdn, + "discount_amount", + discount_amount + ); + frappe.model.set_value( + cdt, + cdn, + "net_amount", + d.amount - discount_amount + ); + } + frm.trigger("update_total"); + } +}); \ No newline at end of file diff --git a/crm/fcrm/doctype/crm_lead/crm_lead.json b/crm/fcrm/doctype/crm_lead/crm_lead.json index e39af407..a9c25416 100644 --- a/crm/fcrm/doctype/crm_lead/crm_lead.json +++ b/crm/fcrm/doctype/crm_lead/crm_lead.json @@ -37,6 +37,12 @@ "annual_revenue", "image", "converted", + "products_tab", + "products", + "section_break_ggwh", + "total", + "column_break_uisv", + "net_total", "sla_tab", "sla", "sla_creation", @@ -285,12 +291,47 @@ "fieldtype": "Table", "label": "Status Change Log", "options": "CRM Status Change Log" + }, + { + "fieldname": "products_tab", + "fieldtype": "Tab Break", + "label": "Products" + }, + { + "fieldname": "products", + "fieldtype": "Table", + "label": "Products", + "options": "CRM Products" + }, + { + "fieldname": "section_break_ggwh", + "fieldtype": "Section Break" + }, + { + "fieldname": "total", + "fieldtype": "Currency", + "label": "Total", + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "column_break_uisv", + "fieldtype": "Column Break" + }, + { + "description": "Total after discount", + "fieldname": "net_total", + "fieldtype": "Currency", + "label": "Net Total", + "options": "currency", + "read_only": 1 } ], + "grid_page_length": 50, "image_field": "image", "index_web_pages_for_search": 1, "links": [], - "modified": "2025-01-02 22:14:01.991054", + "modified": "2025-05-14 19:51:06.184569", "modified_by": "Administrator", "module": "FCRM", "name": "CRM Lead", @@ -331,6 +372,7 @@ "share": 1 } ], + "row_format": "Dynamic", "sender_field": "email", "sender_name_field": "first_name", "show_title_field_in_link": 1, @@ -339,4 +381,4 @@ "states": [], "title_field": "lead_name", "track_changes": 1 -} \ No newline at end of file +}