[fixes] calculate valuation rate for non stock item
This commit is contained in:
parent
2d7af63351
commit
5ada14b887
@ -880,7 +880,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
set_gross_profit: function(item) {
|
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));
|
item.gross_profit = flt((((item.rate - item.valuation_rate) * item.qty) * (this.frm.doc.conversion_rate || 1)), precision("amount", item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
} else {
|
} else {
|
||||||
this.price_list_rate(doc, cdt, cdn);
|
this.price_list_rate(doc, cdt, cdn);
|
||||||
}
|
}
|
||||||
this.gross_profit(item);
|
this.set_gross_profit(item);
|
||||||
},
|
},
|
||||||
|
|
||||||
commission_rate: function() {
|
commission_rate: function() {
|
||||||
|
@ -44,6 +44,8 @@ def get_item_details(args):
|
|||||||
|
|
||||||
if out.get("warehouse"):
|
if out.get("warehouse"):
|
||||||
out.update(get_bin_details(args.item_code, out.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)
|
get_price_list_rate(args, item_doc, out)
|
||||||
|
|
||||||
@ -167,8 +169,7 @@ def get_basic_details(args, item):
|
|||||||
"net_amount": 0.0,
|
"net_amount": 0.0,
|
||||||
"discount_percentage": 0.0,
|
"discount_percentage": 0.0,
|
||||||
"supplier": item.default_supplier,
|
"supplier": item.default_supplier,
|
||||||
"delivered_by_supplier": item.delivered_by_supplier,
|
"delivered_by_supplier": item.delivered_by_supplier
|
||||||
"valuation_rate": get_bin_details(item.name, warehouse)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
# if default specified in item is for another company, fetch from company
|
# if default specified in item is for another company, fetch from company
|
||||||
@ -359,7 +360,8 @@ def get_projected_qty(item_code, warehouse):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_bin_details(item_code, warehouse):
|
def get_bin_details(item_code, warehouse):
|
||||||
return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": 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()
|
@frappe.whitelist()
|
||||||
def get_batch_qty(batch_no,warehouse,item_code):
|
def get_batch_qty(batch_no,warehouse,item_code):
|
||||||
@ -469,11 +471,17 @@ def get_default_bom(item_code=None):
|
|||||||
else:
|
else:
|
||||||
frappe.throw(_("No default BOM exists for Item {0}").format(item_code))
|
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):
|
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
|
return out
|
||||||
|
Loading…
x
Reference in New Issue
Block a user