Valuation rate of raw materials in BOM. #1688

This commit is contained in:
Nabin Hait 2014-05-29 18:53:09 +05:30
parent 66cecf4824
commit 7f03e24c55

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cint, cstr, flt, now, nowdate
from frappe.utils import cint, cstr, flt
from frappe import _
from frappe.model.document import Document
@ -132,26 +132,15 @@ class BOM(Document):
return bom and bom[0]['unit_cost'] or 0
def get_valuation_rate(self, args):
""" Get average valuation rate of relevant warehouses
as per valuation method (MAR/FIFO)
as on costing date
"""
from erpnext.stock.utils import get_incoming_rate
posting_date, posting_time = nowdate(), now().split()[1]
warehouse = frappe.db.sql("select warehouse from `tabBin` where item_code = %s", args['item_code'])
rate = []
for wh in warehouse:
r = get_incoming_rate({
"item_code": args.get("item_code"),
"warehouse": wh[0],
"posting_date": posting_date,
"posting_time": posting_time,
"qty": args.get("qty") or 0
})
if r:
rate.append(r)
""" Get weighted average of valuation rate from all warehouses """
return rate and flt(sum(rate))/len(rate) or 0
total_qty, total_value = 0, 0
for d in frappe.db.sql("""select actual_qty, stock_value from `tabBin`
where item_code=%s and actual_qty > 0""", args['item_code'], as_dict=1):
total_qty += flt(d.actual_qty)
total_value += flt(d.stock_value)
return total_value / total_qty
def manage_default_bom(self):
""" Uncheck others if current one is selected as default,