[fix] [minor] merge conflict
diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.txt b/accounts/doctype/purchase_invoice/purchase_invoice.txt
index f98c14a..af0eb8e 100755
--- a/accounts/doctype/purchase_invoice/purchase_invoice.txt
+++ b/accounts/doctype/purchase_invoice/purchase_invoice.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-11-05 23:09:38", 
+  "modified": "2013-11-22 17:15:27", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -297,7 +297,7 @@
   "oldfieldname": "net_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -396,7 +396,7 @@
   "oldfieldname": "grand_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -406,7 +406,7 @@
   "label": "In Words", 
   "oldfieldname": "in_words_import", 
   "oldfieldtype": "Data", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
diff --git a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
index e1a0d14..84521ed 100644
--- a/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
+++ b/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
@@ -14,6 +14,19 @@
    cur_frm.set_footnote(wn.markdown(cur_frm.meta.description));
 }
 
+// For customizing print
+cur_frm.pformat.net_total_import = function(doc) {
+	return '';
+}
+
+cur_frm.pformat.grand_total_import = function(doc) {
+	return '';
+}
+
+cur_frm.pformat.in_words_import = function(doc) {
+	return '';
+}
+
 cur_frm.pformat.purchase_tax_details= function(doc){
  
   //function to make row of table
@@ -42,9 +55,9 @@
 		<tr><td style="width: 60%"></td><td>';
   
   // main table
-  out +='<table class="noborder" style="width:100%">'
-  if(!print_hide('net_total')) {
-	out += make_row('Net Total', convert_rate(doc.net_total), 1);
+  out +='<table class="noborder" style="width:100%">';
+  if(!print_hide('net_total_import')) {
+	out += make_row('Net Total', doc.net_total_import, 1);
   }
   
   // add rows
diff --git a/buying/doctype/purchase_order/purchase_order.txt b/buying/doctype/purchase_order/purchase_order.txt
index 6a97eed..4d39771 100644
--- a/buying/doctype/purchase_order/purchase_order.txt
+++ b/buying/doctype/purchase_order/purchase_order.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-11-05 23:09:58", 
+  "modified": "2013-11-22 17:15:58", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -263,7 +263,7 @@
   "oldfieldname": "net_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -376,7 +376,7 @@
   "oldfieldname": "grand_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1, 
   "report_hide": 0
  }, 
@@ -387,7 +387,7 @@
   "label": "In Words", 
   "oldfieldname": "in_words_import", 
   "oldfieldtype": "Data", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
diff --git a/buying/doctype/supplier_quotation/supplier_quotation.txt b/buying/doctype/supplier_quotation/supplier_quotation.txt
index fcef822..cf62a9f 100644
--- a/buying/doctype/supplier_quotation/supplier_quotation.txt
+++ b/buying/doctype/supplier_quotation/supplier_quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:45", 
   "docstatus": 0, 
-  "modified": "2013-11-03 14:14:12", 
+  "modified": "2013-11-22 17:16:16", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -262,7 +262,7 @@
   "oldfieldname": "net_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -366,7 +366,7 @@
   "oldfieldname": "grand_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1, 
   "report_hide": 0
  }, 
@@ -377,7 +377,7 @@
   "label": "In Words", 
   "oldfieldname": "in_words_import", 
   "oldfieldtype": "Data", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
diff --git a/stock/doctype/purchase_receipt/purchase_receipt.txt b/stock/doctype/purchase_receipt/purchase_receipt.txt
index 6035b71..95e254e 100755
--- a/stock/doctype/purchase_receipt/purchase_receipt.txt
+++ b/stock/doctype/purchase_receipt/purchase_receipt.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-21 16:16:39", 
   "docstatus": 0, 
-  "modified": "2013-11-03 14:20:21", 
+  "modified": "2013-11-22 17:15:47", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -291,7 +291,7 @@
   "oldfieldname": "net_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -398,7 +398,7 @@
   "oldfieldname": "grand_total_import", 
   "oldfieldtype": "Currency", 
   "options": "currency", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
@@ -408,7 +408,7 @@
   "label": "In Words", 
   "oldfieldname": "in_words_import", 
   "oldfieldtype": "Data", 
