Merge branch 'dev' of github.com:webnotes/erpnext into dev
diff --git a/erpnext/selling/doctype/sales_common/sales_common.js b/erpnext/selling/doctype/sales_common/sales_common.js
index f662dae..c229ece 100644
--- a/erpnext/selling/doctype/sales_common/sales_common.js
+++ b/erpnext/selling/doctype/sales_common/sales_common.js
@@ -343,7 +343,7 @@
 				Please either <br /> \
 				* Specify Basic Rate (i.e. Rate which will be displayed in print) <br /> \
 				-- or -- <br />\
-				* Uncheck 'Included in Print Rate' in the tax entries of Taxes section.");
+				* Uncheck 'Is this Tax included in Basic Rate?' in the tax entries of Taxes section.");
 		}
 	}
 }
@@ -656,27 +656,15 @@
 	var tax = locals[cdt][cdn];
 	if(tax.included_in_print_rate==1) { 
 		if(!inList(['On Net Total', 'On Previous Row Total', 'On Previous Row Amount'], tax.charge_type)) {
-			msgprint("Included in Print Rate (i.e. Inclusive Price) is only valid for charges of type: <br /> \
+			msgprint("'Is this Tax included in Basic Rate?' (i.e. Inclusive Price) is only valid for charges of type: <br /> \
 				* On Net Total <br /> \
 				* On Previous Row Amount <br /> \
 				* On Previous Row Total");
 			tax.included_in_print_rate = 0;
 			refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname);
-		} else if(inList(['On Previous Row Total', 'On Previous Row Amount'], tax.charge_type)){
-			if(tax.row_id) {
-				var tax_list = getchildren('Sales Taxes and Charges', doc.name, cur_frm.cscript.other_fname, doc.doctype);
-				if(tax_list[tax.row_id-1].charge_type=='Actual') {
-					msgprint("Row of type 'Actual' cannot be depended on for type '" + tax.charge_type + "'\
-						when using tax inclusive prices.<br />\
-						This will lead to incorrect values.<br /><br /> \
-						<b>Please specify correct value in 'Enter Row' column of <span style='color:red'>Row: "	
-						+ tax.idx + "</span> in Taxes table</b>");
-					validated = false;
-					tax.included_in_print_rate = 0;
-					refresh_field('included_in_print_rate', tax.name, cur_frm.cscript.other_fname);
-				}
-			}
-		}
+		} 
+		var tax_list = getchildren('Sales Taxes and Charges', doc.name, cur_frm.cscript.other_fname, doc.doctype);
+		cur_frm.cscript.validate_print_rate_option(doc, tax_list, tax.idx-1);
 	}
 }
 
@@ -758,6 +746,32 @@
 	cur_frm.cscript.calculate_charges(doc,cdt,cdn);
 }
 
