fixed estimate item price and view on save draft
This commit is contained in:
parent
ac0c02a299
commit
c56f1a2930
3 changed files with 29 additions and 5 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,27 @@ class ItemService:
|
|||
]
|
||||
)
|
||||
|
||||
# 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]
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue