diff --git a/versa_system/hooks.py b/versa_system/hooks.py index 16bf1c6..290d7fc 100644 --- a/versa_system/hooks.py +++ b/versa_system/hooks.py @@ -146,10 +146,6 @@ } } - - - - # Scheduled Tasks # --------------- diff --git a/versa_system/public/js/lead.js b/versa_system/public/js/lead.js index 3a7e77c..bf6f1af 100644 --- a/versa_system/public/js/lead.js +++ b/versa_system/public/js/lead.js @@ -13,5 +13,17 @@ frappe.ui.form.on("Lead", { } }); +frappe.ui.form.on('Lead', { + refresh: function(frm) { + frm.fields_dict['material_details'].grid.get_field('product_item').get_query = function(doc, cdt, cdn) { + return { + query: "versa_system.versa_system.custom_script.lead.get_only_products" + }; + }; + } +}); + + + diff --git a/versa_system/public/js/quotation.js b/versa_system/public/js/quotation.js index 87c9bb1..ccc8f77 100644 --- a/versa_system/public/js/quotation.js +++ b/versa_system/public/js/quotation.js @@ -1,14 +1,18 @@ + + frappe.ui.form.on("Quotation", { refresh: function(frm) { - frm.add_custom_button( - __("GoTo Final Design"), - function () { - frappe.model.open_mapped_doc({ - method: "versa_system.versa_system.doctype.final_design.final_design.map_quotation_to_final_design", - source_name: frm.doc.name - }); - }, - __("Create") - ); + if (frm.doc.workflow_state === "Approved") { + frm.add_custom_button( + __("GoTo Final Design"), + function () { + frappe.model.open_mapped_doc({ + method: "versa_system.versa_system.doctype.final_design.final_design.map_quotation_to_final_design", + source_name: frm.doc.name + }); + }, + __("Create") + ); + } } -}); \ No newline at end of file +}); diff --git a/versa_system/public/js/sales_order.js b/versa_system/public/js/sales_order.js index 9aaeb97..f32cfbb 100644 --- a/versa_system/public/js/sales_order.js +++ b/versa_system/public/js/sales_order.js @@ -1,16 +1,13 @@ frappe.ui.form.on("Sales Order", { refresh: function (frm) { - // Set the indicator label based on the current status setStatusIndicator(frm); }, status: function (frm) { - // Update the indicator label dynamically when the status changes setStatusIndicator(frm); }, }); -// Function to set the indicator label based on status function setStatusIndicator(frm) { if (frm.doc.status === "Proforma Invoice") { frm.page.set_indicator("Proforma Invoice", "blue"); diff --git a/versa_system/versa_system/custom_script/lead.py b/versa_system/versa_system/custom_script/lead.py new file mode 100644 index 0000000..c47aab4 --- /dev/null +++ b/versa_system/versa_system/custom_script/lead.py @@ -0,0 +1,17 @@ +import frappe + +@frappe.whitelist() +def get_only_products(doctype, txt='', searchfield='name', start=0, page_len=20, filters=None): + """ + Fetch only 'Products' from the Item doctype. + """ + items = frappe.db.get_list( + "Item", + filters={"item_group": "Products"}, + fields=["name"], + order_by="modified DESC", + start=start, + page_length=page_len + ) + + return [(item["name"],) for item in items] diff --git a/versa_system/versa_system/custom_script/quotation.py b/versa_system/versa_system/custom_script/quotation.py index b2fa958..53e0dd7 100644 --- a/versa_system/versa_system/custom_script/quotation.py +++ b/versa_system/versa_system/custom_script/quotation.py @@ -9,43 +9,57 @@ def map_moc_design_to_quotation(source_name, target_doc=None): """ def set_missing_values(source, target): + target.party_name = source.lead + lead_materials = frappe.get_all( "Lead Material Details", filters={"parent": source.name}, - fields=["material_type", "size", "brand", "rate_range", "quantity", "image", "feasible"] + fields=["product_item", "size", "brand", "rate_range", "quantity", "image", "feasible"] ) for item in lead_materials: - # Append to 'material_item' table if it exists + item_code = item.get("product_item") + + if not item_code: + frappe.throw(f"Product Item is missing for an entry in Lead Material Details: {item}") + + item_details = frappe.get_value("Item", item_code, ["item_name", "stock_uom"], as_dict=True) + + if not item_details: + frappe.throw(f"Item {item_code} not found in Item Master.") + if hasattr(target, "material_item"): target.append("material_item", { - "material_type": item.material_type, - "size": item.size, - "brand": item.brand, - "rate_range": item.rate_range, - "image": item.image, - "feasible": item.feasible, - "quantity": item.quantity + "product_item": item_code, + "size": item.get("size"), + "brand": item.get("brand"), + "rate_range": item.get("rate_range"), + "image": item.get("image"), + "feasible": item.get("feasible"), + "quantity": item.get("quantity") }) - # Append to 'items' table if it exists if hasattr(target, "items"): target.append("items", { - "item_code": item.material_type, - "rate": item.rate_range, - "qty": item.quantity + "item_code": item_code, + "item_name": item_details["item_name"], + "rate": item.get("rate_range"), + "qty": item.get("quantity"), + "uom": item_details["stock_uom"] }) target_doc = get_mapped_doc( "MOC Design", source_name, { "MOC Design": { - "doctype": "Quotation" + "doctype": "Quotation", + "field_map": { + "lead": "party_name" + } } - }, # Removed the duplicate 'Lead Material Details' mapping + }, target_doc, set_missing_values ) return target_doc - diff --git a/versa_system/versa_system/custom_script/work_order.py b/versa_system/versa_system/custom_script/work_order.py index 57b6046..3136dbc 100644 --- a/versa_system/versa_system/custom_script/work_order.py +++ b/versa_system/versa_system/custom_script/work_order.py @@ -3,14 +3,13 @@ @frappe.whitelist() def update_sales_order_status_on_work_order_completion(doc, method): - # Fetch the latest status directly from the database + current_status = frappe.db.get_value("Work Order", doc.name, "status") if current_status == "Completed" and doc.sales_order: try: sales_order = frappe.get_doc("Sales Order", doc.sales_order) - # Check if status needs to be updated if sales_order.status != "Proforma Invoice": sales_order.status = "Proforma Invoice" sales_order.save(ignore_permissions=True) diff --git a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.js b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.js index 7def155..1f64c00 100644 --- a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.js +++ b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.js @@ -3,7 +3,7 @@ frappe.ui.form.on("Feasibility Check", { refresh(frm) { - if (frm.doc.workflow_state === "Approved") { // Ensure the button appears only after saving + if (frm.doc.workflow_state === "Approved") { frm.add_custom_button( __("GoTo MOC Design"), function () { diff --git a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.json b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.json index 9e3e03e..cbd7e4c 100644 --- a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.json +++ b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.json @@ -14,7 +14,8 @@ "fieldname": "lead", "fieldtype": "Link", "label": "Lead ", - "options": "Lead" + "options": "Lead", + "read_only": 1 }, { "fieldname": "feasible_material_details", @@ -25,7 +26,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2025-02-28 02:44:35.596369", + "modified": "2025-03-04 23:53:23.789715", "modified_by": "Administrator", "module": "Versa System", "name": "Feasibility Check", diff --git a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.py b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.py index 127fe78..411bfdb 100644 --- a/versa_system/versa_system/doctype/feasibility_check/feasibility_check.py +++ b/versa_system/versa_system/doctype/feasibility_check/feasibility_check.py @@ -16,6 +16,8 @@ def map_lead_to_feasibility_check(source_name, target_doc=None): def set_missing_values(source,target): pass + + target_doc = get_mapped_doc("Lead", source_name, { "Lead": { @@ -26,6 +28,7 @@ def set_missing_values(source,target): "doctype": "Lead Material Details", "field_map": { "material_type": "material_type", + "product_item":"product_item", "size": "size", "brand": "brand", "rate_range": "rate_range", @@ -45,3 +48,4 @@ def set_missing_values(source,target): + diff --git a/versa_system/versa_system/doctype/final_design/final_design.json b/versa_system/versa_system/doctype/final_design/final_design.json index d1514dd..313536b 100644 --- a/versa_system/versa_system/doctype/final_design/final_design.json +++ b/versa_system/versa_system/doctype/final_design/final_design.json @@ -20,12 +20,13 @@ "fieldname": "lead", "fieldtype": "Link", "label": "Lead", - "options": "Lead" + "options": "Lead", + "read_only": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2025-02-25 22:19:47.411803", + "modified": "2025-03-05 21:04:15.751651", "modified_by": "Administrator", "module": "Versa System", "name": "Final Design", diff --git a/versa_system/versa_system/doctype/final_design/final_design.py b/versa_system/versa_system/doctype/final_design/final_design.py index f28cf84..132630c 100644 --- a/versa_system/versa_system/doctype/final_design/final_design.py +++ b/versa_system/versa_system/doctype/final_design/final_design.py @@ -10,13 +10,10 @@ def before_save(self): self.fetch_lead_items() def fetch_lead_items(self): - # Fetch Lead document lead_doc = frappe.get_doc("Lead", self.lead) - # Clear existing items in the child table self.set("items", []) - # Check if the lead has a child table named 'lead_material_details' if hasattr(lead_doc, "lead_material_details"): for item in lead_doc.lead_material_details: self.append("items", { diff --git a/versa_system/versa_system/doctype/lead_material_details/lead_material_details.json b/versa_system/versa_system/doctype/lead_material_details/lead_material_details.json index 4259cd8..efa843e 100644 --- a/versa_system/versa_system/doctype/lead_material_details/lead_material_details.json +++ b/versa_system/versa_system/doctype/lead_material_details/lead_material_details.json @@ -13,7 +13,8 @@ "image", "feasible", "quantity", - "availability" + "availability", + "product_item" ], "fields": [ { @@ -60,12 +61,18 @@ "fieldtype": "Select", "label": "Availability", "options": "Available\nNot Available" + }, + { + "fieldname": "product_item", + "fieldtype": "Link", + "label": "Product Item", + "options": "Item" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2025-02-25 23:48:13.158021", + "modified": "2025-03-10 03:31:21.387104", "modified_by": "Administrator", "module": "Versa System", "name": "Lead Material Details", diff --git a/versa_system/versa_system/doctype/material_check/material_check.js b/versa_system/versa_system/doctype/material_check/material_check.js index e82ffdd..cb11999 100644 --- a/versa_system/versa_system/doctype/material_check/material_check.js +++ b/versa_system/versa_system/doctype/material_check/material_check.js @@ -3,12 +3,14 @@ frappe.ui.form.on("Material Check", { refresh(frm) { + if(!frm.is_new()) frm.add_custom_button( __("Material Request"), function () { frappe.set_route("Form", "Material Request", "new-material-request"); } ); + if(!frm.is_new()) frm.add_custom_button( __("Work Order"), function () { diff --git a/versa_system/versa_system/doctype/moc_design/moc_design.js b/versa_system/versa_system/doctype/moc_design/moc_design.js index ad504a2..ded7978 100644 --- a/versa_system/versa_system/doctype/moc_design/moc_design.js +++ b/versa_system/versa_system/doctype/moc_design/moc_design.js @@ -3,7 +3,7 @@ frappe.ui.form.on("MOC Design", { refresh(frm) { - if (frm.doc.workflow_state === "Approved") { // Ensure the button appears only after saving + if (frm.doc.workflow_state === "Approved") { frm.add_custom_button( __("GoTo Quotation"), function () { diff --git a/versa_system/versa_system/doctype/moc_design/moc_design.json b/versa_system/versa_system/doctype/moc_design/moc_design.json index bf746e5..5553190 100644 --- a/versa_system/versa_system/doctype/moc_design/moc_design.json +++ b/versa_system/versa_system/doctype/moc_design/moc_design.json @@ -21,18 +21,20 @@ "fieldname": "feasibility_check", "fieldtype": "Link", "label": "Feasibility Check", - "options": "Feasibility Check" + "options": "Feasibility Check", + "read_only": 1 }, { "fieldname": "lead", "fieldtype": "Link", "label": "Lead", - "options": "Lead" + "options": "Lead", + "read_only": 1 } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2025-02-23 22:03:54.661291", + "modified": "2025-03-04 23:54:59.326096", "modified_by": "Administrator", "module": "Versa System", "name": "MOC Design", diff --git a/versa_system/versa_system/doctype/moc_design/moc_design.py b/versa_system/versa_system/doctype/moc_design/moc_design.py index 98a87e6..008b6b3 100644 --- a/versa_system/versa_system/doctype/moc_design/moc_design.py +++ b/versa_system/versa_system/doctype/moc_design/moc_design.py @@ -10,37 +10,31 @@ class MOCDesign(Document): @frappe.whitelist() def map_feasibility_check_to_moc_design(source_name, target_doc=None): """ - Map fields from Feasibility Check to MOC Design, - including child table 'Feasible Material Details' -> 'MOC Material Details' + Map Feasibility Check to MOC Design, including only child table rows where 'feasible' is checked. """ def set_missing_values(source, target): - pass + target.set("Lead Material Details", []) - target_doc = get_mapped_doc( - "Feasibility Check", source_name, + filtered_materials = [row for row in source.get("feasible_material_details") if row.get("feasible")] + + for row in filtered_materials: + target.append("moc_design", { + "material_type": row.material_type, + "product_item":row.product_item, + "size": row.size, + "brand": row.brand, + "rate_range": row.rate_range, + "image": row.image, + "feasible": row.feasible, + "quantity": row.quantity + }) + + target_doc = get_mapped_doc("Feasibility Check", source_name, { "Feasibility Check": { "doctype": "MOC Design", "field_map": {} - - }, - "Lead Material Details": { - "doctype": "Lead Material Details", - "field_map": { - "material_type": "material_type", - "size": "size", - "brand": "brand", - "rate_range": "rate_range", - "image": "image", - "feasible": "feasible", - "quantity": "quantity" - }, - "add_if_empty": True } - }, - target_doc, - set_missing_values - ) + }, target_doc, set_missing_values) return target_doc - diff --git a/versa_system/versa_system/report/__init__.py b/versa_system/versa_system/report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/versa_system/versa_system/report/sales_order_report/__init__.py b/versa_system/versa_system/report/sales_order_report/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/versa_system/versa_system/report/sales_order_report/sales_order_report.js b/versa_system/versa_system/report/sales_order_report/sales_order_report.js new file mode 100644 index 0000000..02df9e8 --- /dev/null +++ b/versa_system/versa_system/report/sales_order_report/sales_order_report.js @@ -0,0 +1,8 @@ +// Copyright (c) 2025, efeone and contributors +// For license information, please see license.txt + +frappe.query_reports["Sales Order Report"] = { + "filters": [ + + ] +}; diff --git a/versa_system/versa_system/report/sales_order_report/sales_order_report.json b/versa_system/versa_system/report/sales_order_report/sales_order_report.json new file mode 100644 index 0000000..e50eaa3 --- /dev/null +++ b/versa_system/versa_system/report/sales_order_report/sales_order_report.json @@ -0,0 +1,39 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2025-03-03 00:37:59.668841", + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "letterhead": null, + "modified": "2025-03-03 00:37:59.668841", + "modified_by": "Administrator", + "module": "Versa System", + "name": "Sales Order Report", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Sales Order", + "report_name": "Sales Order Report", + "report_type": "Script Report", + "roles": [ + { + "role": "Sales User" + }, + { + "role": "Sales Manager" + }, + { + "role": "Maintenance User" + }, + { + "role": "Accounts User" + }, + { + "role": "Stock User" + } + ], + "timeout": 0 +} \ No newline at end of file diff --git a/versa_system/versa_system/report/sales_order_report/sales_order_report.py b/versa_system/versa_system/report/sales_order_report/sales_order_report.py new file mode 100644 index 0000000..dd44daa --- /dev/null +++ b/versa_system/versa_system/report/sales_order_report/sales_order_report.py @@ -0,0 +1,9 @@ +# Copyright (c) 2025, efeone and contributors +# For license information, please see license.txt + +# import frappe + + +def execute(filters=None): + columns, data = [], [] + return columns, data