Get valuation rate for fg item base don issued item cost + operation cost. #1688

This commit is contained in:
Nabin Hait 2014-05-29 19:48:41 +05:30
parent 7f03e24c55
commit c7253b3a37
3 changed files with 29 additions and 20 deletions

View File

@ -4,11 +4,11 @@
// On REFRESH
cur_frm.cscript.refresh = function(doc,dt,dn){
cur_frm.toggle_enable("item", doc.__islocal);
if (!doc.__islocal && doc.docstatus<2) {
cur_frm.add_custom_button(__("Update Cost"), cur_frm.cscript.update_cost);
}
cur_frm.cscript.with_operations(doc);
set_operation_no(doc);
}
@ -41,14 +41,14 @@ var set_operation_no = function(doc) {
var op = op_table[i].operation_no;
if (op && !inList(operations, op)) operations.push(op);
}
frappe.meta.get_docfield("BOM Item", "operation_no",
frappe.meta.get_docfield("BOM Item", "operation_no",
cur_frm.docname).options = operations.join("\n");
$.each(doc.bom_materials || [], function(i, v) {
if(!inList(operations, cstr(v.operation_no))) v.operation_no = null;
});
refresh_field("bom_materials");
}
@ -97,7 +97,7 @@ var get_bom_material_detail= function(doc, cdt, cdn) {
doc: cur_frm.doc,
method: "get_bom_material_detail",
args: {
'item_code': d.item_code,
'item_code': d.item_code,
'bom_no': d.bom_no != null ? d.bom_no: '',
'qty': d.qty
},
@ -131,7 +131,7 @@ cur_frm.cscript.rate = function(doc, cdt, cdn) {
}
}
var calculate_op_cost = function(doc) {
var calculate_op_cost = function(doc) {
var op = doc.bom_operations || [];
total_op_cost = 0;
for(var i=0;i<op.length;i++) {
@ -143,13 +143,13 @@ var calculate_op_cost = function(doc) {
refresh_field('operating_cost');
}
var calculate_rm_cost = function(doc) {
var calculate_rm_cost = function(doc) {
var rm = doc.bom_materials || [];
total_rm_cost = 0;
for(var i=0;i<rm.length;i++) {
amt = flt(rm[i].rate) * flt(rm[i].qty);
set_multiple('BOM Item',rm[i].name, {'amount': amt}, 'bom_materials');
set_multiple('BOM Item',rm[i].name,
set_multiple('BOM Item',rm[i].name,
{'qty_consumed_per_unit': flt(rm[i].qty)/flt(doc.quantity)}, 'bom_materials');
total_rm_cost += amt;
}
@ -196,7 +196,7 @@ cur_frm.fields_dict['bom_materials'].grid.get_field('bom_no').get_query = functi
'is_active': 1,
'docstatus': 1
}
}
}
}
cur_frm.cscript.validate = function(doc, dt, dn) {

View File

@ -175,6 +175,9 @@ class StockEntry(StockController):
def get_stock_and_rate(self):
"""get stock and incoming rate on posting date"""
raw_material_cost = 0.0
for d in self.get('mtn_details'):
args = frappe._dict({
"item_code": d.item_code,
@ -182,17 +185,27 @@ class StockEntry(StockController):
"posting_date": self.posting_date,
"posting_time": self.posting_time,
"qty": d.s_warehouse and -1*d.transfer_qty or d.transfer_qty,
"serial_no": d.serial_no,
"bom_no": d.bom_no,
"serial_no": d.serial_no
})
# get actual stock at source warehouse
d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0
# get incoming rate
if not flt(d.incoming_rate):
d.incoming_rate = self.get_incoming_rate(args)
if not d.bom_no:
if not flt(d.incoming_rate):
d.incoming_rate = self.get_incoming_rate(args)
d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
raw_material_cost += flt(d.amount)
# set incoming rate for fg item
if self.production_order and self.purpose == "Manufacture/Repack":
for d in self.get("mtn_details"):
if d.bom_no:
bom = frappe.db.get_value("BOM", d.bom_no, ["operating_cost", "quantity"], as_dict=1)
operation_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity)
d.incoming_rate = operation_cost_per_unit + (raw_material_cost / flt(d.transfer_qty))
d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
def get_incoming_rate(self, args):
incoming_rate = 0

View File

@ -68,10 +68,6 @@ def get_incoming_rate(args):
in_rate = 0
if args.get("serial_no"):
in_rate = get_avg_purchase_rate(args.get("serial_no"))
elif args.get("bom_no"):
result = frappe.db.sql("""select ifnull(total_cost, 0) / ifnull(quantity, 1)
from `tabBOM` where name = %s and docstatus=1 and is_active=1""", args.get("bom_no"))
in_rate = result and flt(result[0][0]) or 0
else:
valuation_method = get_valuation_method(args.get("item_code"))
previous_sle = get_previous_sle(args)