Merge pull request #7336 from rohitwaghchaure/pos_enhancement_and_issues

[Enhancement] POS features
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index f9516335..c6a8ea1 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.2.2'
+__version__ = '7.2.6'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/budget_account/budget_account.json b/erpnext/accounts/doctype/budget_account/budget_account.json
index 58bb90e..172e092 100644
--- a/erpnext/accounts/doctype/budget_account/budget_account.json
+++ b/erpnext/accounts/doctype/budget_account/budget_account.json
@@ -9,11 +9,13 @@
  "doctype": "DocType", 
  "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "account", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -30,6 +32,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -40,6 +43,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "budget_amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -50,11 +54,13 @@
    "label": "Budget Amount", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -72,7 +78,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-11 03:27:58.705376", 
+ "modified": "2017-01-02 17:02:53.339420", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Budget Account", 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index cd79363..b31a304 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -326,10 +326,12 @@
 			if d.account_currency == self.company_currency:
 				d.exchange_rate = 1
 			elif not d.exchange_rate or d.exchange_rate == 1 or \
-				(d.reference_type in ("Sales Invoice", "Purchase Invoice") and d.reference_name and d.posting_date):
+				(d.reference_type in ("Sales Invoice", "Purchase Invoice") 
+				and d.reference_name and self.posting_date):
+				
 					# Modified to include the posting date for which to retreive the exchange rate
-					d.exchange_rate = get_exchange_rate(self.posting_date, d.account, d.account_currency, self.company,
-						d.reference_type, d.reference_name, d.debit, d.credit, d.exchange_rate)
+					d.exchange_rate = get_exchange_rate(self.posting_date, d.account, d.account_currency, 
+						self.company, d.reference_type, d.reference_name, d.debit, d.credit, d.exchange_rate)
 
 			if not d.exchange_rate:
 				frappe.throw(_("Row {0}: Exchange Rate is mandatory").format(d.idx))
@@ -651,7 +653,8 @@
 	if args.get("party_account"):
 		# Modified to include the posting date for which the exchange rate is required. 
 		# Assumed to be the posting date in the reference document
