validate returned qty only if there is reference qty
diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py
index 4ea2a5f..d8f28af 100644
--- a/erpnext/controllers/sales_and_purchase_return.py
+++ b/erpnext/controllers/sales_and_purchase_return.py
@@ -106,24 +106,25 @@
 
 def validate_quantity(doc, args, ref, valid_items, already_returned_items):
 	fields = ['qty']
-	if doc.doctype in ['Purchase Invoice', 'Purchase Receipt']:
+	if doc.doctype in ['Purchase Receipt', 'Purchase Invoice']:
 		fields.extend(['received_qty', 'rejected_qty'])
 
 	already_returned_data = already_returned_items.get(args.item_code) or {}
 
 	for column in fields:
-		return_qty = flt(already_returned_data.get(column, 0)) if len(already_returned_data) > 0 else 0
-		referenced_qty = ref.get(column)
-		max_return_qty = flt(referenced_qty) - return_qty
+		returned_qty = flt(already_returned_data.get(column, 0)) if len(already_returned_data) > 0 else 0
+		reference_qty = ref.get(column)
+		max_returnable_qty = flt(reference_qty) - returned_qty
 		label = column.replace('_', ' ').title()
-
-		if flt(args.get(column)) > 0:
-			frappe.throw(_("{0} must be negative in return document").format(label))
-		elif return_qty >= referenced_qty and flt(args.get(column)) != 0:
-			frappe.throw(_("Item {0} has already been returned").format(args.item_code), StockOverReturnError)
-		elif abs(args.get(column)) > max_return_qty:
-			frappe.throw(_("Row # {0}: Cannot return more than {1} for Item {2}")
-				.format(args.idx, referenced_qty, args.item_code), StockOverReturnError)
+		if reference_qty:	
+			if flt(args.get(column)) > 0:
+				frappe.throw(_("{0} must be negative in return document").format(label))
+			elif returned_qty >= reference_qty and args.get(column):
+				frappe.throw(_("Item {0} has already been returned")
+					.format(args.item_code), StockOverReturnError)
+			elif abs(args.get(column)) > max_returnable_qty:
+				frappe.throw(_("Row # {0}: Cannot return more than {1} for Item {2}")
+					.format(args.idx, reference_qty, args.item_code), StockOverReturnError)
 
 def get_ref_item_dict(valid_items, ref_item_row):
 	from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos