Demo records for Projects+Tasks+Billing, pos invoice
diff --git a/erpnext/demo/setup_data.py b/erpnext/demo/setup_data.py
index 918fd54..3367527 100644
--- a/erpnext/demo/setup_data.py
+++ b/erpnext/demo/setup_data.py
@@ -32,9 +32,11 @@
 	setup_employee()
 	setup_salary_structure()
 	setup_salary_structure_for_timesheet()
+	setup_mode_of_payment()
 	setup_account_to_expense_type()
 	setup_user_roles()
 	setup_budget()
+	setup_pos_profile()
 	frappe.db.commit()
 	frappe.clear_cache()
 
@@ -316,6 +318,18 @@
 		ss_doc.hour_rate = flt(random.random() * 10, 2)
 		ss_doc.save(ignore_permissions=True)
 
+def setup_mode_of_payment():
+	account_dict = {'Cash': 'Cash - WPL', 'Bank': 'National Bank - WPL'}
+	for payment_mode in frappe.get_all('Mode of Payment', fields = ["name", "type"]):
+		if payment_mode.type:
+			mop = frappe.get_doc('Mode of Payment', payment_mode.name)
+			mop.append('accounts', {
+				'company': erpnext.get_default_company(),
+				'default_account': account_dict.get(payment_mode.type)
+			})
+
+			mop.save(ignore_permissions=True)
+
 def setup_account():
 	frappe.flags.in_import = True
 	data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data',
@@ -402,3 +416,17 @@
 		user.add_roles('HR User', 'Projects User')
 		frappe.db.set_global('demo_projects_user', user.name)
 
+def setup_pos_profile():
+	pos = frappe.new_doc('POS Profile')
+	pos.user = frappe.db.get_global('demo_accounts_user')
+	pos.naming_series = 'SINV-'
+	pos.update_stock = 0
+	pos.write_off_account = 'Cost of Goods Sold - WPL'
+	pos.write_off_cost_center = 'Main - WPL'
+
+	pos.append('payments', {
+		'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'),
+		'amount': 0.0
+	})
+
+	pos.insert()
diff --git a/erpnext/demo/user/accounts.py b/erpnext/demo/user/accounts.py
index 052d456..045c306 100644
--- a/erpnext/demo/user/accounts.py
+++ b/erpnext/demo/user/accounts.py
@@ -12,12 +12,14 @@
 from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
 from frappe.utils.make_random import get_random
 from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request, make_payment_entry
+from erpnext.demo.user.sales import make_sales_order
+from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
+from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
 
 def work():
 	frappe.set_user(frappe.db.get_global('demo_accounts_user'))
 
 	if random.random() <= 0.6:
-		from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
 		report = "Ordered Items to be Billed"
 		for so in list(set([r[0] for r in query_report.run(report)["result"]
 				if r[0]!="Total"]))[:random.randint(1, 5)]:
@@ -31,7 +33,6 @@
 			frappe.db.commit()
 
 	if random.random() <= 0.6:
-		from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
 		report = "Received Items to be Billed"
 		for pr in list(set([r[0] for r in query_report.run(report)["result"]
 			if r[0]!="Total"]))[:random.randint(1, 5)]:
@@ -61,6 +62,8 @@
 				payment_entry.posting_date = frappe.flags.current_date
 				payment_entry.submit()
 
+	make_pos_invoice()
+
 def make_payment_entries(ref_doctype, report):
 	outstanding_invoices = list(set([r[3] for r in query_report.run(report,
 	{"report_date": frappe.flags.current_date })["result"] if r[2]==ref_doctype]))
@@ -75,7 +78,7 @@
 		pe.submit()
 		frappe.db.commit()
 		outstanding_invoices.remove(inv)
-		
+
 	# make payment via JV
 	for inv in outstanding_invoices[:1]:
 		jv = frappe.get_doc(get_payment_entry_against_invoice(ref_doctype, inv))
@@ -85,3 +88,24 @@
 		jv.insert()
 		jv.submit()
 		frappe.db.commit()
+
+def make_pos_invoice():
+	make_sales_order()
+
+	for data in frappe.get_all('Sales Order', fields=["name"],
+		filters = [["per_billed", "<", "100"]]):
+		si = frappe.get_doc(make_sales_invoice(data.name))
+		si.is_pos =1
+		si.posting_date = frappe.flags.current_date
+		for d in si.get("items"):
+			if not d.income_account:
+				d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr'))
+		si.set_missing_values()
+		make_payment_entries_for_pos_invoice(si)
+		si.insert()
+		si.submit()
+
+def make_payment_entries_for_pos_invoice(si):
+	for data in si.payments:
+		data.amount = si.outstanding_amount
+		return
diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py
index 219fa20..28966ec 100644
--- a/erpnext/demo/user/hr.py
+++ b/erpnext/demo/user/hr.py
@@ -108,6 +108,7 @@
 	salary_slip = make_salary_slip(name)
 	salary_slip.insert()
 	salary_slip.submit()
+	frappe.db.commit()
 
 def make_sales_invoice_for_timesheet(name):
 	sales_invoice = make_sales_invoice(name)
@@ -117,7 +118,9 @@
 		'qty': 1,
 		'rate': 1000
 	})
+	sales_invoice.flags.ignore_permissions = 1
 	sales_invoice.set_missing_values()
 	sales_invoice.calculate_taxes_and_totals()
 	sales_invoice.insert()
-	sales_invoice.submit()
\ No newline at end of file
+	sales_invoice.submit()
+	frappe.db.commit()
\ No newline at end of file
diff --git a/erpnext/demo/user/projects.py b/erpnext/demo/user/projects.py
index 12fad29..e7febd0 100644
--- a/erpnext/demo/user/projects.py
+++ b/erpnext/demo/user/projects.py
@@ -4,9 +4,11 @@
 from __future__ import unicode_literals
 
 import frappe
+from frappe.utils import flt
 from frappe.utils.make_random import can_make
 from frappe.utils.make_random import how_many, get_random
 from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
+from erpnext.demo.user.hr import make_sales_invoice_for_timesheet
 
 def run_projects(current_date):
 	frappe.set_user(frappe.db.get_global('demo_projects_user'))
@@ -19,9 +21,13 @@
 	for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}):
 		employee = get_random("Employee")
 		if frappe.db.get_value('Salary Structure', {'employee': employee}, 'salary_slip_based_on_timesheet'):
-			make_timesheet(employee, simulate = True, billable = 1, 
+			ts = make_timesheet(employee, simulate = True, billable = 1,
 				activity_type=get_random("Activity Type"), project=data.project, task =data.name)
 
+			if flt(ts.total_billing_amount) > 0.0:
+				make_sales_invoice_for_timesheet(ts.name)
+				frappe.db.commit()
+
 def close_tasks(current_date):
 	for task in frappe.get_all("Task", ["name"], {"status": "Open", "exp_end_date": ("<", current_date)}):
 		task = frappe.get_doc("Task", task.name)