-		exchange_rate = get_exchange_rate(ref_doc.posting_date, args.get("party_account"), args.get("party_account_currency"),
+		exchange_rate = get_exchange_rate(ref_doc.get("posting_date") or ref_doc.get("transaction_date"), 
+			args.get("party_account"), args.get("party_account_currency"),
 			ref_doc.company, ref_doc.doctype, ref_doc.name)
 
 	je = frappe.new_doc("Journal Entry")
@@ -686,7 +689,8 @@
 		bank_row.update(bank_account)
 		# Modified to include the posting date for which the exchange rate is required. 
 		# Assumed to be the posting date of the reference date
-		bank_row.exchange_rate = get_exchange_rate(ref_doc.posting_date, bank_account["account"],
+		bank_row.exchange_rate = get_exchange_rate(ref_doc.get("posting_date") 
+			or ref_doc.get("transaction_date"), bank_account["account"], 
 			bank_account["account_currency"], ref_doc.company)
 
 	bank_row.cost_center = cost_center
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 9928227..3c62297 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -109,12 +109,16 @@
 
 	item_list = args.get("items")
 	args.pop("items")
+	
+	set_serial_nos_based_on_fifo = frappe.db.get_single_value("Stock Settings", 
+		"automatically_set_serial_nos_based_on_fifo")
 
 	for item in item_list:
 		args_copy = copy.deepcopy(args)
 		args_copy.update(item)
 		out.append(get_pricing_rule_for_item(args_copy))
-		out.append(get_serial_no_for_item(args_copy))
+		if set_serial_nos_based_on_fifo:
+			out.append(get_serial_no_for_item(args_copy))
 	return out
 	
 def get_serial_no_for_item(args):
diff --git a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js
new file mode 100644
index 0000000..1454b2c
--- /dev/null
+++ b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Delivered Items To Be Billed"] = {
+	"filters": [
+
+	]
+}
diff --git a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.json b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.json
index 3432273..f9d830b 100644
--- a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.json
+++ b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.json
@@ -7,7 +7,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-08-18 14:29:50.680329", 
+ "modified": "2017-01-02 16:13:27.369266", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Delivered Items To Be Billed", 
@@ -15,5 +15,5 @@
  "query": "select\n    `tabDelivery Note`.`name` as \"Delivery Note:Link/Delivery Note:120\",\n\t`tabDelivery Note`.`customer` as \"Customer:Link/Customer:120\",\n\t`tabDelivery Note`.`customer_name` as \"Customer Name::150\",\n\t`tabDelivery Note`.`posting_date` as \"Date:Date\",\n\t`tabDelivery Note`.`project` as \"Project\",\n\t`tabDelivery Note Item`.`item_code` as \"Item:Link/Item:120\",\n\t(`tabDelivery Note Item`.`base_amount` - `tabDelivery Note Item`.`billed_amt`*ifnull(`tabDelivery Note`.conversion_rate, 1)) as \"Pending Amount:Currency:110\",\n\t`tabDelivery Note Item`.`item_name` as \"Item Name::150\",\n\t`tabDelivery Note Item`.`description` as \"Description::200\",\n\t`tabDelivery Note`.`company` as \"Company:Link/Company:\"\nfrom `tabDelivery Note`, `tabDelivery Note Item`\nwhere  \n    `tabDelivery Note`.name = `tabDelivery Note Item`.parent \n    and `tabDelivery Note`.docstatus = 1 \n    and `tabDelivery Note`.`status` not in (\"Stopped\", \"Closed\") \n    and `tabDelivery Note Item`.amount > 0\n    and `tabDelivery Note Item`.billed_amt < `tabDelivery Note Item`.amount\norder by `tabDelivery Note`.`name` desc", 
  "ref_doctype": "Sales Invoice", 
  "report_name": "Delivered Items To Be Billed", 
- "report_type": "Query Report"
+ "report_type": "Script Report"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.py b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.py
new file mode 100644
index 0000000..9bf851d
--- /dev/null
+++ b/erpnext/accounts/report/delivered_items_to_be_billed/delivered_items_to_be_billed.py
@@ -0,0 +1,26 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from erpnext.accounts.report.non_billed_report import get_ordered_to_be_billed_data
+
+def execute(filters=None):
+	columns = get_column()
+	args = get_args()
+	data = get_ordered_to_be_billed_data(args)
+	return columns, data
+
+def get_column():
+	return [
+		_("Delivery Note") + ":Link/Delivery Note:120", _("Date") + ":Date:100",
+		_("Suplier") + ":Link/Customer:120", _("Customer Name") + "::120",
+		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", 
+		_("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Pending Amount") + ":Currency:100",
+		_("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120",
+	]
+
+def get_args():
+	return {'doctype': 'Delivery Note', 'party': 'customer', 
+		'date': 'posting_date', 'order': 'name', 'order_by': 'desc'}
\ No newline at end of file
diff --git a/erpnext/accounts/report/non_billed_report.py b/erpnext/accounts/report/non_billed_report.py
new file mode 100644
index 0000000..41ec9b7
--- /dev/null
+++ b/erpnext/accounts/report/non_billed_report.py
@@ -0,0 +1,38 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from erpnext import get_default_currency
+from frappe.model.meta import get_field_precision
+
+def get_ordered_to_be_billed_data(args):
+	doctype, party = args.get('doctype'), args.get('party')
+	child_tab = doctype + " Item"
+	precision = get_field_precision(frappe.get_meta(child_tab).get_field("billed_amt"),
+		currency=get_default_currency()) or 2
+		
+	project_field = get_project_field(doctype, party)
+
+	return frappe.db.sql("""
+		Select
+			`{parent_tab}`.name, `{parent_tab}`.{date_field}, `{parent_tab}`.{party}, `{parent_tab}`.{party}_name,
+			{project_field}, `{child_tab}`.item_code, `{child_tab}`.base_amount,
+			(`{child_tab}`.billed_amt * ifnull(`{parent_tab}`.conversion_rate, 1)), 
+			(`{child_tab}`.base_amount - (`{child_tab}`.billed_amt * ifnull(`{parent_tab}`.conversion_rate, 1))),
+			`{child_tab}`.item_name, `{child_tab}`.description, `{parent_tab}`.company
+		from
+			`{parent_tab}`, `{child_tab}`
+		where
+			`{parent_tab}`.name = `{child_tab}`.parent and `{parent_tab}`.docstatus = 1 and `{parent_tab}`.status != 'Closed'
+			and `{child_tab}`.amount > 0 and round(`{child_tab}`.billed_amt *
+			ifnull(`{parent_tab}`.conversion_rate, 1), {precision}) < `{child_tab}`.base_amount
+		order by
+			`{parent_tab}`.{order} {order_by}
+		""".format(parent_tab = 'tab' + doctype, child_tab = 'tab' + child_tab, precision= precision, party = party,
+			date_field = args.get('date'), project_field = project_field, order= args.get('order'), order_by = args.get('order_by')))
+
+def get_project_field(doctype, party):
+	if party == "supplier": doctype = doctype + ' Item'
+	return "`tab%s`.project"%(doctype)
\ No newline at end of file
diff --git a/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.js b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.js
new file mode 100644
index 0000000..6e13d67
--- /dev/null
+++ b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Ordered Items To Be Billed"] = {
+	"filters": [
+
+	]
+}
diff --git a/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.json b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.json
index 9091aa1..96cf1a3 100644
--- a/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.json
+++ b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.json
@@ -7,7 +7,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-08-18 14:29:50.680329", 
+ "modified": "2017-01-02 14:53:06.277319", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Ordered Items To Be Billed", 
@@ -15,5 +15,5 @@
  "query": "select \n `tabSales Order`.`name` as \"Sales Order:Link/Sales Order:120\",\n `tabSales Order`.`customer` as \"Customer:Link/Customer:120\",\n  `tabSales Order`.`customer_name` as \"Customer Name:150\",\n`tabSales Order`.`status` as \"Status\",\n `tabSales Order`.`transaction_date` as \"Date:Date\",\n `tabSales Order`.`project` as \"Project\",\n `tabSales Order Item`.item_code as \"Item:Link/Item:120\",\n `tabSales Order Item`.base_amount as \"Amount:Currency:110\",\n (`tabSales Order Item`.billed_amt * ifnull(`tabSales Order`.conversion_rate, 1)) as \"Billed Amount:Currency:110\",\n (`tabSales Order Item`.base_amount - (`tabSales Order Item`.billed_amt * ifnull(`tabSales Order`.conversion_rate, 1))) as \"Pending Amount:Currency:120\",\n `tabSales Order Item`.item_name as \"Item Name::150\",\n `tabSales Order Item`.description as \"Description::200\",\n `tabSales Order`.`company` as \"Company:Link/Company:\"\nfrom\n `tabSales Order`, `tabSales Order Item`\nwhere\n `tabSales Order Item`.`parent` = `tabSales Order`.`name`\n and `tabSales Order`.docstatus = 1\n and `tabSales Order`.status != \"Closed\"\n and `tabSales Order Item`.amount > 0\n and `tabSales Order Item`.billed_amt < `tabSales Order Item`.amount\norder by `tabSales Order`.transaction_date asc", 
  "ref_doctype": "Sales Invoice", 
  "report_name": "Ordered Items To Be Billed", 
- "report_type": "Query Report"
+ "report_type": "Script Report"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.py b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.py
new file mode 100644
index 0000000..5765266
--- /dev/null
+++ b/erpnext/accounts/report/ordered_items_to_be_billed/ordered_items_to_be_billed.py
@@ -0,0 +1,26 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from erpnext.accounts.report.non_billed_report import get_ordered_to_be_billed_data
+
+def execute(filters=None):
+	columns = get_column()
+	args = get_args()
+	data = get_ordered_to_be_billed_data(args)
+	return columns, data
+
+def get_column():
+	return [
+		_("Sales Order") + ":Link/Sales Order:120", _("Date") + ":Date:100",
+		_("Suplier") + ":Link/Customer:120", _("Customer Name") + "::120",
+		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", 
+		_("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Pending Amount") + ":Currency:100",
+		_("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120",
+	]
+
+def get_args():
+	return {'doctype': 'Sales Order', 'party': 'customer', 
+		'date': 'transaction_date', 'order': 'transaction_date', 'order_by': 'asc'}
\ No newline at end of file
diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js
new file mode 100644
index 0000000..24c9592
--- /dev/null
+++ b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Purchase Order Items To Be Billed"] = {
+	"filters": [
+
+	]
+}
diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json
index 004c5a9..16ed1be 100644
--- a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json
+++ b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.json
@@ -7,7 +7,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-08-18 15:46:45.789536", 
+ "modified": "2017-01-02 12:08:36.400900", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Order Items To Be Billed", 
@@ -15,5 +15,5 @@
  "query": "select \n    `tabPurchase Order`.`name` as \"Purchase Order:Link/Purchase Order:120\",\n    `tabPurchase Order`.`transaction_date` as \"Date:Date:100\",\n\t`tabPurchase Order`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Order`.`supplier_name` as \"Supplier Name::150\",\n\t`tabPurchase Order Item`.`project` as \"Project\",\n\t`tabPurchase Order Item`.item_code as \"Item Code:Link/Item:120\",\n\t`tabPurchase Order Item`.base_amount as \"Amount:Currency:100\",\n\t(`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1)) as \"Billed Amount:Currency:100\", \n\t(`tabPurchase Order Item`.base_amount - (`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1))) as \"Amount to Bill:Currency:100\",\n\t`tabPurchase Order Item`.item_name as \"Item Name::150\",\n\t`tabPurchase Order Item`.description as \"Description::200\",\n\t`tabPurchase Order`.company as \"Company:Link/Company:\"\nfrom\n\t`tabPurchase Order`, `tabPurchase Order Item`\nwhere\n\t`tabPurchase Order Item`.`parent` = `tabPurchase Order`.`name`\n\tand `tabPurchase Order`.docstatus = 1\n\tand `tabPurchase Order`.status != \"Closed\"\n        and `tabPurchase Order Item`.amount > 0\n\tand (`tabPurchase Order Item`.billed_amt * ifnull(`tabPurchase Order`.conversion_rate, 1)) < `tabPurchase Order Item`.base_amount\norder by `tabPurchase Order`.transaction_date asc", 
  "ref_doctype": "Purchase Invoice", 
  "report_name": "Purchase Order Items To Be Billed", 
- "report_type": "Query Report"
+ "report_type": "Script Report"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py
new file mode 100644
index 0000000..5aed93d
--- /dev/null
+++ b/erpnext/accounts/report/purchase_order_items_to_be_billed/purchase_order_items_to_be_billed.py
@@ -0,0 +1,26 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from erpnext.accounts.report.non_billed_report import get_ordered_to_be_billed_data
+
+def execute(filters=None):
+	columns = get_column()
+	args = get_args()
+	data = get_ordered_to_be_billed_data(args)
+	return columns, data
+
+def get_column():
+	return [
+		_("Purchase Order") + ":Link/Purchase Order:120", _("Date") + ":Date:100",
+		_("Suplier") + ":Link/Supplier:120", _("Suplier Name") + "::120",
+		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", 
+		_("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Amount to Bill") + ":Currency:100",
+		_("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120",
+	]
+
+def get_args():
+	return {'doctype': 'Purchase Order', 'party': 'supplier', 
+		'date': 'transaction_date', 'order': 'transaction_date', 'order_by': 'asc'}
diff --git a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js
new file mode 100644
index 0000000..0ee3f57
--- /dev/null
+++ b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Received Items To Be Billed"] = {
+	"filters": [
+
+	]
+}
diff --git a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.json b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.json
index 00964c0..0379a5c 100644
--- a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.json
+++ b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.json
@@ -7,7 +7,7 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-08-18 14:32:20.965816", 
+ "modified": "2017-01-02 16:05:01.929390", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Received Items To Be Billed", 
@@ -15,5 +15,5 @@
  "query": "select\n    `tabPurchase Receipt`.`name` as \"Purchase Receipt:Link/Purchase Receipt:120\",\n    `tabPurchase Receipt`.`supplier` as \"Supplier:Link/Supplier:120\",\n\t`tabPurchase Receipt`.`supplier_name` as \"Supplier Name::150\",\n\t`tabPurchase Receipt`.`posting_date` as \"Date:Date\",\n\t`tabPurchase Receipt Item`.`project` as \"Project\",\n\t`tabPurchase Receipt Item`.`item_code` as \"Item:Link/Item:120\",\n\t(`tabPurchase Receipt Item`.`base_amount` - `tabPurchase Receipt Item`.`billed_amt`*ifnull(`tabPurchase Receipt`.conversion_rate, 1)) as \"Pending Amount:Currency:110\",\n\t`tabPurchase Receipt Item`.`item_name` as \"Item Name::150\",\n\t`tabPurchase Receipt Item`.`description` as \"Description::200\",\n\t`tabPurchase Receipt`.`company` as \"Company:Link/Company:\"\nfrom `tabPurchase Receipt`, `tabPurchase Receipt Item`\nwhere\n    `tabPurchase Receipt`.name = `tabPurchase Receipt Item`.parent \n    and `tabPurchase Receipt`.docstatus = 1 \n    and `tabPurchase Receipt`.status != \"Closed\" \n    and `tabPurchase Receipt Item`.amount > 0\n    and `tabPurchase Receipt Item`.billed_amt < `tabPurchase Receipt Item`.amount\norder by `tabPurchase Receipt`.`name` desc", 
  "ref_doctype": "Purchase Invoice", 
  "report_name": "Received Items To Be Billed", 
- "report_type": "Query Report"
+ "report_type": "Script Report"
 }
