From c56f1a2930f7de8063c6d2e5967b906b73421b24 Mon Sep 17 00:00:00 2001 From: Casey Date: Mon, 23 Feb 2026 12:27:17 -0600 Subject: [PATCH] fixed estimate item price and view on save draft --- custom_ui/api/db/estimates.py | 1 + custom_ui/services/item_service.py | 23 +++++++++++++++++++++- frontend/src/components/pages/Estimate.vue | 10 ++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/custom_ui/api/db/estimates.py b/custom_ui/api/db/estimates.py index 36a5307..c8545c4 100644 --- a/custom_ui/api/db/estimates.py +++ b/custom_ui/api/db/estimates.py @@ -494,6 +494,7 @@ def upsert_estimate(data): frappe.db.commit() estimate_dict = estimate.as_dict() estimate_dict["history"] = get_doc_history("Quotation", estimate_name) + estimate_dict["items"] = [{**ItemService.get_full_dict(item.item_code), **item.as_dict()} for item in estimate.items] print(f"DEBUG: Estimate updated: {estimate.name}") return build_success_response(estimate_dict) diff --git a/custom_ui/services/item_service.py b/custom_ui/services/item_service.py index d6e10c3..0ccc2d9 100644 --- a/custom_ui/services/item_service.py +++ b/custom_ui/services/item_service.py @@ -80,7 +80,28 @@ class ItemService: "standard_rate", "stock_uom", "default_bom" ] ) - + + # For items with standard_rate=0, try to get price from Item Price (selling price list) + items_needing_price = [item["item_code"] for item in items if not item.get("standard_rate")] + if items_needing_price: + # Get the default selling price list + default_price_list = frappe.db.get_single_value("Selling Settings", "selling_price_list") + if default_price_list: + price_filters = { + "item_code": ["in", items_needing_price], + "price_list": default_price_list, + "selling": 1 + } + item_prices = frappe.get_all( + "Item Price", + filters=price_filters, + fields=["item_code", "price_list_rate"] + ) + price_map = {ip["item_code"]: ip["price_list_rate"] for ip in item_prices} + for item in items: + if not item.get("standard_rate") and item["item_code"] in price_map: + item["standard_rate"] = price_map[item["item_code"]] + # Get all item codes that have BOMs items_with_boms = [item for item in items if item.get("default_bom")] item_codes_with_boms = [item["item_code"] for item in items_with_boms] diff --git a/frontend/src/components/pages/Estimate.vue b/frontend/src/components/pages/Estimate.vue index 22a906e..3279910 100644 --- a/frontend/src/components/pages/Estimate.vue +++ b/frontend/src/components/pages/Estimate.vue @@ -1001,14 +1001,16 @@ watch( if (estimate.value.items && estimate.value.items.length > 0) { selectedItems.value = estimate.value.items.map(item => { - const fullItem = Object.values(quotationItems.value).flat().find(qi => qi.itemCode === item.itemCode); const discountPercentage = item.discountPercentage || item.discount_percentage || 0; const discountAmount = item.discountAmount || item.discount_amount || 0; return { - itemCode: item.itemCode, - itemName: item.itemName, + itemCode: item.itemCode || item.item_code, + itemName: item.itemName || item.item_name, qty: item.qty, - standardRate: item.rate || fullItem?.standardRate || 0, + rate: item.rate, + standardRate: item.rate, + bom: item.bom || null, + uom: item.uom || item.stockUom || item.stock_uom || 'Nos', discountAmount: discountAmount === 0 ? null : discountAmount, discountPercentage: discountPercentage === 0 ? null : discountPercentage, discountType: discountPercentage > 0 ? 'percentage' : 'currency'