+cur_frm.cscript.validate_print_rate_option = function(doc, taxes, i) {
+	if(in_list(['On Previous Row Amount','On Previous Row Total'], taxes[i].charge_type)) { 
+		if(!taxes[i].row_id){
+			alert("Please Enter Row on which amount needs to be calculated for row : "+taxes[i].idx);
+			validated = false;
+		} else if(taxes[i].included_in_print_rate && taxes[taxes[i].row_id-1].charge_type=='Actual') {
+			msgprint("Row of type 'Actual' cannot be depended on for type '" + taxes[i].charge_type + "'\
+				when using tax inclusive prices.<br />\
+				This will lead to incorrect values.<br /><br /> \
+				<b>Please specify correct value in 'Enter Row' column of <span style='color:red'>Row: "	
+				+ taxes[i].idx + "</span> in Taxes table</b>");
+			validated = false;
+			taxes[i].included_in_print_rate = 0;
+			refresh_field('included_in_print_rate', taxes[i].name, other_fname);
+		} else if ((taxes[i].included_in_print_rate && !taxes[taxes[i].row_id-1].included_in_print_rate) || 
+			(!taxes[i].included_in_print_rate && taxes[taxes[i].row_id-1].included_in_print_rate)) {
+			msgprint("If any row in the tax table depends on 'Previous Row Amount/Total', <br />\
+				'Is this Tax included in Basic Rate?' column should be same for both row <br />\
+				i.e for that row and the previous row. <br /><br />\
+				The same is violated for row #"+(i+1)+" and row #"+taxes[i].row_id
+			);
+			validated = false;
+		}		
+	}
+}
+
 cur_frm.cscript.calculate_charges = function(doc, cdt, cdn) {
 	var other_fname	= cur_frm.cscript.other_fname;
 
@@ -767,21 +781,7 @@
 		cl[i].total_amount = 0;
 		cl[i].tax_amount = 0;										// this is done to calculate other charges
 		cl[i].total = 0;
-		if(in_list(['On Previous Row Amount','On Previous Row Total'], cl[i].charge_type)) { 
-			if(!cl[i].row_id){
-				alert("Please Enter Row on which amount needs to be calculated for row : "+cl[i].idx);
-				validated = false;
-			} else if(cl[i].included_in_print_rate && cl[cl[i].row_id-1].charge_type=='Actual') {
-				msgprint("Row of type 'Actual' cannot be depended on for type '" + cl[i].charge_type + "'\
-					when using tax inclusive prices.<br />\
-					This will lead to incorrect values.<br /><br /> \
-					<b>Please specify correct value in 'Enter Row' column of <span style='color:red'>Row: "	
-					+ cl[i].idx + "</span> in Taxes table</b>");
-				validated = false;
-				cl[i].included_in_print_rate = 0;
-				refresh_field('included_in_print_rate', cl[i].name, other_fname);
-			}
-		}
+		cur_frm.cscript.validate_print_rate_option(doc, cl, i);
 	}
 	cur_frm.cscript.recalc(doc, 1);
 }
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 02bffca..f4f1bbc 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -181,19 +181,28 @@
 			if getdate(self.doc.transaction_date) > getdate(self.doc.delivery_date):
 				msgprint("Expected Delivery Date cannot be before Sales Order Date")
 				raise Exception
-
-	# Validate P.O Date
-	# ------------------
-	def validate_po_date(self):
-		# validate p.o date v/s delivery date
-		if self.doc.po_date and self.doc.delivery_date and getdate(self.doc.po_date) > getdate(self.doc.delivery_date):
-			msgprint("Expected Delivery Date cannot be before Purchase Order Date")
-			raise Exception	
 		# amendment date is necessary if document is amended
 		if self.doc.amended_from and not self.doc.amendment_date:
 			msgprint("Please Enter Amendment Date")
 			raise Exception
 	
+
+	# Validate P.O Date
+	# ------------------
+	def validate_po(self):
+		# validate p.o date v/s delivery date
+		if self.doc.po_date and self.doc.delivery_date and getdate(self.doc.po_date) > getdate(self.doc.delivery_date):
+			msgprint("Expected Delivery Date cannot be before Purchase Order Date")
+			raise Exception	
+		
+		if self.doc.po_no and self.doc.customer:
+			so = webnotes.conn.sql("select name from `tabSales Order` \
+				where ifnull(po_no, '') = %s and name != %s and docstatus < 2\
+				and customer = %s", (self.doc.po_no, self.doc.name, self.doc.customer))
+			if so and so[0][0]:
+				msgprint("""Another Sales Order (%s) exists against same PO No and Customer. 
+					Please be sure, you are not making duplicate entry.""" % so[0][0])
+	
 	# Validations of Details Table
 	# -----------------------------
 	def validate_for_items(self):
@@ -305,7 +314,7 @@
 		self.validate_order_type()
 		self.validate_mandatory()
 		self.validate_proj_cust()
-		self.validate_po_date()
+		self.validate_po()
 		#self.validate_reference_value()
 		self.validate_for_items()
 		sales_com_obj = get_obj(dt = 'Sales Common')