[fix] paging for products (support)
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index 9111830..4bb6765 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -39,7 +39,7 @@
 
 		if not self.title:
 			self.title = self.customer_name
-			
+
 		if not self.with_items:
 			self.items = []
 
@@ -64,7 +64,7 @@
 				lead = frappe.get_doc({
 					"doctype": "Lead",
 					"email_id": self.contact_email,
-					"lead_name": sender_name
+					"lead_name": sender_name or 'Unknown'
 				})
 
 				lead.flags.ignore_email_validation = True
@@ -93,9 +93,9 @@
 
 	def has_lost_quotation(self):
 		return frappe.db.sql("""
-			select q.name 
+			select q.name
 			from `tabQuotation` q, `tabQuotation Item` qi
-			where q.name = qi.parent and q.docstatus=1 
+			where q.name = qi.parent and q.docstatus=1
 				and qi.prevdoc_docname =%s and q.status = 'Lost'
 			""", self.name)
 
@@ -213,7 +213,7 @@
 		if company_currency == quotation.currency:
 			exchange_rate = 1
 		else:
-			exchange_rate = get_exchange_rate(quotation.currency, company_currency, 
+			exchange_rate = get_exchange_rate(quotation.currency, company_currency,
 				quotation.transaction_date)
 
 		quotation.conversion_rate = exchange_rate
diff --git a/erpnext/demo/demo.py b/erpnext/demo/demo.py
index 180ddfa..aeaa1f0 100644
--- a/erpnext/demo/demo.py
+++ b/erpnext/demo/demo.py
@@ -30,7 +30,7 @@
 		manufacture.setup_data()
 	elif domain== 'Education':
 		education.setup_data()
-	
+
 	site = frappe.local.site
 	frappe.destroy()
 	frappe.init(site)
@@ -52,7 +52,7 @@
 	demo_last_date = frappe.db.get_global('demo_last_date')
 	if demo_last_date:
 		current_date = frappe.utils.add_days(frappe.utils.getdate(demo_last_date), 1)
-		
+
 	# run till today
 	if not runs_for:
 		runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date)
@@ -60,7 +60,8 @@
 
 	fixed_asset.work()
 	for i in xrange(runs_for):
-		sys.stdout.write("\rSimulating {0}".format(current_date.strftime("%Y-%m-%d")))
+		sys.stdout.write("\rSimulating {0}: Day {1}".format(
+			current_date.strftime("%Y-%m-%d"), i))
 		sys.stdout.flush()
 		frappe.flags.current_date = current_date
 		if current_date.weekday() in (5, 6):
@@ -73,16 +74,16 @@
 			accounts.work()
 			projects.run_projects(current_date)
 			#run_messages()
-			
+
 			if domain=='Manufacturing':
 				sales.work()
 				manufacturing.work()
 			elif domain=='Education':
 				schools.work()
-		
+
 		except:
 			frappe.db.set_global('demo_last_date', current_date)
-			raise	
+			raise
 		finally:
 			current_date = frappe.utils.add_days(current_date, 1)
 			frappe.db.commit()
diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py
index ab8ec77..960a316 100644
--- a/erpnext/demo/user/purchase.py
+++ b/erpnext/demo/user/purchase.py
@@ -75,7 +75,7 @@
 				frappe.db.commit()
 
 	# make purchase orders
-	if random.random() < 0.3:
+	if random.random() < 0.5:
 		from erpnext.stock.doctype.material_request.material_request import make_purchase_order
 		report = "Requested Items To Be Ordered"
 		for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
@@ -103,7 +103,7 @@
 		mr.material_request_type = "Purchase"
 
 	mr.transaction_date = frappe.flags.current_date
