Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions versa_system/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@
"onload": "versa_system.versa_system.custom_script.work_order.update_sales_order_status_on_work_order_completion"
}
}
doc_events = {
"Lead": {
"on_change": "versa_system.versa_system.custom_script.lead.get_only_products"
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed




Expand Down
15 changes: 15 additions & 0 deletions versa_system/public/js/lead.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,20 @@ frappe.ui.form.on("Lead", {
}
});

frappe.ui.form.on('Lead', {
refresh: function(frm) {
console.log("Lead form loaded - setting product filter");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

frm.fields_dict['material_details'].grid.get_field('product_item').get_query = function(doc, cdt, cdn) {
console.log("Product item field filter applied");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

return {
query: "versa_system.versa_system.custom_script.lead.get_only_products"
};
};
}
});





26 changes: 15 additions & 11 deletions versa_system/public/js/quotation.js
Original file line number Diff line number Diff line change
@@ -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")
); // <-- Corrected closing bracket
}
}
});
});
3 changes: 0 additions & 3 deletions versa_system/public/js/sales_order.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
18 changes: 18 additions & 0 deletions versa_system/versa_system/custom_script/lead.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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]
38 changes: 26 additions & 12 deletions versa_system/versa_system/custom_script/quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,43 @@ def map_moc_design_to_quotation(source_name, target_doc=None):
"""

def set_missing_values(source, target):



lead_materials = frappe.get_all(
"Lead Material Details",
filters={"parent": source.name},
fields=["material_type", "size", "brand", "rate_range", "quantity", "image", "feasible"]
)

for item in lead_materials:
item_code = item.get("material_type")

# Fetch `item_name` and `uom` from Item doctype
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.")

# Append to 'material_item' table if it exists
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
"material_type": 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(
Expand All @@ -42,10 +54,12 @@ def set_missing_values(source, target):
"MOC Design": {
"doctype": "Quotation"
}
}, # Removed the duplicate 'Lead Material Details' mapping
},
target_doc,
set_missing_values
)

return target_doc



Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"fieldname": "lead",
"fieldtype": "Link",
"label": "Lead ",
"options": "Lead"
"options": "Lead",
"read_only": 1
},
{
"fieldname": "feasible_material_details",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -45,3 +48,4 @@ def set_missing_values(source,target):




Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"image",
"feasible",
"quantity",
"availability"
"availability",
"product_item"
],
"fields": [
{
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions versa_system/versa_system/doctype/moc_design/moc_design.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
88 changes: 64 additions & 24 deletions versa_system/versa_system/doctype/moc_design/moc_design.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not push commented code

Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@


# import frappe
# from frappe.model.document import Document
# from frappe.model.mapper import get_mapped_doc

# class MOCDesign(Document):
# pass

# @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'
# """
# def set_missing_values(source, target):
# pass

# 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
# )

# return target_doc

import frappe
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
Expand All @@ -10,37 +54,33 @@ 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", [])

# Filter only those rows where 'feasible' is checked
filtered_materials = [row for row in source.get("feasible_material_details") if row.get("feasible")]

# Append only feasible items to the target document
for row in filtered_materials:
target.append("moc_design", {
"material_type": row.material_type,
"product_items":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,
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

Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2025, efeone and contributors
// For license information, please see license.txt

frappe.query_reports["Sales Order Report"] = {
"filters": [

]
};
Loading