[fixes] calculate valuation rate for non stock item
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index cb8f4e6..3023a9f 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -880,7 +880,7 @@
},
set_gross_profit: function(item) {
- if (this.frm.doc.doctype == "Sales Order") {
+ if (this.frm.doc.doctype == "Sales Order" && item.valuation_rate) {
item.gross_profit = flt((((item.rate - item.valuation_rate) * item.qty) * (this.frm.doc.conversion_rate || 1)), precision("amount", item));
}
}
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index ef9cadc..05a5387 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -136,7 +136,7 @@
} else {
this.price_list_rate(doc, cdt, cdn);
}
- this.gross_profit(item);
+ this.set_gross_profit(item);
},
commission_rate: function() {
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 9b61c00..a98a25a 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -44,6 +44,8 @@
if out.get("warehouse"):
out.update(get_bin_details(args.item_code, out.warehouse))
+ else:
+ out.update(get_valuation_rate(args.item_code))
get_price_list_rate(args, item_doc, out)
@@ -167,8 +169,7 @@
"net_amount": 0.0,
"discount_percentage": 0.0,
"supplier": item.default_supplier,
- "delivered_by_supplier": item.delivered_by_supplier,
- "valuation_rate": get_bin_details(item.name, warehouse)
+ "delivered_by_supplier": item.delivered_by_supplier
})
# if default specified in item is for another company, fetch from company
@@ -359,7 +360,8 @@
@frappe.whitelist()
def get_bin_details(item_code, warehouse):
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse},
- ["projected_qty", "actual_qty", "valuation_rate"], as_dict=True) or {"projected_qty": 0, "actual_qty": 0}
+ ["projected_qty", "actual_qty", "valuation_rate"], as_dict=True) \
+ or {"projected_qty": 0, "actual_qty": 0, "valuation_rate": 0}
@frappe.whitelist()
def get_batch_qty(batch_no,warehouse,item_code):
@@ -469,11 +471,17 @@
else:
frappe.throw(_("No default BOM exists for Item {0}").format(item_code))
+def get_valuation_rate(item_code):
+ valuation_rate =frappe.db.sql("""select sum(base_net_amount) / sum(qty) from `tabPurchase Invoice Item`
+ where item_code = %s and docstatus=1""", item_code)
+
+ if valuation_rate:
+ return {"valuation_rate": valuation_rate[0][0]}
def get_gross_profit(out):
- if isinstance(out.valuation_rate, dict): return out
+ if out.valuation_rate:
+ out.update({
+ "gross_profit": ((out.base_rate - out.valuation_rate) * out.qty)
+ })
- out.update({
- "gross_profit": ((out.base_rate - out.valuation_rate) * out.qty)
- })
return out