\ No newline at end of file
diff --git a/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py
new file mode 100644
index 0000000..2ab3053c
--- /dev/null
+++ b/erpnext/accounts/report/received_items_to_be_billed/received_items_to_be_billed.py
@@ -0,0 +1,26 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from erpnext.accounts.report.non_billed_report import get_ordered_to_be_billed_data
+
+def execute(filters=None):
+	columns = get_column()
+	args = get_args()
+	data = get_ordered_to_be_billed_data(args)
+	return columns, data
+
+def get_column():
+	return [
+		_("Purchase Receipt") + ":Link/Purchase Receipt:120", _("Date") + ":Date:100",
+		_("Suplier") + ":Link/Supplier:120", _("Suplier Name") + "::120",
+		_("Project") + ":Link/Project:120", _("Item Code") + ":Link/Item:120", 
+		_("Amount") + ":Currency:100", _("Billed Amount") + ":Currency:100", _("Amount to Bill") + ":Currency:100",
+		_("Item Name") + "::120", _("Description") + "::120", _("Company") + ":Link/Company:120",
+	]
+
+def get_args():
+	return {'doctype': 'Purchase Receipt', 'party': 'supplier', 
+		'date': 'posting_date', 'order': 'name', 'order_by': 'desc'}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 5c836df..fbf86e1 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -217,7 +217,7 @@
 
 	def validate_attendance(self):
 		attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s and (att_date between %s and %s)
