Merge pull request #973 from fogueri/master

[docs] Customize links added
diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js
index c68b991..043fe90 100644
--- a/accounts/doctype/sales_invoice/pos.js
+++ b/accounts/doctype/sales_invoice/pos.js
@@ -167,7 +167,7 @@
 				"fieldtype": "Data",
 				"label": "Barcode",
 				"fieldname": "pos_barcode",
-				"placeholder": "Barcode"
+				"placeholder": "Barcode / Serial No"
 			},
 			parent: this.wrapper.find(".barcode-area")
 		});
@@ -228,7 +228,7 @@
 			}
 		});
 	},
-	add_to_cart: function(item_code) {
+	add_to_cart: function(item_code, serial_no) {
 		var me = this;
 		var caught = false;
 
@@ -239,39 +239,46 @@
 		if (no_of_items != 0) {
 			$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, 
 				this.frm.cscript.fname,	this.frm.doctype), function(i, d) {
-				if (d.item_code == item_code)
+				if (d.item_code == item_code) {
 					caught = true;
+					if (serial_no) {
+						d.serial_no += '\n' + serial_no;
+						me.frm.script_manager.trigger("serial_no", d.doctype, d.name);
+					}
+					else {
+						d.qty += 1;
+						me.frm.script_manager.trigger("qty", d.doctype, d.name);
+					}
+				}
 			});
 		}
 		
-		// if duplicate row then append the qty
-		if (caught) {
-			me.update_qty(item_code, 1);
-		}
-		else {
+		// if item not found then add new item
+		if (!caught) {
 			var child = wn.model.add_child(me.frm.doc, this.frm.doctype + " Item", 
 				this.frm.cscript.fname);
 			child.item_code = item_code;
-			me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name);
+
+			if (serial_no)
+				child.serial_no = serial_no;
+
+			me.frm.script_manager.trigger("item_code", child.doctype, child.name);
 		}
+		me.refresh();
 	},