-	
+
 	mr.append("items", {
 		"doctype": "Material Request Item",
 		"schedule_date": frappe.utils.add_days(mr.transaction_date, 7),
@@ -130,7 +130,7 @@
 		po.supplier = get_random("Supplier")
 
 		item_code = get_random("Item", {"is_sub_contracted_item": 1})
-		
+
 		po.append("items", {
 			"item_code": item_code,
 			"schedule_date": frappe.utils.add_days(frappe.flags.current_date, 7),
diff --git a/erpnext/demo/user/stock.py b/erpnext/demo/user/stock.py
index 0bd5ce3..1b12db8 100644
--- a/erpnext/demo/user/stock.py
+++ b/erpnext/demo/user/stock.py
@@ -36,6 +36,7 @@
 			try:
 				pr.submit()
 			except NegativeStockError:
+				print 'Negative stock for {0}'.format(po)
 				pass
 			frappe.db.commit()
 
@@ -101,23 +102,25 @@
 			frappe.db.rollback()
 
 def make_sales_return_records():
-	for data in frappe.get_all('Delivery Note', fields=["name"], filters={"docstatus": 1}):
-		if random.random() < 0.1:
-			try:
-				dn = make_sales_return(data.name)
-				dn.insert()
-				dn.submit()
-				frappe.db.commit()
-			except Exception:
-				frappe.db.rollback()
+	if random.random() < 0.1:
+		for data in frappe.get_all('Delivery Note', fields=["name"], filters={"docstatus": 1}):
+			if random.random() < 0.1:
+				try:
+					dn = make_sales_return(data.name)
+					dn.insert()
+					dn.submit()
+					frappe.db.commit()
+				except Exception:
+					frappe.db.rollback()
 
 def make_purchase_return_records():
-	for data in frappe.get_all('Purchase Receipt', fields=["name"], filters={"docstatus": 1}):
-		if random.random() < 0.1:
-			try:
-				pr = make_purchase_return(data.name)
-				pr.insert()
-				pr.submit()
-				frappe.db.commit()
-			except Exception:
-				frappe.db.rollback()
+	if random.random() < 0.1:
+		for data in frappe.get_all('Purchase Receipt', fields=["name"], filters={"docstatus": 1}):
+			if random.random() < 0.1:
+				try:
+					pr = make_purchase_return(data.name)
+					pr.insert()
+					pr.submit()
+					frappe.db.commit()
+				except Exception:
+					frappe.db.rollback()
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 12899cd..c38e04d 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -68,7 +68,7 @@
 			start = 0
 		context.update({
 			"items": get_product_list_for_group(product_group = self.name, start=start,
-				limit=context.page_length, search=frappe.form_dict.get("search")),
+				limit=context.page_length + 1, search=frappe.form_dict.get("search")),
 			"parent_groups": get_parent_item_groups(self.name),
 			"title": self.name,
 			"products_as_list": cint(frappe.db.get_single_value('Website Settings', 'products_as_list'))
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index e1aa16d..8272977 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -3052,7 +3052,7 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 0, 
+   "collapsible": 1, 
    "collapsible_depends_on": "sales_team", 
    "columns": 0, 
    "fieldname": "section_break1", 
@@ -3120,7 +3120,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-07 05:52:12.783914", 
+ "modified": "2016-12-16 03:56:08.745185", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/item/item_dashboard.py b/erpnext/stock/doctype/item/item_dashboard.py
index b40b196..c721086 100644
--- a/erpnext/stock/doctype/item/item_dashboard.py
+++ b/erpnext/stock/doctype/item/item_dashboard.py
@@ -28,7 +28,7 @@
 			{
 				'label': _('Buy'),
 				'items': ['Material Request', 'Supplier Quotation', 'Request for Quotation',
-					'Purchase Order', 'Purchase Invoice']
+					'Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
 			},
 			{
 				'label': _('Traceability'),
diff --git a/erpnext/templates/generators/item_group.html b/erpnext/templates/generators/item_group.html
index 7dac218..19dc204 100644
--- a/erpnext/templates/generators/item_group.html
+++ b/erpnext/templates/generators/item_group.html
@@ -25,15 +25,17 @@
 	<div>
 		{% if items %}
 		<div id="search-list" {% if not products_as_list -%} class="row" {%- endif %}>
-			{% for item in items %}
-				{{ item }}
+			{% for i in range(0, page_length) %}
+				{% if items[i] %}
+					{{ items[i] }}
+				{% endif %}
 			{% endfor %}
 		</div>
 		<div class="text-center item-group-nav-buttons">
 			{% if frappe.form_dict.start|int > 0 %}
 			<a class="btn btn-default" href="/{{ pathname }}?start={{ frappe.form_dict.start|int - page_length }}">Prev</a>
 			{% endif %}
-			{% if items|length == page_length %}
+			{% if items|length > page_length %}
 			<a class="btn btn-default" href="/{{ pathname }}?start={{ frappe.form_dict.start|int + page_length }}">Next</a>
 			{% endif %}
 		</div>