-					and docstatus = 1""",
+					and status = "Present" and docstatus = 1""",
 			(self.employee, self.from_date, self.to_date))
 		if attendance:
 			frappe.throw(_("Attendance for employee {0} is already marked for this day").format(self.employee),
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js
index 6d9111f..a879b39 100644
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js
+++ b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js
@@ -4,19 +4,18 @@
 frappe.query_reports["Monthly Salary Register"] = {
 	"filters": [
 		{
-			"fieldname":"month",
-			"label": __("Month"),
-			"fieldtype": "Select",
-			"options": "\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec",
-			"default": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", 
-				"Dec"][frappe.datetime.str_to_obj(frappe.datetime.get_today()).getMonth()],
+			"fieldname":"from_date",
+			"label": __("From"),
+			"fieldtype": "Date",
+			"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
+			"reqd": 1
 		},
 		{
-			"fieldname":"fiscal_year",
-			"label": __("Fiscal Year"),
-			"fieldtype": "Link",
-			"options": "Fiscal Year",
-			"default": sys_defaults.fiscal_year,
+			"fieldname":"to_date",
+			"label": __("To"),
+			"fieldtype": "Date",
+			"default": frappe.datetime.get_today(),
+			"reqd": 1
 		},
 		{
 			"fieldname":"employee",
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
index 1e9d03e..e8d0a0b 100644
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
+++ b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
@@ -18,7 +18,7 @@
 	data = []
 	for ss in salary_slips:
 		row = [ss.name, ss.employee, ss.employee_name, ss.branch, ss.department, ss.designation,
-			ss.company, ss.month, ss.leave_withut_pay, ss.payment_days]
+			ss.company, ss.start_date, ss.end_date, ss.leave_withut_pay, ss.payment_days]
 
 		for e in earning_types:
 			row.append(ss_earning_map.get(ss.name, {}).get(e))
@@ -38,7 +38,7 @@
 	columns = [
 		_("Salary Slip ID") + ":Link/Salary Slip:150",_("Employee") + ":Link/Employee:120", _("Employee Name") + "::140", _("Branch") + ":Link/Branch:120",
 		_("Department") + ":Link/Department:120", _("Designation") + ":Link/Designation:120",
-		_("Company") + ":Link/Company:120", _("Month") + "::80", _("Leave Without Pay") + ":Float:130",
+		_("Company") + ":Link/Company:120", _("Start Date") + "::80", _("End Date") + "::80", _("Leave Without Pay") + ":Float:130",
 		_("Payment Days") + ":Float:120"
 	]
 
@@ -60,23 +60,18 @@
 def get_salary_slips(filters):
 	conditions, filters = get_conditions(filters)
 	salary_slips = frappe.db.sql("""select * from `tabSalary Slip` where docstatus = 1 %s
-		order by employee, month""" % conditions, filters, as_dict=1)
+		order by employee""" % conditions, filters, as_dict=1)
 
 	if not salary_slips:
-		frappe.throw(_("No salary slip found for month {0} and year {1}").format(
-			filters.get("month"), filters.get("fiscal_year")))
+		frappe.throw(_("No salary slip found between {0} and {1}").format(
+			filters.get("from_date"), filters.get("to_date")))
 
 	return salary_slips
 
 def get_conditions(filters):
 	conditions = ""
-	if filters.get("month"):
-		month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
-			"Dec"].index(filters["month"]) + 1
-		filters["month"] = month
-		conditions += " and month = %(month)s"
-
-	if filters.get("fiscal_year"): conditions += " and fiscal_year = %(fiscal_year)s"
+	if filters.get("from_date"): conditions += " and start_date >= %(from_date)s"
+	if filters.get("to_date"): conditions += " and end_date <= %(to_date)s"
 	if filters.get("company"): conditions += " and company = %(company)s"
 	if filters.get("employee"): conditions += " and employee = %(employee)s"
 
diff --git a/erpnext/patches/v7_1/save_stock_settings.py b/erpnext/patches/v7_1/save_stock_settings.py
index 83c27dc..d3f0263 100644
--- a/erpnext/patches/v7_1/save_stock_settings.py
+++ b/erpnext/patches/v7_1/save_stock_settings.py
@@ -3,5 +3,13 @@
 
 def execute():
 	stock_settings = frappe.get_doc('Stock Settings')
+	
+	if stock_settings.default_warehouse \
+		and not frappe.db.exists("Warehouse", stock_settings.default_warehouse):
+			stock_settings.default_warehouse = None
+			
+	if stock_settings.stock_uom and not frappe.db.exists("UOM", stock_settings.stock_uom):
+		stock_settings.stock_uom = None
+		
 	stock_settings.flags.ignore_mandatory = True
 	stock_settings.save()
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index dcbb56b..799730e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -349,7 +349,7 @@
 						me.frm.set_value("letter_head", company_doc.default_letter_head);
 					}
 				}
-				if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice") {
+				if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice" && frappe.meta.has_field(me.frm.doc.doctype, "tc_name")) {
 					me.frm.set_value("tc_name", company_doc.default_terms);
 				}
 
diff --git a/erpnext/setup/doctype/sms_settings/sms_settings.py b/erpnext/setup/doctype/sms_settings/sms_settings.py
index 681237f..ddfc045 100644
--- a/erpnext/setup/doctype/sms_settings/sms_settings.py
+++ b/erpnext/setup/doctype/sms_settings/sms_settings.py
@@ -77,7 +77,7 @@
 	for d in arg.get('receiver_list'):
 		args[ss.receiver_parameter] = d
 		status = send_request(ss.sms_gateway_url, args)
-		if status > 200 and status < 300:
+		if status >= 200 and status < 300:
 			success_list.append(d)
 
 	if len(success_list) > 0:
diff --git a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
index d2b68b4..37f114b 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -9,7 +9,8 @@
 
 class TermsandConditions(Document):
 	def validate(self):
-		validate_template(self.terms)
+		if self.terms:
+			validate_template(self.terms)
 
 @frappe.whitelist()
 def get_terms_and_conditions(template_name, doc):
diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.js b/erpnext/stock/doctype/quality_inspection/quality_inspection.js
index 5d7b6b4..53579fb 100644
--- a/erpnext/stock/doctype/quality_inspection/quality_inspection.js
+++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.js
@@ -9,7 +9,7 @@
 		return {
 			query: "erpnext.stock.doctype.quality_inspection.quality_inspection.item_query",
 			filters: {
-				"from": doc.reference_type,
+				"from": doc.reference_type + " Item",
 				"parent": doc.reference_name
 			}
 		}
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 4ab49e5..ba303bb 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -237,7 +237,7 @@
 		elif not frappe.db.sql("""select name from `tabStock Ledger Entry` limit 1"""):
 			if frappe.db.get_value("Account", self.expense_account, "report_type") == "Profit and Loss":
 				frappe.throw(_("Difference Account must be a Asset/Liability type account, since this Stock Reconciliation is an Opening Entry"), OpeningEntryAccountError)
-				
+
 	def set_total_qty_and_amount(self):
 		for d in self.get("items"):
 			d.amount = flt(d.qty) * flt(d.valuation_rate)
@@ -267,7 +267,8 @@
 	items = frappe.get_list("Bin", fields=["item_code"], filters={"warehouse": warehouse}, as_list=1)
 
 	items += frappe.get_list("Item", fields=["name"], filters= {"is_stock_item": 1, "has_serial_no": 0,
-		"has_batch_no": 0, "has_variants": 0, "disabled": 0, "default_warehouse": warehouse}, as_list=1)
+		"has_batch_no": 0, "has_variants": 0, "disabled": 0, "default_warehouse": warehouse},
+			as_list=1)
 
 	res = []
 	for item in set(items):
@@ -280,6 +281,7 @@
 				"item_code": item[0],
 				"warehouse": warehouse,
 				"qty": stock_bal[0],
+				"item_name": frappe.db.get_value('Item', item[0], 'item_name'),
 				"valuation_rate": stock_bal[1],
 				"current_qty": stock_bal[0],
 				"current_valuation_rate": stock_bal[1]