-	update_qty: function(item_code, qty, textbox_qty) {
+	update_qty: function(item_code, qty) {
 		var me = this;
 		$.each(wn.model.get_children(this.frm.doctype + " Item", this.frm.doc.name, 
 			this.frm.cscript.fname, this.frm.doctype), function(i, d) {
 			if (d.item_code == item_code) {
-				if (textbox_qty) {
-					if (qty == 0 && d.item_code == item_code)
-						wn.model.clear_doc(d.doctype, d.name);
+				if (qty == 0)
+					wn.model.clear_doc(d.doctype, d.name);
+				else {
 					d.qty = qty;
+					me.frm.script_manager.trigger("qty", d.doctype, d.name);
 				}
-				else
-					d.qty += 1;
-
-				me.frm.cscript.qty(me.frm.doc, d.doctype, d.name);
 			}
 		});
-		me.frm.dirty();
 		me.refresh();
 	},
 	refresh: function() {
@@ -352,7 +359,7 @@
 			// append quantity to the respective item after change from input box
 			$(this.wrapper).find("input.qty").on("change", function() {
 				var item_code = $(this).closest("tr")[0].id;
-				me.update_qty(item_code, $(this).val(), true);
+				me.update_qty(item_code, $(this).val());
 			});
 
 			// on td click toggle the highlighting of row
@@ -407,11 +414,14 @@
 		var me = this;
 		me.barcode_timeout = null;
 		wn.call({
-			method: 'accounts.doctype.sales_invoice.pos.get_item_from_barcode',
-			args: {barcode: this.barcode.$input.val()},
+			method: 'accounts.doctype.sales_invoice.pos.get_item_code',
+			args: {barcode_serial_no: this.barcode.$input.val()},
 			callback: function(r) {
 				if (r.message) {
-					me.add_to_cart(r.message[0].name);
+					if (r.message[1] == "serial_no")
+						me.add_to_cart(r.message[0][0].item_code, r.message[0][0].name);
+					else
+						me.add_to_cart(r.message[0][0].name);
 				}
 				else
 					msgprint(wn._("Invalid Barcode"));
@@ -443,7 +453,6 @@
 		});
 		this.frm.fields_dict[this.frm.cscript.fname].grid.refresh();
 		this.frm.script_manager.trigger("calculate_taxes_and_totals");
-		me.frm.dirty();
 		me.refresh();
 	},
 	make_payment: function() {
diff --git a/accounts/doctype/sales_invoice/pos.py b/accounts/doctype/sales_invoice/pos.py
index 44fe40d..7bebbd2 100644
--- a/accounts/doctype/sales_invoice/pos.py
+++ b/accounts/doctype/sales_invoice/pos.py
@@ -20,25 +20,30 @@
 		condition += " and i.name='%s'" % item
 
 	return webnotes.conn.sql("""select i.name, i.item_name, i.image, 
-		pl_items.ref_rate, pl_items.currency 
+		item_det.ref_rate, item_det.currency 
 		from `tabItem` i LEFT JOIN 
-			(select ip.item_code, ip.ref_rate, pl.currency from 
-				`tabItem Price` ip, `tabPrice List` pl 
-				where ip.parent=%s and ip.parent = pl.name) pl_items
+			(select item_code, ref_rate, currency from 
+				`tabItem Price`	where price_list=%s) item_det
 		ON
-			pl_items.item_code=i.name
+			item_det.item_code=i.name
 		where
 			%s""" % ('%s', condition), (price_list), as_dict=1)
 
 @webnotes.whitelist()
-def get_item_from_barcode(barcode):
-	return webnotes.conn.sql("""select name from `tabItem` where barcode=%s""",
-		(barcode), as_dict=1)
+def get_item_code(barcode_serial_no):
+	input_via = "serial_no"
+	item_code = webnotes.conn.sql("""select name, item_code from `tabSerial No` where 
+		name=%s""", (barcode_serial_no), as_dict=1)
 
-@webnotes.whitelist()
-def get_item_from_serial_no(serial_no):
-	return webnotes.conn.sql("""select name, item_code from `tabSerial No` where 
-		name=%s""", (serial_no), as_dict=1)
+	if not item_code:
+		input_via = "barcode"
+		item_code = webnotes.conn.sql("""select name from `tabItem` where barcode=%s""",
+			(barcode_serial_no), as_dict=1)
+
+	if item_code:
+		return item_code, input_via
+	else:
+		webnotes.throw("Invalid Barcode / Serial No")
 
 @webnotes.whitelist()
 def get_mode_of_payment():
diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js
index 8192fe5..b5c1646 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -18,21 +18,21 @@
 erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({
 	onload: function() {
 		this._super();
-		
-		if(!this.frm.doc.__islocal) {
+
+		if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
 			// show debit_to in print format
-			if(!this.frm.doc.customer && this.frm.doc.debit_to) {
-				this.frm.set_df_property("debit_to", "print_hide", 0);
-			}
+			this.frm.set_df_property("debit_to", "print_hide", 0);
 		}
 		
 		// toggle to pos view if is_pos is 1 in user_defaults
-		if ((cint(wn.defaults.get_user_defaults("is_pos"))===1 || cur_frm.doc.is_pos) && 
-				cint(wn.defaults.get_user_defaults("fs_pos_view"))===1) {
-					if(this.frm.doc.__islocal && !this.frm.doc.amended_from && !this.frm.doc.customer) {
-						this.frm.set_value("is_pos", 1);
-						this.is_pos(function() {cur_frm.cscript.toggle_pos(true);});
-					}
+		if ((cint(wn.defaults.get_user_defaults("is_pos"))===1 || cur_frm.doc.is_pos)) {
+			if(this.frm.doc.__islocal && !this.frm.doc.amended_from && !this.frm.doc.customer) {
+				this.frm.set_value("is_pos", 1);
+				this.is_pos(function() {
+					if (cint(wn.defaults.get_user_defaults("fs_pos_view"))===1)
+						cur_frm.cscript.toggle_pos(true);
+				});
+			}
 		}
 		
 		// if document is POS then change default print format to "POS Invoice"
@@ -44,7 +44,7 @@
 	
 	refresh: function(doc, dt, dn) {
 		this._super();
-		
+
 		cur_frm.cscript.is_opening(doc, dt, dn);
 		cur_frm.dashboard.reset();
 
@@ -141,6 +141,10 @@
 					callback: function(r) {
 						if(!r.exc) {
 							me.frm.script_manager.trigger("update_stock");
+							me.set_default_values();
+							me.set_dynamic_labels();
+							me.calculate_taxes_and_totals();
+
 							if(callback_fn) callback_fn()
 						}
 					}
diff --git a/accounts/general_ledger.py b/accounts/general_ledger.py
index 995fdc0..b0c585a 100644
--- a/accounts/general_ledger.py
+++ b/accounts/general_ledger.py
@@ -30,8 +30,12 @@
 		entry.credit = flt(entry.credit, 2)
 	
 		# toggle debit, credit if negative entry
-		if flt(entry.debit) < 0 or flt(entry.credit) < 0:
-			entry.debit, entry.credit = abs(flt(entry.credit)), abs(flt(entry.debit))
+		if flt(entry.debit) < 0:
+			entry.credit = flt(entry.credit) - flt(entry.debit)
+			entry.debit = 0.0
+		if flt(entry.credit) < 0:
+			entry.debit = flt(entry.debit) - flt(entry.credit)
+			entry.credit = 0.0
 
 	return gl_map
 		
diff --git a/buying/page/buying_home/buying_home.js b/buying/page/buying_home/buying_home.js
index eec0725..b6de994 100644
--- a/buying/page/buying_home/buying_home.js
+++ b/buying/page/buying_home/buying_home.js
@@ -67,10 +67,15 @@
 			},
 			{
 				label: wn._("Price List"),
-				description: wn._("Mupltiple Item prices."),
+				description: wn._("Multiple Price list."),
 				doctype:"Price List"
 			},
 			{
+				label: wn._("Item Price"),
+				description: wn._("Multiple Item prices."),
+				doctype:"Item Price"
+			},
+			{
 				"doctype":"Supplier Type",
 				"label": wn._("Supplier Type"),
 				"description": wn._("Supplier classification.")
diff --git a/buying/utils.py b/buying/utils.py
index 115b023..385a8c7 100644
--- a/buying/utils.py
+++ b/buying/utils.py
@@ -89,10 +89,9 @@
 	
 	# try fetching from price list
 	if args.buying_price_list and args.price_list_currency:
-		price_list_rate = webnotes.conn.sql("""select ip.ref_rate from `tabItem Price` ip, 
-		`tabPrice List` pl where ip.parent = pl.name and ip.parent=%s and 
-		ip.item_code=%s and pl.buying_or_selling='Buying'""", 
-		(args.buying_price_list, args.item_code), as_dict=1)
+		price_list_rate = webnotes.conn.sql("""select ref_rate from `tabItem Price` 
+			where price_list=%s and item_code=%s and buying_or_selling='Buying'""", 
+			(args.buying_price_list, args.item_code), as_dict=1)
 		
 		if price_list_rate:
 			from utilities.transaction_base import validate_currency
diff --git a/controllers/stock_controller.py b/controllers/stock_controller.py
index d4c92a9..359dc9e 100644
--- a/controllers/stock_controller.py
+++ b/controllers/stock_controller.py
@@ -12,18 +12,17 @@
 
 class StockController(AccountsController):
 	def make_gl_entries(self):
-		if not cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
-			return
-		
-		warehouse_account = self.get_warehouse_account()
-		
-		if self.doc.docstatus==1:
-			gl_entries = self.get_gl_entries_for_stock(warehouse_account)
-			make_gl_entries(gl_entries)
-		else:	
+		if self.doc.docstatus == 2:
 			delete_gl_entries(voucher_type=self.doc.doctype, voucher_no=self.doc.name)
+			
+		if cint(webnotes.defaults.get_global_default("auto_accounting_for_stock")):
+			warehouse_account = self.get_warehouse_account()
 		
-		self.update_gl_entries_after(warehouse_account)
+			if self.doc.docstatus==1:
+				gl_entries = self.get_gl_entries_for_stock(warehouse_account)
+				make_gl_entries(gl_entries)
+
+			self.update_gl_entries_after(warehouse_account)
 	
 	def get_gl_entries_for_stock(self, warehouse_account=None, default_expense_account=None,
 			default_cost_center=None):
@@ -91,15 +90,11 @@
 		return stock_ledger
 		
 	def get_warehouse_account(self):
-		for d in webnotes.conn.sql("select name from tabWarehouse"):
-			webnotes.bean("Warehouse", d[0]).save()
-
 		warehouse_account = dict(webnotes.conn.sql("""select master_name, name from tabAccount 
 			where account_type = 'Warehouse' and ifnull(master_name, '') != ''"""))
 		return warehouse_account
 		
 	def update_gl_entries_after(self, warehouse_account=None):
-		from accounts.utils import get_stock_and_account_difference
 		future_stock_vouchers = self.get_future_stock_vouchers()
 		gle = self.get_voucherwise_gl_entries(future_stock_vouchers)
 		if not warehouse_account:
diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py
index 9a56612..c3dd724 100644
--- a/manufacturing/doctype/bom/bom.py
+++ b/manufacturing/doctype/bom/bom.py
@@ -121,7 +121,7 @@
 			elif self.doc.rm_cost_as_per == "Price List":
 				if not self.doc.buying_price_list:
 					webnotes.throw(_("Please select Price List"))
-				rate = webnotes.conn.get_value("Item Price", {"parent": self.doc.buying_price_list, 
+				rate = webnotes.conn.get_value("Item Price", {"price_list": self.doc.buying_price_list, 
 					"item_code": arg["item_code"]}, "ref_rate") or 0
 			elif self.doc.rm_cost_as_per == 'Standard Rate':
 				rate = arg['standard_rate']
diff --git a/patches/march_2013/p06_remove_sales_purchase_return_tool.py b/patches/march_2013/p06_remove_sales_purchase_return_tool.py
index ed8fbc8..ac11ecc 100644
--- a/patches/march_2013/p06_remove_sales_purchase_return_tool.py
+++ b/patches/march_2013/p06_remove_sales_purchase_return_tool.py
@@ -4,5 +4,7 @@
 import webnotes
 
 def execute():
-	webnotes.delete_doc("DocType", "Sales and Purchase Return Item")
-	webnotes.delete_doc("DocType", "Sales and Purchase Return Tool")
\ No newline at end of file
+	if webnotes.conn.exists("DocType", "Sales and Purchase Return Item"):
+		webnotes.delete_doc("DocType", "Sales and Purchase Return Item")
+	if webnotes.conn.exists("DocType", "Sales and Purchase Return Tool"):
+		webnotes.delete_doc("DocType", "Sales and Purchase Return Tool")
\ No newline at end of file
diff --git a/patches/october_2012/fix_cancelled_gl_entries.py b/patches/october_2012/fix_cancelled_gl_entries.py
index b610985..475ea1c 100644
--- a/patches/october_2012/fix_cancelled_gl_entries.py
+++ b/patches/october_2012/fix_cancelled_gl_entries.py
@@ -11,6 +11,7 @@
 				and docstatus=2""" % (entry['voucher_type'], "%s"), entry['voucher_no'])
 			is_cancelled = docstatus and 'Yes' or None
 			if is_cancelled:
+				print entry['voucher_type'], entry['voucher_no']
 				webnotes.conn.sql("""update `tabGL Entry` set is_cancelled = 'Yes'
 					where voucher_type = %s and voucher_no = %s""", 
 					(entry['voucher_type'], entry['voucher_no']))
diff --git a/patches/october_2013/p02_update_price_list_and_item_details_in_item_price.py b/patches/october_2013/p02_update_price_list_and_item_details_in_item_price.py
new file mode 100644
index 0000000..209ebf3
--- /dev/null
+++ b/patches/october_2013/p02_update_price_list_and_item_details_in_item_price.py
@@ -0,0 +1,20 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	webnotes.reload_doc("setup", "doctype", "item_price")
+
+	webnotes.conn.sql("""update `tabItem Price` ip, `tabItem` i 
+		set ip.item_name=i.item_name, ip.item_description=i.description 
+		where ip.item_code=i.name""")
+
+	webnotes.conn.sql("""update `tabItem Price` ip, `tabPrice List` pl 
+		set ip.price_list=pl.name, ip.currency=pl.currency, 
+		ip.buying_or_selling=pl.buying_or_selling 
+		where ip.parent=pl.name""")
+
+	webnotes.conn.sql("""update `tabItem Price` 
+		set parent=null, parenttype=null, parentfield=null, idx=null""")
\ No newline at end of file
diff --git a/patches/october_2013/p03_remove_sales_and_purchase_return_tool.py b/patches/october_2013/p03_remove_sales_and_purchase_return_tool.py
new file mode 100644
index 0000000..e0965ab
--- /dev/null
+++ b/patches/october_2013/p03_remove_sales_and_purchase_return_tool.py
@@ -0,0 +1,8 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+
+def execute():
+	from patches.march_2013 import p06_remove_sales_purchase_return_tool
+	p06_remove_sales_purchase_return_tool.execute()
\ No newline at end of file
diff --git a/patches/october_2013/p04_update_report_permission.py b/patches/october_2013/p04_update_report_permission.py
new file mode 100644
index 0000000..1a9f99d
--- /dev/null
+++ b/patches/october_2013/p04_update_report_permission.py
@@ -0,0 +1,9 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+import webnotes
+
+def execute():
+	webnotes.conn.sql("""update tabDocPerm set `create`=1 where
+		parent='Report'
+		and role in ('Administrator', 'Report Manager', 'System Manager')""")
\ No newline at end of file
diff --git a/patches/october_2013/p05_delete_gl_entries_for_cancelled_vouchers.py b/patches/october_2013/p05_delete_gl_entries_for_cancelled_vouchers.py
new file mode 100644
index 0000000..1d8657a
--- /dev/null
+++ b/patches/october_2013/p05_delete_gl_entries_for_cancelled_vouchers.py
@@ -0,0 +1,16 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+def execute():
+	import webnotes
+	entries = webnotes.conn.sql("""select voucher_type, voucher_no 
+		from `tabGL Entry` group by voucher_type, voucher_no""", as_dict=1)
+	for entry in entries:
+		try:
+			cancelled_voucher = webnotes.conn.sql("""select name from `tab%s` where name = %s
+				and docstatus=2""" % (entry['voucher_type'], "%s"), entry['voucher_no'])
+			if cancelled_voucher:
+				webnotes.conn.sql("""delete from `tabGL Entry` where voucher_type = %s and 
+					voucher_no = %s""", (entry['voucher_type'], entry['voucher_no']))
+		except:
+			pass
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 59e0b0c..565ff99 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -222,4 +222,9 @@
 	"patches.october_2013.fix_is_cancelled_in_sle",
 	"patches.october_2013.repost_ordered_qty",
 	"patches.october_2013.repost_planned_qty",
+	"patches.october_2013.p02_update_price_list_and_item_details_in_item_price",
+	"execute:webnotes.delete_doc('Report', 'Item-wise Price List')",
+	"patches.october_2013.p03_remove_sales_and_purchase_return_tool",
+	"patches.october_2013.p04_update_report_permission",
+	"patches.october_2013.p05_delete_gl_entries_for_cancelled_vouchers",
 ]
\ No newline at end of file
diff --git a/public/js/transaction.js b/public/js/transaction.js
index 1c8f681..d52b742 100644
--- a/public/js/transaction.js
+++ b/public/js/transaction.js
@@ -39,7 +39,7 @@
 	onload_post_render: function() {
 		var me = this;
 		if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) {
-			if(!this.frm.doc.customer) {
+			if(!this.frm.doc.customer || !this.frm.doc.supplier) {
 				return this.frm.call({
 					doc: this.frm.doc,
 					method: "onload_post_render",
@@ -48,7 +48,7 @@
 						// remove this call when using client side mapper
 						me.set_default_values();
 						me.set_dynamic_labels();
-						me.calculate_taxes_and_totals()
+						me.calculate_taxes_and_totals();
 					}
 				});
 			} else {
@@ -114,6 +114,40 @@
 			this.frm.refresh();
 		}
 	},
+
+	serial_no: function(doc, cdt, cdn) {
+		var me = this;
+		var item = wn.model.get_doc(cdt, cdn);
+
+		if (item.serial_no) {
+			if (!item.item_code) {
+				this.frm.script_manager.trigger("item_code", cdt, cdn);
+			}
+			else {
+				var sr_no = [];
+
+				// Replacing all occurences of comma with carriage return
+				var serial_nos = item.serial_no.trim().replace(/,/g, '\n');
+
+				serial_nos = serial_nos.trim().split('\n');
+				
+				// Trim each string and push unique string to new list
+				for (var x=0; x<=serial_nos.length - 1; x++) {
+					if (serial_nos[x].trim() != "" && sr_no.indexOf(serial_nos[x].trim()) == -1) {
+						sr_no.push(serial_nos[x].trim());
+					}
+				}
+
+				// Add the new list to the serial no. field in grid with each in new line
+				item.serial_no = "";
+				for (var x=0; x<=sr_no.length - 1; x++)
+					item.serial_no += sr_no[x] + '\n';
+
+				refresh_field("serial_no", item.name, item.parentfield);
+				wn.model.set_value(item.doctype, item.name, "qty", sr_no.length);
+			}
+		}
+	},
 	
 	validate: function() {
 		this.calculate_taxes_and_totals();
@@ -171,7 +205,8 @@
 	conversion_rate: function() {
 		if(this.frm.doc.currency === this.get_company_currency()) {
 			this.frm.set_value("conversion_rate", 1.0);
-		} else if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
+		}
+		if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
 			this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) {
 				this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate);
 		}
diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js
index c87e823..8203af8 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -160,7 +160,7 @@
 	item_code: function(doc, cdt, cdn) {
 		var me = this;
 		var item = wn.model.get_doc(cdt, cdn);
-		if(item.item_code || item.barcode) {
+		if(item.item_code || item.barcode || item.serial_no) {
 			if(!this.validate_company_and_party("customer")) {
 				cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove();
 			} else {
@@ -171,6 +171,7 @@
 						args: {
 							item_code: item.item_code,
 							barcode: item.barcode,
+							serial_no: item.serial_no,
 							warehouse: item.warehouse,
 							doctype: me.frm.doc.doctype,
 							parentfield: item.parentfield,
diff --git a/selling/page/selling_home/selling_home.js b/selling/page/selling_home/selling_home.js
index 9697ccf..4981ee7 100644
--- a/selling/page/selling_home/selling_home.js
+++ b/selling/page/selling_home/selling_home.js
@@ -83,10 +83,15 @@
 			},
 			{
 				label: wn._("Price List"),
-				description: wn._("Mupltiple Item prices."),
+				description: wn._("Multiple Price list."),
 				doctype:"Price List"
 			},
 			{
+				label: wn._("Item Price"),
+				description: wn._("Multiple Item prices."),
+				doctype:"Item Price"
+			},
+			{
 				label: wn._("Sales BOM"),
 				description: wn._("Bundle items at time of sale."),
 				doctype:"Sales BOM"
@@ -163,6 +168,11 @@
 		icon: "icon-list",
 		items: [
 			{
+				"label":wn._("Lead Details"),
+				route: "query-report/Lead Details",
+				doctype: "Lead"
+			},
+			{
 				"label":wn._("Customer Addresses And Contacts"),
 				route: "query-report/Customer Addresses And Contacts",
 				doctype: "Contact"
diff --git a/setup/report/item_wise_price_list/__init__.py b/selling/report/lead_details/__init__.py
similarity index 100%
rename from setup/report/item_wise_price_list/__init__.py
rename to selling/report/lead_details/__init__.py
diff --git a/selling/report/lead_details/lead_details.txt b/selling/report/lead_details/lead_details.txt
new file mode 100644
index 0000000..6da9b79
--- /dev/null
+++ b/selling/report/lead_details/lead_details.txt
@@ -0,0 +1,22 @@
+[
+ {
+  "creation": "2013-10-22 11:58:16", 
+  "docstatus": 0, 
+  "modified": "2013-10-22 12:08:18", 
+  "modified_by": "Administrator", 
+  "owner": "Administrator"
+ }, 
+ {
+  "doctype": "Report", 
+  "is_standard": "Yes", 
+  "name": "__common__", 
+  "query": "SELECT\n    `tabLead`.name as \"Lead Id:Link/Lead:120\",\n    `tabLead`.lead_name as \"Lead Name::120\",\n\t`tabLead`.company_name as \"Company Name::120\",\n\t`tabLead`.status as \"Status::120\",\n\tconcat_ws(', ', \n\t\ttrim(',' from `tabAddress`.address_line1), \n\t\ttrim(',' from tabAddress.address_line2), \n\t\ttabAddress.state, tabAddress.pincode, tabAddress.country\n\t) as 'Address::180',\n\t`tabLead`.phone as \"Phone::100\",\n\t`tabLead`.mobile_no as \"Mobile No::100\",\n\t`tabLead`.email_id as \"Email Id::120\",\n\t`tabLead`.lead_owner as \"Lead Owner::120\",\n\t`tabLead`.source as \"Source::120\",\n\t`tabLead`.territory as \"Territory::120\"\nFROM\n\t`tabLead`\n\tleft join `tabAddress` on (\n\t\t`tabAddress`.lead=`tabLead`.name\n\t)\nWHERE\n\t`tabLead`.docstatus<2\nORDER BY\n\t`tabLead`.name asc", 
+  "ref_doctype": "Lead", 
+  "report_name": "Lead Details", 
+  "report_type": "Query Report"
+ }, 
+ {
+  "doctype": "Report", 
+  "name": "Lead Details"
+ }
+]
\ No newline at end of file
diff --git a/selling/utils/__init__.py b/selling/utils/__init__.py
index 6e74ac4..fd9c492 100644
--- a/selling/utils/__init__.py
+++ b/selling/utils/__init__.py
@@ -40,7 +40,9 @@
 	args = webnotes._dict(args)
 	
 	if args.barcode:
-		args.item_code = _get_item_code(args.barcode)
+		args.item_code = _get_item_code(barcode=args.barcode)
+	elif not args.item_code and args.serial_no:
+		args.item_code = _get_item_code(serial_no=args.serial_no)
 	
 	item_bean = webnotes.bean("Item", args.item_code)
 	
@@ -88,15 +90,17 @@
 			"qty": cint(args.qty)
 		}))
 
-def _get_item_code(barcode):
-	item_code = webnotes.conn.sql_list("""select name from `tabItem` where barcode=%s""", barcode)
+def _get_item_code(barcode=None, serial_no=None):
+	if barcode:
+		input_type = "Barcode"
+		item_code = webnotes.conn.sql_list("""select name from `tabItem` where barcode=%s""", barcode)
+	elif serial_no:
+		input_type = "Serial No"
+		item_code = webnotes.conn.sql_list("""select item_code from `tabSerial No` 
+			where name=%s""", serial_no)
 			
 	if not item_code:
-		msgprint(_("No Item found with Barcode") + ": %s" % barcode, raise_exception=True)
-	
-	elif len(item_code) > 1:
-		msgprint(_("Items") + " %s " % comma_and(item_code) + 
-			_("have the same Barcode") + " %s" % barcode, raise_exception=True)
+		msgprint(_("No Item found with ") + input_type + ": %s" % (barcode or serial_no), raise_exception=True)
 	
 	return item_code[0]
 	
@@ -142,9 +146,8 @@
 	return out
 	
 def _get_price_list_rate(args, item_bean, meta):
-	ref_rate = webnotes.conn.sql("""select ip.ref_rate from `tabItem Price` ip, 
-		`tabPrice List` pl where ip.parent = pl.name and ip.parent=%s and 
-		ip.item_code=%s and pl.buying_or_selling='Selling'""", 
+	ref_rate = webnotes.conn.sql("""select ref_rate from `tabItem Price` 
+		where price_list=%s and item_code=%s and buying_or_selling='Selling'""", 
 		(args.selling_price_list, args.item_code), as_dict=1)
 
 	if not ref_rate:
diff --git a/selling/utils/product.py b/selling/utils/product.py
index 3432170..df5f16d 100644
--- a/selling/utils/product.py
+++ b/selling/utils/product.py
@@ -27,9 +27,8 @@
 	else:
 		in_stock = -1
 		
-	price = price_list and webnotes.conn.sql("""select ip.ref_rate, pl.currency from
-		`tabItem Price` ip, `tabPrice List` pl where ip.parent = pl.name and 
-		ip.item_code=%s and ip.parent=%s""", 
+	price = price_list and webnotes.conn.sql("""select ref_rate, currency from
+		`tabItem Price` where item_code=%s and price_list=%s""", 
 		(item_code, price_list), as_dict=1) or []
 	
 	price = price and price[0] or None
diff --git a/setup/doctype/company/company.js b/setup/doctype/company/company.js
index ca3c93b..d023f8d 100644
--- a/setup/doctype/company/company.js
+++ b/setup/doctype/company/company.js
@@ -2,14 +2,53 @@
 // License: GNU General Public License v3. See license.txt
 
 cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	if(doc.abbr && !doc.__islocal)
-		cur_frm.set_df_property("abbr", "read_only", 1)
+	if(doc.abbr && !doc.__islocal) {
+		cur_frm.set_df_property("abbr", "read_only", 1);
+		if(in_list(user_roles, "System Manager"))
+			cur_frm.add_custom_button("Replace Abbreviation", cur_frm.cscript.replace_abbr)
+	}
 		
 	if(!doc.__islocal) {
 		cur_frm.toggle_enable("default_currency", !cur_frm.doc.__transactions_exist);
 	}
 }
 
+cur_frm.cscript.replace_abbr = function() {
+	var dialog = new wn.ui.Dialog({
+		title: "Replace Abbr",
+		fields: [
+			{"fieldtype": "Data", "label": "New Abbreviation", "fieldname": "new_abbr",
+				"reqd": 1 },
+			{"fieldtype": "Button", "label": "Update", "fieldname": "update"},
+		]
+	});
+
+	dialog.fields_dict.update.$input.click(function() {
+		args = dialog.get_values();
+		if(!args) return;
+		return wn.call({
+			method: "setup.doctype.company.company.replace_abbr",
+			args: {
+				"company": cur_frm.doc.name,
+				"old": cur_frm.doc.abbr,
+				"new": args.new_abbr
+			},
+			callback: function(r) {
+				if(r.exc) {
+					msgprint(wn._("There were errors."));
+					return;
+				} else {
+					cur_frm.set_value("abbr", args.new_abbr);
+				}
+				dialog.hide();
+				cur_frm.refresh();
+			},
+			btn: this
+		})
+	});
+	dialog.show();
+}
+
 cur_frm.cscript.has_special_chars = function(t) {
   var iChars = "!@#$%^*+=-[]\\\';,/{}|\":<>?";
   for (var i = 0; i < t.length; i++) {
diff --git a/setup/doctype/company/company.py b/setup/doctype/company/company.py
index 9746eb2..7da2310 100644
--- a/setup/doctype/company/company.py
+++ b/setup/doctype/company/company.py
@@ -5,9 +5,7 @@
 import webnotes
 from webnotes import _, msgprint
 
-from webnotes.utils import cstr, cint
-from webnotes.model.doc import Document
-from webnotes.model.code import get_obj
+from webnotes.utils import cstr
 import webnotes.defaults
 
 sql = webnotes.conn.sql
@@ -316,4 +314,19 @@
 			where doctype='Global Defaults' and field='default_company' 
 			and value=%s""", (newdn, olddn))
 		
-		webnotes.defaults.clear_default("company", value=olddn)
\ No newline at end of file
+		webnotes.defaults.clear_default("company", value=olddn)
+
+@webnotes.whitelist()
+def replace_abbr(company, old, new):
+	webnotes.conn.set_value("Company", company, "abbr", new)
+	
+	def _rename_record(dt):
+		for d in webnotes.conn.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company):
+			parts = d[0].split(" - ")
+			if parts[-1].lower() == old.lower():
+				name_without_abbr = " - ".join(parts[:-1])
+				webnotes.rename_doc(dt, d[0], name_without_abbr + " - " + new)
+		
+	for dt in ["Account", "Cost Center", "Warehouse"]:
+		_rename_record(dt)
+		webnotes.conn.commit()
\ No newline at end of file
diff --git a/setup/doctype/global_defaults/global_defaults.txt b/setup/doctype/global_defaults/global_defaults.txt
index fbfa8ca..a8a80b1 100644
--- a/setup/doctype/global_defaults/global_defaults.txt
+++ b/setup/doctype/global_defaults/global_defaults.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-02 17:53:24", 
   "docstatus": 0, 
-  "modified": "2013-08-06 11:22:22", 
+  "modified": "2013-10-23 10:22:44", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -176,13 +176,6 @@
   "read_only": 0
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "hr", 
-  "fieldtype": "Section Break", 
-  "label": "HR", 
-  "read_only": 0
- }, 
- {
   "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/setup/doctype/item_price/item_price.js b/setup/doctype/item_price/item_price.js
new file mode 100644
index 0000000..0a08c98
--- /dev/null
+++ b/setup/doctype/item_price/item_price.js
@@ -0,0 +1,16 @@
+// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+// License: GNU General Public License v3. See license.txt
+
+$.extend(cur_frm.cscript, {
+	
+	onload: function () {
+
+		// Fetch price list details
+		cur_frm.add_fetch("price_list", "buying_or_selling", "buying_or_selling");
+		cur_frm.add_fetch("price_list", "currency", "currency");
+
+		// Fetch item details
+		cur_frm.add_fetch("item_code", "item_name", "item_name");
+		cur_frm.add_fetch("item_code", "description", "item_description");
+	}
+});
\ No newline at end of file
diff --git a/setup/doctype/item_price/item_price.py b/setup/doctype/item_price/item_price.py
index 3256c80..ddde87e 100644
--- a/setup/doctype/item_price/item_price.py
+++ b/setup/doctype/item_price/item_price.py
@@ -5,7 +5,36 @@
 
 from __future__ import unicode_literals
 import webnotes
+from webnotes import _
+
+class ItemPriceDuplicateItem(Exception): pass
 
 class DocType:
 	def __init__(self, d, dl):
-		self.doc, self.doclist = d, dl
\ No newline at end of file
+		self.doc, self.doclist = d, dl
+
+	def on_update(self):
+		self.update_price_list_details()
+		self.update_item_details()
+		self.check_duplicate_item()
+
+	def update_price_list_details(self):
+		self.doc.buying_or_selling = webnotes.conn.get_value("Price List", self.doc.price_list, 
+			"buying_or_selling")
+
+		self.doc.currency = webnotes.conn.get_value("Price List", self.doc.price_list, 
+			"currency")
+
+	def update_item_details(self):
+		self.doc.item_name = webnotes.conn.get_value("Item", self.doc.item_code, "item_name")
+
+		self.doc.item_description = webnotes.conn.get_value("Item", self.doc.item_code, 
+			"description")
+
+	def check_duplicate_item(self):
+		if webnotes.conn.sql("""select name from `tabItem Price` 
+			where item_code=%s and price_list=%s and name!=%s""", 
+			(self.doc.item_code, self.doc.price_list, self.doc.name)):
+				webnotes.throw(_("Duplicate Item: ") + self.doc.item_code + 
+						_(" already available in Price List: ") + self.doc.price_list, 
+						ItemPriceDuplicateItem)
\ No newline at end of file
diff --git a/setup/doctype/item_price/item_price.txt b/setup/doctype/item_price/item_price.txt
index 4ff5124..779bbd4 100644
--- a/setup/doctype/item_price/item_price.txt
+++ b/setup/doctype/item_price/item_price.txt
@@ -2,29 +2,42 @@
  {
   "creation": "2013-05-02 16:29:48", 
   "docstatus": 0, 
-  "modified": "2013-09-13 11:50:02", 
+  "modified": "2013-10-21 15:11:20", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
   "autoname": "RFD/.#####", 
+  "description": "Multiple Item prices.", 
   "doctype": "DocType", 
+  "document_type": "Master", 
+  "icon": "icon-flag", 
   "in_create": 0, 
-  "istable": 1, 
+  "istable": 0, 
   "module": "Setup", 
   "name": "__common__", 
   "read_only": 0
  }, 
  {
   "doctype": "DocField", 
-  "in_filter": 1, 
-  "in_list_view": 1, 
   "name": "__common__", 
   "parent": "Item Price", 
   "parentfield": "fields", 
   "parenttype": "DocType", 
+  "permlevel": 0
+ }, 
+ {
+  "cancel": 1, 
+  "create": 1, 
+  "doctype": "DocPerm", 
+  "name": "__common__", 
+  "parent": "Item Price", 
+  "parentfield": "permissions", 
+  "parenttype": "DocType", 
   "permlevel": 0, 
-  "reqd": 1
+  "read": 1, 
+  "report": 1, 
+  "write": 1
  }, 
  {
   "doctype": "DocType", 
@@ -32,22 +45,83 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "price_list", 
+  "fieldtype": "Link", 
+  "in_filter": 1, 
+  "label": "Price List", 
+  "options": "Price List", 
+  "reqd": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "item_code", 
   "fieldtype": "Link", 
+  "in_filter": 1, 
+  "in_list_view": 1, 
   "label": "Item Code", 
   "oldfieldname": "price_list_name", 
   "oldfieldtype": "Select", 
   "options": "Item", 
+  "reqd": 1, 
   "search_index": 1
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "ref_rate", 
   "fieldtype": "Currency", 
+  "in_filter": 1, 
+  "in_list_view": 1, 
   "label": "Rate", 
   "oldfieldname": "ref_rate", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
+  "reqd": 1, 
   "search_index": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "col_br_1", 
+  "fieldtype": "Column Break"
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "buying_or_selling", 
+  "fieldtype": "Select", 
+  "in_filter": 1, 
+  "in_list_view": 1, 
+  "label": "Valid for Buying or Selling?", 
+  "options": "Selling\nBuying", 
+  "reqd": 0
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "item_name", 
+  "fieldtype": "Data", 
+  "label": "Item Name", 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "item_description", 
+  "fieldtype": "Text", 
+  "label": "Item Description", 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
+  "fieldname": "currency", 
+  "fieldtype": "Link", 
+  "hidden": 1, 
+  "label": "Currency", 
+  "options": "Currency", 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "Sales Master Manager"
+ }, 
+ {
+  "doctype": "DocPerm", 
+  "role": "Purchase Master Manager"
  }
 ]
\ No newline at end of file
diff --git a/setup/doctype/item_price/test_item_price.py b/setup/doctype/item_price/test_item_price.py
new file mode 100644
index 0000000..43694da
--- /dev/null
+++ b/setup/doctype/item_price/test_item_price.py
@@ -0,0 +1,23 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import unittest
+import webnotes
+from setup.doctype.item_price.item_price import ItemPriceDuplicateItem
+
+class TestItem(unittest.TestCase):
+	def test_duplicate_item(self):
+		item_price = webnotes.bean(copy=test_records[0])
+		self.assertRaises(ItemPriceDuplicateItem, item_price.insert)
+
+test_records = [
+	[
+		{
+			"doctype": "Item Price",
+			"price_list": "_Test Price List",
+			"item_code": "_Test Item",
+			"ref_rate": 100
+		}
+	]
+]
\ No newline at end of file
diff --git a/setup/doctype/price_list/price_list.js b/setup/doctype/price_list/price_list.js
index 67090bc..84c4c2f 100644
--- a/setup/doctype/price_list/price_list.js
+++ b/setup/doctype/price_list/price_list.js
@@ -5,253 +5,13 @@
 	onload: function() {
 		erpnext.add_for_territory();
 	},
-});
 
-cur_frm.cscript.refresh = function(doc, cdt, cdn) {
-	cur_frm.cscript.show_item_prices();
-}
-
-cur_frm.cscript.show_item_prices = function() {
-	var item_price = wn.model.get("Item Price", {parent: cur_frm.doc.name});
-	
-	$(cur_frm.fields_dict.item_prices_html.wrapper).empty();
-	
-	new wn.ui.form.TableGrid({
-		parent: cur_frm.fields_dict.item_prices_html.wrapper,
-		frm: cur_frm,
-		table_field: wn.meta.get_docfield("Price List", "item_prices", cur_frm.doc.name)
-	});
-}
-
-wn.ui.form.TableGrid = Class.extend({
-	init: function(opts) {
-		$.extend(this, opts);
-		this.fields = wn.meta.get_docfields("Item Price", cur_frm.doc.name);
-		this.make_table();
-	},
-	make_table: function() {
-		var me = this;
-		// Creating table & assigning attributes
-		var grid_table = document.createElement("table");
-		grid_table.className = "table table-hover table-bordered table-grid";
-		
-		// Appending header & rows to table
-		grid_table.appendChild(this.make_table_headers());
-		grid_table.appendChild(this.make_table_rows());
-				
-		// Creating button to add new row
-		var btn_div = document.createElement("div");
-		var new_row_btn = document.createElement("button");
-		new_row_btn.className = "btn btn-success table-new-row";
-		new_row_btn.title = "Add new row";
-
-		var btn_icon = document.createElement("i");
-		btn_icon.className = "icon-plus";
-		new_row_btn.appendChild(btn_icon);
-		new_row_btn.innerHTML += " Add new row";
-		btn_div.appendChild(new_row_btn);
-
-		// Appending table & button to parent
-		var $grid_table = $(grid_table).appendTo($(this.parent));
-		var $btn_div = $(btn_div).appendTo($(this.parent));
-
-		$btn_div.on("click", ".table-new-row", function() {
-			me.make_dialog();
-			return false;
-		});
-
-		$grid_table.on("click", ".table-row", function() {
-			me.make_dialog(this);
-			return false;
-		});
-	},
-	make_table_headers: function() {
-		var me = this;
-		var header = document.createElement("thead");
-		
-		// Creating header row
-		var row = document.createElement("tr");
-		row.className = "active";
-		
-		// Creating head first cell
-		var th = document.createElement("th");
-		th.width = "8%";
-		th.className = "text-center";
-		th.innerHTML = "#";
-		row.appendChild(th);
-
-		// Make other headers with label as heading
-		for(var i=0, l=this.fields.length; i<l; i++) {
-			var df = this.fields[i];
-			
-			if(!!!df.hidden && df.in_list_view === 1) {
-				var th = document.createElement("th");
-			
-				// If currency then move header to right
-				if(["Int", "Currency", "Float"].indexOf(df.fieldtype) !== -1) th.className = "text-right";
-			
-				th.innerHTML = wn._(df.label);
-				row.appendChild(th);
-			}
-		}
-		
-		header.appendChild(row);
-
-		return header;
-	},
-	make_table_rows: function() {
-		var me = this;
-
-		// Creating table body
-		var table_body = document.createElement("tbody");
-
-		var item_prices = wn.model.get_children(this.table_field.options, this.frm.doc.name, 
-			this.table_field.fieldname, this.frm.doctype);
-			
-		for(var i=0, l=item_prices.length; i<l; i++) {
-			var d = item_prices[i];
-			
-			// Creating table row
-			var tr = this.add_new_row(d);
-			
-			// append row to table body
-			table_body.appendChild(tr);
-		}
-		
-		this.table_body = table_body;
-		
-		return table_body;
-	},
-	make_dialog: function(row) {
-		var me = this;
-
-		this.dialog = new wn.ui.Dialog({
-			title: this.table_field.options, 
-			fields: this.fields
-		});
-
-		if (row)
-			this.dialog.set_values(this.make_dialog_values(row));
-
-		$a(this.dialog.body, 'div', '', '', this.make_dialog_buttons(row));
-		this.dialog.show();
-
-		this.dialog.$wrapper.find('button.update').on('click', function() {
-			me.update_row(row);
-		});
-
-		this.dialog.$wrapper.find('button.delete').on('click', function() {
-			me.delete_row(row);
-		});
-		return row;
-	},
-	make_dialog_values: function(row) {
-		var me = this;
-		var dialog_values = {};
-
-		$.each(this.fields, function(i, item) {
-			dialog_values[item.fieldname] = $(row).find('td[data-fieldname="'+ item.fieldname +'"]').attr('data-fieldvalue');
-		});
-
-		return dialog_values;
-	},
-	make_dialog_buttons: function(row) {
-		var me = this;
-		var buttons = '<button class="btn btn-primary update">Update</button>';
-
-		// if user can delete then only add the delete button in dialog
-		if (wn.model.can_delete(me.frm.doc.doctype) && row)
-			buttons += ' <button class="btn btn-default delete">Delete</button>';
-
-		return buttons;
-	},
-	update_row: function(row) {
-		var me = this;
-
-		if (!row) {
-			var d = wn.model.add_child(this.frm.doc, this.table_field.options, 
-				this.table_field.fieldname);
-			refresh_field(this.table_field.fieldname);
-			this.update_item_price(d.name);
-			var tr = this.add_new_row(d);
-			this.table_body.appendChild(tr);
-		}
-		else {
-			this.update_item_price(null, row);
-		}
-		
-		this.dialog.hide();
-	},
-	
-	update_item_price: function(docname, row) {
-		var me = this;
-		if(!docname && row) docname = $(row).attr("data-docname");
-		$.each(me.fields, function(i, df) {
-			var val = me.dialog.get_values()[df.fieldname];
-			
-			if(["Currency", "Float"].indexOf(df.fieldtype)!==-1) {
-				val = flt(val);
-			} else if(["Int", "Check"].indexOf(df.fieldtype)!==-1) {
-				val = cint(val);
-			}
-			
-			wn.model.set_value(me.table_field.options, docname, 
-				df.fieldname, val);
-				
-			if(row) {
-				var $td = $(row).find('td[data-fieldname="'+ df.fieldname +'"]');
-				$td.attr('data-fieldvalue', val);
-				// If field type is currency the update with format currency
-				$td.html(wn.format(val, df));
-			}
-		});
-	},
-	
-	delete_row: function(row) {
-		var me = this;
-		var docname = $(row).find('td:last').attr('data-docname');
-		wn.model.clear_doc(me.table_field.options, docname);
-		$(row).remove();
-
-		// Re-assign idx
-		$.each($(this.parent).find("tbody tr"), function(idx, data) {
-			var $td = $(data).find('td:first');
-			$td.html(idx + 1);
-		});
-		this.dialog.hide();
-	},
-	
-	add_new_row: function(d) {
-		var tr = document.createElement("tr");
-		tr.className = "table-row";
-		tr.setAttribute("data-docname", d.name);
-		
-		// Creating table data & appending to row
-		var td = document.createElement("td");
-		td.className = "text-center";
-		td.innerHTML = d.idx;
-		tr.appendChild(td);
-		
-		for(var f=0, lf=this.fields.length; f<lf; f++) {
-			var df = this.fields[f];
-			if(!!!df.hidden && df.in_list_view===1) {
-				var td = document.createElement("td");
-				td.setAttribute("data-fieldname", df.fieldname);
-				td.setAttribute("data-fieldvalue", d[df.fieldname]);
-				td.setAttribute("data-docname", d.name);
-				
-				// If currency then move header to right
-				if(["Int", "Currency", "Float"].indexOf(df.fieldtype) !== -1) {
-					td.className = "text-right";
-				}
-				
-				// format and set display
-				td.innerHTML = wn.format(d[df.fieldname], df);
-				
-				// append column to tabel row
-				tr.appendChild(td);
-			}
-		}
-		return tr;
+	refresh: function() {
+		cur_frm.add_custom_button("Add / Edit Prices", function() {
+			wn.route_options = {
+				"price_list": cur_frm.doc.name
+			};
+			wn.set_route("Report", "Item Price");
+		}, "icon-money");
 	}
 });
\ No newline at end of file
diff --git a/setup/doctype/price_list/price_list.py b/setup/doctype/price_list/price_list.py
index 2fcaf21..d94b78e 100644
--- a/setup/doctype/price_list/price_list.py
+++ b/setup/doctype/price_list/price_list.py
@@ -8,8 +8,6 @@
 from webnotes.model.controller import DocListController
 import webnotes.defaults
 
-class PriceListDuplicateItem(Exception): pass
-
 class DocType(DocListController):
 	def validate(self):
 		if self.doc.buying_or_selling not in ["Buying", "Selling"]:
@@ -27,23 +25,13 @@
 			else:
 				# at least one territory
 				self.validate_table_has_rows("valid_for_territories")
-
-		# check for duplicate items
-		self.check_duplicate_items()
 		
 	def on_update(self):
 		self.set_default_if_missing()
+		self.update_item_price()
 		cart_settings = webnotes.get_obj("Shopping Cart Settings")
 		if cint(cart_settings.doc.enabled):
 			cart_settings.validate_price_lists()
-
-	def check_duplicate_items(self):
-		item_codes = []
-		for d in self.doclist.get({"parentfield": "item_prices"}):
-			if d.item_code not in item_codes:
-				item_codes.append(d.item_code)
-			else:
-				msgprint(_("Duplicate Item ") + ": " + d.item_code, raise_exception=PriceListDuplicateItem)
 				
 	def set_default_if_missing(self):
 		if self.doc.buying_or_selling=="Selling":
@@ -54,3 +42,7 @@
 			if not webnotes.conn.get_value("Buying Settings", None, "buying_price_list"):
 				webnotes.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.doc.name)
 
+	def update_item_price(self):
+		webnotes.conn.sql("""update `tabItem Price` set currency=%s, 
+			buying_or_selling=%s where price_list=%s""", 
+			(self.doc.currency, self.doc.buying_or_selling, self.doc.name))
\ No newline at end of file
diff --git a/setup/doctype/price_list/price_list.txt b/setup/doctype/price_list/price_list.txt
index df91bd9..b93cfcc 100644
--- a/setup/doctype/price_list/price_list.txt
+++ b/setup/doctype/price_list/price_list.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-25 11:35:09", 
   "docstatus": 0, 
-  "modified": "2013-10-02 11:36:09", 
+  "modified": "2013-10-18 13:33:07", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -85,27 +85,6 @@
   "reqd": 1
  }, 
  {
-  "description": "To change row values, click on the respective row", 
-  "doctype": "DocField", 
-  "fieldname": "item_prices_section", 
-  "fieldtype": "Section Break", 
-  "hidden": 0, 
-  "label": "Item Prices"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "item_prices_html", 
-  "fieldtype": "HTML"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "item_prices", 
-  "fieldtype": "Table", 
-  "hidden": 1, 
-  "label": "Item Prices", 
-  "options": "Item Price"
- }, 
- {
   "amend": 0, 
   "cancel": 0, 
   "create": 0, 
diff --git a/setup/doctype/price_list/test_price_list.py b/setup/doctype/price_list/test_price_list.py
index b1174d3..d5174ed 100644
--- a/setup/doctype/price_list/test_price_list.py
+++ b/setup/doctype/price_list/test_price_list.py
@@ -2,16 +2,7 @@
 # License: GNU General Public License v3. See license.txt
 
 from __future__ import unicode_literals
-import unittest
 import webnotes
-from setup.doctype.price_list.price_list import PriceListDuplicateItem
-
-class TestItem(unittest.TestCase):
-	def test_duplicate_item(self):
-		price_list = webnotes.bean(copy=test_records[0])
-		item_price = price_list.doclist.get({"doctype": "Item Price"})[0]
-		price_list.doclist.append(webnotes.doc(item_price.fields.copy()))
-		self.assertRaises(PriceListDuplicateItem, price_list.insert)
 
 # test_ignore = ["Item"]
 
@@ -28,12 +19,6 @@
 			"parentfield": "valid_for_territories",
 			"territory": "All Territories"
 		},
-		{
-			"doctype": "Item Price",
-			"parentfield": "item_prices",
-			"item_code": "_Test Item",
-			"ref_rate": 100
-		}
 	],
 	[
 		{
diff --git a/setup/page/setup/setup.py b/setup/page/setup/setup.py
index 6e6be31..1569ef0 100644
--- a/setup/page/setup/setup.py
+++ b/setup/page/setup/setup.py
@@ -41,6 +41,7 @@
 			{"doctype":"UOM"}, 
 			{"doctype":"Brand"},
 			{"doctype":"Price List"}, 
+			{"doctype": "Item Price"}, 
 			{ "title": "Stock Settings", 
 				"route": "Form/Stock Settings", "type": "Link", "icon": "icon-cog" },
 		],
diff --git a/setup/report/item_wise_price_list/item_wise_price_list.txt b/setup/report/item_wise_price_list/item_wise_price_list.txt
deleted file mode 100644
index 44118c8..0000000
--- a/setup/report/item_wise_price_list/item_wise_price_list.txt
+++ /dev/null
@@ -1,22 +0,0 @@
-[
- {
-  "creation": "2013-09-25 10:29:04", 
-  "docstatus": 0, 
-  "modified": "2013-09-25 10:29:04", 
-  "modified_by": "Administrator", 
-  "owner": "Administrator"
- }, 
- {
-  "doctype": "Report", 
-  "is_standard": "Yes", 
-  "json": "{\"filters\":[[\"Item Price\",\"item_code\",\"like\",\"%\"],[\"Price List\",\"price_list_name\",\"like\",\"%\"]],\"columns\":[[\"item_code\",\"Item Price\"],[\"price_list_name\",\"Price List\"],[\"currency\",\"Price List\"],[\"ref_rate\",\"Item Price\"],[\"buying_or_selling\",\"Price List\"],[\"name\",\"Price List\"]],\"sort_by\":\"Price List.modified\",\"sort_order\":\"desc\",\"sort_by_next\":\"\",\"sort_order_next\":\"desc\"}", 
-  "name": "__common__", 
-  "ref_doctype": "Price List", 
-  "report_name": "Item-Wise Price List", 
-  "report_type": "Report Builder"
- }, 
- {
-  "doctype": "Report", 
-  "name": "Item-Wise Price List"
- }
-]
\ No newline at end of file
diff --git a/setup/report/item_wise_price_list_rate/item_wise_price_list_rate.txt b/setup/report/item_wise_price_list_rate/item_wise_price_list_rate.txt
index 08b1bef..888203d 100644
--- a/setup/report/item_wise_price_list_rate/item_wise_price_list_rate.txt
+++ b/setup/report/item_wise_price_list_rate/item_wise_price_list_rate.txt
@@ -2,14 +2,14 @@
  {
   "creation": "2013-09-25 10:21:15", 
   "docstatus": 0, 
-  "modified": "2013-09-25 10:24:57", 
+  "modified": "2013-10-21 16:06:22", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
  {
   "doctype": "Report", 
   "is_standard": "Yes", 
-  "json": "{\"filters\":[[\"Item Price\",\"item_code\",\"like\",\"%\"],[\"Price List\",\"price_list_name\",\"like\",\"%\"]],\"columns\":[[\"item_code\",\"Item Price\"],[\"price_list_name\",\"Price List\"],[\"currency\",\"Price List\"],[\"ref_rate\",\"Item Price\"],[\"buying_or_selling\",\"Price List\"],[\"name\",\"Price List\"]],\"sort_by\":\"Price List.modified\",\"sort_order\":\"desc\",\"sort_by_next\":\"\",\"sort_order_next\":\"desc\"}", 
+  "json": "{\"filters\":[[\"Item Price\",\"price_list\",\"like\",\"%\"],[\"Item Price\",\"item_code\",\"like\",\"%\"]],\"columns\":[[\"name\",\"Item Price\"],[\"price_list\",\"Item Price\"],[\"item_code\",\"Item Price\"],[\"item_name\",\"Item Price\"],[\"item_description\",\"Item Price\"],[\"ref_rate\",\"Item Price\"],[\"buying_or_selling\",\"Item Price\"],[\"currency\",\"Item Price\"]],\"sort_by\":\"Item Price.modified\",\"sort_order\":\"desc\",\"sort_by_next\":\"\",\"sort_order_next\":\"desc\"}", 
   "name": "__common__", 
   "ref_doctype": "Price List", 
   "report_name": "Item-wise Price List Rate", 
diff --git a/stock/doctype/item/item.js b/stock/doctype/item/item.js
index a83032e..ecd4612 100644
--- a/stock/doctype/item/item.js
+++ b/stock/doctype/item/item.js
@@ -6,6 +6,7 @@
 	// read only if any stock ledger entry exists
 
 	cur_frm.cscript.make_dashboard()
+	cur_frm.cscript.edit_prices_button();
 
 	cur_frm.toggle_display("naming_series", sys_defaults.item_naming_by=="Naming Series" 
 		&& doc.__islocal)
@@ -28,6 +29,15 @@
 		return;
 }
 
+cur_frm.cscript.edit_prices_button = function() {
+	cur_frm.add_custom_button("Add / Edit Prices", function() {
+		wn.route_options = {
+			"item_code": cur_frm.doc.name
+		};
+		wn.set_route("Report", "Item Price");
+	}, "icon-money");
+}
+
 cur_frm.cscript.item_code = function(doc) {
 	if(!doc.item_name) cur_frm.set_value("item_name", doc.item_code);
 	if(!doc.description) cur_frm.set_value("description", doc.item_code);
diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js
index 7301bd5..b471256 100644
--- a/stock/doctype/stock_entry/stock_entry.js
+++ b/stock/doctype/stock_entry/stock_entry.js
@@ -144,11 +144,18 @@
 	},
 	
 	production_order: function() {
+		var me = this;
 		this.toggle_enable_bom();
 		
 		return this.frm.call({
 			method: "get_production_order_details",
-			args: {production_order: this.frm.doc.production_order}
+			args: {production_order: this.frm.doc.production_order},
+			callback: function(r) {
+				if (!r.exc) {
+					if (me.frm.doc.purpose == "Material Transfer" && !me.frm.doc.to_warehouse)
+						me.frm.set_value("to_warehouse", r.message["wip_warehouse"]);
+				}
+			}
 		});
 	},
 	
diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py
index e4fa9d9..7ec2ba3 100644
--- a/stock/doctype/stock_entry/stock_entry.py
+++ b/stock/doctype/stock_entry/stock_entry.py
@@ -472,11 +472,12 @@
 				if self.doc.purpose=="Material Receipt":
 					self.doc.from_warehouse = ""
 					
-				item = webnotes.conn.sql("""select item, description, uom from `tabBOM`
-					where name=%s""", (self.doc.bom_no,), as_dict=1)
+				item = webnotes.conn.sql("""select name, item_name, description, uom 
+					from `tabItem` where name=%s""", (self.doc.bom_no), as_dict=1)
 				self.add_to_stock_entry_detail({
 					item[0]["item"] : {
 						"qty": self.doc.fg_completed_qty,
+						"item_name": item[0].item_name,
 						"description": item[0]["description"],
 						"stock_uom": item[0]["uom"],
 						"from_warehouse": ""
@@ -484,7 +485,6 @@
 				}, bom_no=self.doc.bom_no)
 		
 		self.get_stock_and_rate()
-		
 	
 	def get_bom_raw_materials(self, qty):
 		""" 
@@ -503,9 +503,12 @@
 				else:
 					item_dict[item.item_code] = {
 						"qty": flt(item.qty), 
+						"item_name": item.item_name, 
 						"description": item.description, 
 						"stock_uom": item.stock_uom,
-						"from_warehouse": item.default_warehouse
+						"from_warehouse": item.default_warehouse,
+						"expense_account": item.purchase_account,
+						"cost_center": item.cost_center
 					}
 		
 		if self.doc.use_multi_level_bom:
@@ -515,7 +518,10 @@
 					ifnull(sum(fb.qty_consumed_per_unit),0)*%s as qty, 
 					fb.description, 
 					fb.stock_uom,
-					it.default_warehouse
+					it.item_name,
+					it.default_warehouse,
+					it.purchase_account,
+					it.cost_center
 				from 
 					`tabBOM Explosion Item` fb,`tabItem` it 
 				where 
@@ -532,10 +538,13 @@
 			# get only BOM items
 			fl_bom_sa_items = sql("""select 
 					`tabItem`.item_code,
+					`tabItem`.item_name,
 					ifnull(sum(`tabBOM Item`.qty_consumed_per_unit), 0) *%s as qty,
 					`tabItem`.description, 
 					`tabItem`.stock_uom,
-					`tabItem`.default_warehouse
+					`tabItem`.default_warehouse,
+					`tabItem`.purchase_account,
+					`tabItem`.cost_center
 				from 
 					`tabBOM Item`, `tabItem`
 				where 
@@ -599,16 +608,24 @@
 		return issued_item_qty
 
 	def add_to_stock_entry_detail(self, item_dict, bom_no=None):
+		idx = 1
+		expense_account, cost_center = webnotes.conn.get_values("Company", self.doc.company, \
+			["default_expense_account", "cost_center"])[0]
+
 		for d in item_dict:
 			se_child = addchild(self.doc, 'mtn_details', 'Stock Entry Detail', 
 				self.doclist)
+			se_child.idx = idx
 			se_child.s_warehouse = item_dict[d].get("from_warehouse", self.doc.from_warehouse)
 			se_child.t_warehouse = item_dict[d].get("to_warehouse", self.doc.to_warehouse)
 			se_child.item_code = cstr(d)
+			se_child.item_name = item_dict[d]["item_name"]
 			se_child.description = item_dict[d]["description"]
 			se_child.uom = item_dict[d]["stock_uom"]
 			se_child.stock_uom = item_dict[d]["stock_uom"]
 			se_child.qty = flt(item_dict[d]["qty"])
+			se_child.expense_account = item_dict[d]["expense_account"] or expense_account
+			se_child.cost_center = item_dict[d]["cost_center"] or cost_center
 			
 			# in stock uom
 			se_child.transfer_qty = flt(item_dict[d]["qty"])
@@ -617,6 +634,9 @@
 			# to be assigned for finished item
 			se_child.bom_no = bom_no
 
+			# increment idx by 1
+			idx += 1
+
 	def get_cust_values(self):
 		"""fetches customer details"""
 		if self.doc.delivery_note_no:
@@ -682,8 +702,8 @@
 @webnotes.whitelist()
 def get_production_order_details(production_order):
 	result = webnotes.conn.sql("""select bom_no, 
-		ifnull(qty, 0) - ifnull(produced_qty, 0) as fg_completed_qty, use_multi_level_bom
-		from `tabProduction Order` where name = %s""", production_order, as_dict=1)
+		ifnull(qty, 0) - ifnull(produced_qty, 0) as fg_completed_qty, use_multi_level_bom, 
+		wip_warehouse from `tabProduction Order` where name = %s""", production_order, as_dict=1)
 	return result and result[0] or {}
 	
 def query_sales_return_doc(doctype, txt, searchfield, start, page_len, filters):
diff --git a/stock/doctype/stock_entry_detail/stock_entry_detail.txt b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
index b766250..5218c1a 100644
--- a/stock/doctype/stock_entry_detail/stock_entry_detail.txt
+++ b/stock/doctype/stock_entry_detail/stock_entry_detail.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-03-29 18:22:12", 
   "docstatus": 0, 
-  "modified": "2013-10-15 14:58:09", 
+  "modified": "2013-10-23 14:35:46", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -67,6 +67,14 @@
  }, 
  {
   "doctype": "DocField", 
+  "fieldname": "item_name", 
+  "fieldtype": "Data", 
+  "label": "Item Name", 
+  "print_hide": 1, 
+  "read_only": 1
+ }, 
+ {
+  "doctype": "DocField", 
   "fieldname": "description", 
   "fieldtype": "Text", 
   "in_list_view": 1, 
diff --git a/stock/doctype/warehouse/warehouse.py b/stock/doctype/warehouse/warehouse.py
index 476a6f6..cfa2782 100644
--- a/stock/doctype/warehouse/warehouse.py
+++ b/stock/doctype/warehouse/warehouse.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import webnotes
 
-from webnotes.utils import cint, flt, validate_email_add
+from webnotes.utils import cint, validate_email_add
 from webnotes import msgprint, _
 
 sql = webnotes.conn.sql
@@ -115,8 +115,9 @@
 			sql("delete from `tabStock Ledger Entry` where warehouse = %s", self.doc.name)
 
 	def on_rename(self, newdn, olddn, merge=False):
-		webnotes.conn.set_value("Account", {"account_type": "Warehouse", "master_name": olddn}, 
-			"master_name", newdn)
+		account = webnotes.conn.get_value("Account", {"account_type": "Warehouse", 
+			"master_name": olddn})
+		webnotes.conn.set_value("Account", account, "master_name", newdn)
 			
 		if merge:
 			from stock.stock_ledger import update_entries_after
diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js
index 63db608..ecfc6fe 100644
--- a/stock/page/stock_home/stock_home.js
+++ b/stock/page/stock_home/stock_home.js
@@ -77,7 +77,12 @@
 			{
 				"doctype":"Price List",
 				"label": wn._("Price List"),
-				"description": wn._("Multiple Item Prices")
+				"description": wn._("Multiple Price list.")
+			},
+			{
+				"doctype":"Item Price",
+				"label": wn._("Item Price"),
+				"description": wn._("Multiple Item prices.")
 			},
 			{
 				"doctype":"Quality Inspection",
@@ -202,8 +207,8 @@
 			},
 			{
 				"label":wn._("Item-wise Price List Rate"),
-				route: "Report/Price List/Item-Wise Price List",
-				doctype: "Price List"
+				route: "Report/Item Price/Item-wise Price List Rate",
+				doctype: "Item Price"
 			},
 			{
 				"label":wn._("Purchase In Transit"),
diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py
index 70c0677..2bb3779 100644
--- a/stock/report/item_prices/item_prices.py
+++ b/stock/report/item_prices/item_prices.py
@@ -57,10 +57,9 @@
 
 	rate = {}
 
-	price_list = webnotes.conn.sql("""select ip.item_code, pl.buying_or_selling, 
-		concat(pl.name, " - ", pl.currency, " ", ip.ref_rate) as price 
-		from `tabItem Price` ip, `tabPrice List` pl where 
-		ip.parent = pl.name and pl.docstatus<2""", as_dict=1)
+	price_list = webnotes.conn.sql("""select item_code, buying_or_selling, 
+		concat(price_list, " - ", currency, " ", ref_rate) as price 
+		from `tabItem Price`""", as_dict=1)
 
 	for j in price_list:
 		if j.price:
diff --git a/utilities/repost_stock.py b/utilities/repost_stock.py
index 7359304..536df81 100644
--- a/utilities/repost_stock.py
+++ b/utilities/repost_stock.py
@@ -13,8 +13,11 @@
 	"""
 	webnotes.conn.auto_commit_on_many_writes = 1
 	
-	for d in webnotes.conn.sql("select item_code, warehouse from tabBin"):
-		repost_stock(d[0], d[1])
+	for d in webnotes.conn.sql("""select distinct item_code, warehouse from 
+		(select item_code, warehouse from tabBin
+		union
+		select item_code, warehouse from `tabStock Ledger Entry`) a"""):
+			repost_stock(d[0], d[1])
 		
 	webnotes.conn.auto_commit_on_many_writes = 0
 
@@ -31,7 +34,10 @@
 
 def repost_actual_qty(item_code, warehouse):
 	from stock.stock_ledger import update_entries_after
-	update_entries_after({ "item_code": item_code, "warehouse": warehouse })
+	try:
+		update_entries_after({ "item_code": item_code, "warehouse": warehouse })
+	except:
+		pass
 
 def get_reserved_qty(item_code, warehouse):
 	reserved_qty = webnotes.conn.sql("""