-  "print_hide": 1, 
+  "print_hide": 0, 
   "read_only": 1
  }, 
  {
diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py
index c7a10ed..1328721 100644
--- a/stock/doctype/serial_no/serial_no.py
+++ b/stock/doctype/serial_no/serial_no.py
@@ -73,23 +73,16 @@
 		self.doc.item_name = item.item_name
 		self.doc.brand = item.brand
 		self.doc.warranty_period = item.warranty_period
-				
-	def set_status(self):
-		last_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
-			where (serial_no like %s or serial_no like %s or serial_no=%s) 
-			and item_code=%s and ifnull(is_cancelled, 'No')='No' 
-			order by name desc limit 1""", 
-			("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, 
-				self.doc.item_code), as_dict=1)
 		
+	def set_status(self, last_sle):
 		if last_sle:
-			if last_sle[0].voucher_type == "Stock Entry":
-				document_type = webnotes.conn.get_value("Stock Entry", last_sle[0].voucher_no, 
+			if last_sle.voucher_type == "Stock Entry":
+				document_type = webnotes.conn.get_value("Stock Entry", last_sle.voucher_no, 
 					"purpose")
 			else:
-				document_type = last_sle[0].voucher_type
+				document_type = last_sle.voucher_type
 
-			if last_sle[0].actual_qty > 0:
+			if last_sle.actual_qty > 0:
 				if document_type == "Sales Return":
 					self.doc.status = "Sales Returned"
 				else:
@@ -97,59 +90,70 @@
 			else:
 				if document_type == "Purchase Return":
 					self.doc.status = "Purchase Returned"
-				elif last_sle[0].voucher_type in ("Delivery Note", "Sales Invoice"):
+				elif last_sle.voucher_type in ("Delivery Note", "Sales Invoice"):
 					self.doc.status = "Delivered"
 				else:
 					self.doc.status = "Not Available"
 		
-	def set_purchase_details(self):
-		purchase_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
-			where (serial_no like %s or serial_no like %s or serial_no=%s) 
-			and item_code=%s and actual_qty > 0 
-			and ifnull(is_cancelled, 'No')='No' order by name asc limit 1""", 
-			("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, 
-				 self.doc.item_code), as_dict=1)
-
+	def set_purchase_details(self, purchase_sle):
 		if purchase_sle:
-			self.doc.purchase_document_type = purchase_sle[0].voucher_type
-			self.doc.purchase_document_no = purchase_sle[0].voucher_no
-			self.doc.purchase_date = purchase_sle[0].posting_date
-			self.doc.purchase_time = purchase_sle[0].posting_time
-			self.doc.purchase_rate = purchase_sle[0].incoming_rate
-			if purchase_sle[0].voucher_type == "Purchase Receipt":
+			self.doc.purchase_document_type = purchase_sle.voucher_type
+			self.doc.purchase_document_no = purchase_sle.voucher_no
+			self.doc.purchase_date = purchase_sle.posting_date
+			self.doc.purchase_time = purchase_sle.posting_time
+			self.doc.purchase_rate = purchase_sle.incoming_rate
+			if purchase_sle.voucher_type == "Purchase Receipt":
 				self.doc.supplier, self.doc.supplier_name = \
