diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index ce0cb50e20..ea1a2e3a42 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -120,50 +120,21 @@ frappe.ui.form.on('Payment Entry', {
set_dynamic_labels: function(frm) {
var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
- var field_label_map = {};
- var grid_field_label_map = {};
-
- var setup_field_label_map = function(fields_list, currency, parentfield) {
- var doctype = parentfield ? frm.fields_dict[parentfield].grid.doctype : frm.doc.doctype;
- $.each(fields_list, function(i, fname) {
- var docfield = frappe.meta.docfield_map[doctype][fname];
- if(docfield) {
- var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
- if(parentfield) {
- grid_field_label_map[doctype + "-" + fname] =
- label.trim() + " (" + __(currency) + ")";
- } else {
- field_label_map[fname] = label.trim() + " (" + currency + ")";
- }
- }
- });
- }
-
- setup_field_label_map(["base_paid_amount", "base_received_amount", "base_total_allocated_amount",
+ frm.set_currency_labels(["base_paid_amount", "base_received_amount", "base_total_allocated_amount",
"difference_amount"], company_currency);
- setup_field_label_map(["paid_amount"], frm.doc.paid_from_account_currency);
- setup_field_label_map(["received_amount"], frm.doc.paid_to_account_currency);
+ frm.set_currency_labels(["paid_amount"], frm.doc.paid_from_account_currency);
+ frm.set_currency_labels(["received_amount"], frm.doc.paid_to_account_currency);
var party_account_currency = frm.doc.payment_type=="Receive" ?
frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency;
- setup_field_label_map(["total_allocated_amount", "unallocated_amount"], party_account_currency);
+ frm.set_currency_labels(["total_allocated_amount", "unallocated_amount"], party_account_currency);
- $.each(field_label_map, function(fname, label) {
- me.frm.fields_dict[fname].set_label(label);
- });
-
- setup_field_label_map(["total_amount", "outstanding_amount", "allocated_amount"],
+ frm.set_currency_labels(["total_amount", "outstanding_amount", "allocated_amount"],
party_account_currency, "references");
- setup_field_label_map(["amount"], company_currency, "deductions");
-
- $.each(grid_field_label_map, function(fname, label) {
- fname = fname.split("-");
- var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
- if(df) df.label = label;
- });
+ frm.set_currency_labels(["amount"], company_currency, "deductions");
cur_frm.set_df_property("source_exchange_rate", "description",
("1 " + frm.doc.paid_from_account_currency + " = [?] " + company_currency));
diff --git a/erpnext/docs/assets/img/manufacturing/price-list-based-currency-bom.png b/erpnext/docs/assets/img/manufacturing/price-list-based-currency-bom.png
new file mode 100644
index 0000000000..c8eca6a3cf
Binary files /dev/null and b/erpnext/docs/assets/img/manufacturing/price-list-based-currency-bom.png differ
diff --git a/erpnext/docs/user/manual/en/manufacturing/bill-of-materials.md b/erpnext/docs/user/manual/en/manufacturing/bill-of-materials.md
index 34d853064d..91bf7edf45 100644
--- a/erpnext/docs/user/manual/en/manufacturing/bill-of-materials.md
+++ b/erpnext/docs/user/manual/en/manufacturing/bill-of-materials.md
@@ -31,6 +31,11 @@ To make a new BOM:
+* User can select the currency in the BOM
+* System calculates the costing based on the price list currency
+
+
+
### Materials Required(exploded)
This table lists down all the Material required for the Item to be Manufactured.
diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js
index ce4c4cbce8..5181cf48a5 100644
--- a/erpnext/manufacturing/doctype/bom/bom.js
+++ b/erpnext/manufacturing/doctype/bom/bom.js
@@ -4,9 +4,19 @@
frappe.provide("erpnext.bom");
frappe.ui.form.on("BOM", {
+ setup: function(frm) {
+ frm.add_fetch('buying_price_list', 'currency', 'currency')
+ frm.fields_dict["items"].grid.get_field("bom_no").get_query = function(doc, cdt, cdn){
+ return {
+ filters: {'currency': frm.doc.currency}
+ }
+ }
+ },
+
onload_post_render: function(frm) {
frm.get_field("items").grid.set_multiple_add("item_code", "qty");
},
+
refresh: function(frm) {
frm.toggle_enable("item", frm.doc.__islocal);
toggle_operations(frm);
@@ -31,6 +41,7 @@ frappe.ui.form.on("BOM", {
});
}
},
+
update_cost: function(frm) {
return frappe.call({
doc: frm.doc,
@@ -43,6 +54,28 @@ frappe.ui.form.on("BOM", {
}
});
+erpnext.bom.BomController = erpnext.TransactionController.extend({
+ conversion_rate: function(doc, cdt, cdn) {
+ if(this.frm.doc.currency === this.get_company_currency()) {
+ this.frm.set_value("conversion_rate", 1.0);
+ } else {
+ erpnext.bom.update_cost(doc);
+ }
+ },
+
+ item_code: function(doc, cdt, cdn){
+ var scrap_items = false;
+ child = locals[cdt][cdn];
+ if(child.doctype == 'BOM Scrap Item') {
+ scrap_items = true;
+ }
+
+ get_bom_material_detail(doc, cdt, cdn, scrap_items);
+ },
+})
+
+$.extend(cur_frm.cscript, new erpnext.bom.BomController({frm: cur_frm}));
+
cur_frm.add_fetch("item", "description", "description");
cur_frm.add_fetch("item", "image", "image");
cur_frm.add_fetch("item", "item_name", "item_name");
@@ -56,19 +89,15 @@ cur_frm.cscript.hour_rate = function(doc, dt, dn) {
cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate;
-cur_frm.cscript.item_code = function(doc, cdt, cdn) {
- get_bom_material_detail(doc, cdt, cdn);
-}
-
cur_frm.cscript.bom_no = function(doc, cdt, cdn) {
- get_bom_material_detail(doc, cdt, cdn);
+ get_bom_material_detail(doc, cdt, cdn, false);
}
cur_frm.cscript.is_default = function(doc) {
if (doc.is_default) cur_frm.set_value("is_active", 1);
}
-var get_bom_material_detail= function(doc, cdt, cdn) {
+var get_bom_material_detail= function(doc, cdt, cdn, scrap_items) {
var d = locals[cdt][cdn];
if (d.item_code) {
return frappe.call({
@@ -77,6 +106,7 @@ var get_bom_material_detail= function(doc, cdt, cdn) {
args: {
'item_code': d.item_code,
'bom_no': d.bom_no != null ? d.bom_no: '',
+ "scrap_items": scrap_items,
'qty': d.qty
},
callback: function(r) {
@@ -96,60 +126,99 @@ var get_bom_material_detail= function(doc, cdt, cdn) {
cur_frm.cscript.qty = function(doc, cdt, cdn) {
erpnext.bom.calculate_rm_cost(doc);
+ erpnext.bom.calculate_scrap_materials_cost(doc);
erpnext.bom.calculate_total(doc);
}
cur_frm.cscript.rate = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
+ var scrap_items = false;
+
+ if(child.doctype == 'BOM Scrap Item') {
+ scrap_items = true;
+ }
+
if (d.bom_no) {
msgprint(__("You can not change rate if BOM mentioned agianst any item"));
- get_bom_material_detail(doc, cdt, cdn);
+ get_bom_material_detail(doc, cdt, cdn, scrap_items);
} else {
erpnext.bom.calculate_rm_cost(doc);
+ erpnext.bom.calculate_scrap_materials_cost(doc);
erpnext.bom.calculate_total(doc);
}
}
+erpnext.bom.update_cost = function(doc) {
+ erpnext.bom.calculate_op_cost(doc);
+ erpnext.bom.calculate_rm_cost(doc);
+ erpnext.bom.calculate_scrap_materials_cost(doc);
+ erpnext.bom.calculate_total(doc);
+}
+
erpnext.bom.calculate_op_cost = function(doc) {
var op = doc.operations || [];
doc.operating_cost = 0.0;
+ doc.base_operating_cost = 0.0;
+
for(var i=0;i