Merge pull request #24324 from marination/bom-rm-rate-company-based

fix: Company Wise Valuation Rate for RM in BOM
This commit is contained in:
rohitwaghchaure 2021-01-13 10:39:39 +05:30 committed by GitHub
commit 1c362c81f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 10 deletions

View File

@ -411,7 +411,7 @@ cur_frm.cscript.hour_rate = function(doc) {
cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate; cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate;
cur_frm.cscript.bom_no = function(doc, cdt, cdn) { cur_frm.cscript.bom_no = function(doc, cdt, cdn) {
get_bom_material_detail(doc, cdt, cdn, false); get_bom_material_detail(doc, cdt, cdn, false);
}; };
@ -419,17 +419,22 @@ cur_frm.cscript.is_default = function(doc) {
if (doc.is_default) cur_frm.set_value("is_active", 1); if (doc.is_default) cur_frm.set_value("is_active", 1);
}; };
var get_bom_material_detail= function(doc, cdt, cdn, scrap_items) { var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) {
if (!doc.company) {
frappe.throw({message: __("Please select a Company first."), title: __("Mandatory")});
}
var d = locals[cdt][cdn]; var d = locals[cdt][cdn];
if (d.item_code) { if (d.item_code) {
return frappe.call({ return frappe.call({
doc: doc, doc: doc,
method: "get_bom_material_detail", method: "get_bom_material_detail",
args: { args: {
'item_code': d.item_code, "company": doc.company,
'bom_no': d.bom_no != null ? d.bom_no: '', "item_code": d.item_code,
"bom_no": d.bom_no != null ? d.bom_no: '',
"scrap_items": scrap_items, "scrap_items": scrap_items,
'qty': d.qty, "qty": d.qty,
"stock_qty": d.stock_qty, "stock_qty": d.stock_qty,
"include_item_in_manufacturing": d.include_item_in_manufacturing, "include_item_in_manufacturing": d.include_item_in_manufacturing,
"uom": d.uom, "uom": d.uom,
@ -468,7 +473,7 @@ cur_frm.cscript.rate = function(doc, cdt, cdn) {
} }
if (d.bom_no) { if (d.bom_no) {
frappe.msgprint(__("You can not change rate if BOM mentioned agianst any item")); frappe.msgprint(__("You cannot change the rate if BOM is mentioned against any Item."));
get_bom_material_detail(doc, cdt, cdn, scrap_items); get_bom_material_detail(doc, cdt, cdn, scrap_items);
} else { } else {
erpnext.bom.calculate_rm_cost(doc); erpnext.bom.calculate_rm_cost(doc);

View File

@ -65,6 +65,10 @@ class BOM(WebsiteGenerator):
def validate(self): def validate(self):
self.route = frappe.scrub(self.name).replace('_', '-') self.route = frappe.scrub(self.name).replace('_', '-')
if not self.company:
frappe.throw(_("Please select a Company first."), title=_("Mandatory"))
self.clear_operations() self.clear_operations()
self.validate_main_item() self.validate_main_item()
self.validate_currency() self.validate_currency()
@ -125,6 +129,7 @@ class BOM(WebsiteGenerator):
self.validate_bom_currecny(item) self.validate_bom_currecny(item)
ret = self.get_bom_material_detail({ ret = self.get_bom_material_detail({
"company": self.company,
"item_code": item.item_code, "item_code": item.item_code,
"item_name": item.item_name, "item_name": item.item_name,
"bom_no": item.bom_no, "bom_no": item.bom_no,
@ -213,6 +218,7 @@ class BOM(WebsiteGenerator):
for d in self.get("items"): for d in self.get("items"):
rate = self.get_rm_rate({ rate = self.get_rm_rate({
"company": self.company,
"item_code": d.item_code, "item_code": d.item_code,
"bom_no": d.bom_no, "bom_no": d.bom_no,
"qty": d.qty, "qty": d.qty,
@ -611,10 +617,20 @@ def get_valuation_rate(args):
""" Get weighted average of valuation rate from all warehouses """ """ Get weighted average of valuation rate from all warehouses """
total_qty, total_value, valuation_rate = 0.0, 0.0, 0.0 total_qty, total_value, valuation_rate = 0.0, 0.0, 0.0
for d in frappe.db.sql("""select actual_qty, stock_value from `tabBin` item_bins = frappe.db.sql("""
where item_code=%s""", args['item_code'], as_dict=1): select
total_qty += flt(d.actual_qty) bin.actual_qty, bin.stock_value
total_value += flt(d.stock_value) from
`tabBin` bin, `tabWarehouse` warehouse
where
bin.item_code=%(item)s
and bin.warehouse = warehouse.name
and warehouse.company=%(company)s""",
{"item": args['item_code'], "company": args['company']}, as_dict=1)
for d in item_bins:
total_qty += flt(d.actual_qty)
total_value += flt(d.stock_value)
if total_qty: if total_qty:
valuation_rate = total_value / total_qty valuation_rate = total_value / total_qty

View File

@ -725,6 +725,7 @@ def add_variant_item(variant_items, wo_doc, bom_no, table_name="items"):
args.update(item_data) args.update(item_data)
args["rate"] = get_bom_item_rate({ args["rate"] = get_bom_item_rate({
"company": wo_doc.company,
"item_code": args.get("item_code"), "item_code": args.get("item_code"),
"qty": args.get("required_qty"), "qty": args.get("required_qty"),
"uom": args.get("stock_uom"), "uom": args.get("stock_uom"),