-					webnotes.conn.get_value("Purchase Receipt", purchase_sle[0].voucher_no, 
+					webnotes.conn.get_value("Purchase Receipt", purchase_sle.voucher_no, 
 						["supplier", "supplier_name"])
 		else:
 			for fieldname in ("purchase_document_type", "purchase_document_no", 
 				"purchase_date", "purchase_time", "purchase_rate", "supplier", "supplier_name"):
 					self.doc.fields[fieldname] = None
 				
-	def set_sales_details(self):
-		delivery_sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
-			where (serial_no like %s or serial_no like %s or serial_no=%s)
-			and item_code=%s and actual_qty<0 
-			and voucher_type in ('Delivery Note', 'Sales Invoice')
-			and ifnull(is_cancelled, 'No')='No' order by name desc limit 1""", 
-			("%%%s%%" % (self.doc.name+"\n"), "%%%s%%" % ("\n"+self.doc.name), self.doc.name, 
-				 self.doc.item_code), as_dict=1)
+	def set_sales_details(self, delivery_sle):
 		if delivery_sle:
-			self.doc.delivery_document_type = delivery_sle[0].voucher_type
-			self.doc.delivery_document_no = delivery_sle[0].voucher_no
-			self.doc.delivery_date = delivery_sle[0].posting_date
-			self.doc.delivery_time = delivery_sle[0].posting_time
+			self.doc.delivery_document_type = delivery_sle.voucher_type
+			self.doc.delivery_document_no = delivery_sle.voucher_no
+			self.doc.delivery_date = delivery_sle.posting_date
+			self.doc.delivery_time = delivery_sle.posting_time
 			self.doc.customer, self.doc.customer_name = \
-				webnotes.conn.get_value(delivery_sle[0].voucher_type, delivery_sle[0].voucher_no, 
+				webnotes.conn.get_value(delivery_sle.voucher_type, delivery_sle.voucher_no, 
 					["customer", "customer_name"])
 			if self.doc.warranty_period:
-				self.doc.warranty_expiry_date	= add_days(cstr(delivery_sle[0].posting_date), 
+				self.doc.warranty_expiry_date	= add_days(cstr(delivery_sle.posting_date), 
 					cint(self.doc.warranty_period))
 		else:
 			for fieldname in ("delivery_document_type", "delivery_document_no", 
 				"delivery_date", "delivery_time", "customer", "customer_name", 
 				"warranty_expiry_date"):
-					self.doc.fields[fieldname] = None		
+					self.doc.fields[fieldname] = None
+					
+	def get_last_sle(self):
+		entries = {}
 		
+		for sle in self.get_stock_ledger_entries():
+			if self.doc.name in get_serial_nos(sle.serial_no):
+				if not entries.get("last_sle"):
+					entries["last_sle"] = sle
+					
+				if not entries.get("purchase_sle") and sle.actual_qty > 0:
+					entries["purchase_sle"] = sle
+				elif not entries.get("delivery_sle") and sle.actual_qty < 0 \
+						and sle.voucher_type in ('Delivery Note', 'Sales Invoice'):
+					entries["delivery_sle"] = sle
+				
+				if entries.get("last_sle") and entries.get("purchase_sle") \
+						and entries.get("delivery_sle"):
+					break
+				
+		return entries
+		
+	def get_stock_ledger_entries(self):
+		return webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
+			where serial_no like %s and item_code=%s and ifnull(is_cancelled, 'No')='No' 
+			order by name desc""", ("%%%s%%" % self.doc.name, self.doc.item_code), as_dict=1)		
+	
 	def on_trash(self):
 		if self.doc.status == 'Delivered':
 			webnotes.throw(_("Delivered Serial No ") + self.doc.name + _(" can not be deleted"))
@@ -176,9 +180,10 @@
 	
 	def on_stock_ledger_entry(self):
 		if self.via_stock_ledger and not self.doc.fields.get("__islocal"):
-			self.set_status()
-			self.set_purchase_details()
-			self.set_sales_details()
+			last_sle = self.get_last_sle()
+			self.set_status(last_sle.get("last_sle"))
+			self.set_purchase_details(last_sle.get("purchase_sle"))
+			self.set_sales_details(last_sle.get("delivery_sle"))
 
 	def on_stock_ledger_entry(self):
 		if self.via_stock_ledger and not self.doc.fields.get("__islocal"):
@@ -235,12 +240,12 @@
 					# transfer out
 					webnotes.throw(_("Serial No must exist to transfer out.") + \
 						": " + serial_no, SerialNoNotExistsError)
-		elif not item_det.serial_no_series:
+		elif sle.actual_qty < 0 or not item_det.serial_no_series:
 			webnotes.throw(_("Serial Number Required for Serialized Item" + ": " 
 				+ sle.item_code), SerialNoRequiredError)
 				
 def update_serial_nos(sle, item_det):
-	if not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series:
+	if sle.is_cancelled == "No" and not sle.serial_no and sle.actual_qty > 0 and item_det.serial_no_series:
 		from webnotes.model.doc import make_autoname
 		serial_nos = []
 		for i in xrange(cint(sle.actual_qty)):