Merge pull request #14740 from manassolanki/fix-20

[minor] fix for the args in the frm.call
diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md
new file mode 100644
index 0000000..aa3a104
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,68 @@
+---
+name: Bug report
+about: Create a report to help us improve
+
+---
+
+Issue: Bug report
+
+Our project, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
+
+**Do the checklist before filing an issue:**
+ - [ ] Have a usage question? Ask your question on  [Discuss Forum](https://discuss.erpnext.com). We use [Discuss Forum](https://discuss.erpnext.com) for usage question and GitHub for bugs.
+ - [ ] Can you replicate the issue? 
+ - [ ] Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome
+
+**Describe the bug** :chart_with_downwards_trend: 
+A clear and concise description of what the bug is.
+
+**To Reproduce** :page_with_curl:
+Steps to reproduce the behavior:
+1. Go to '...'
+2. Click on '....'
+3. Scroll down to '....'
+4. See error
+
+**Expected behavior** :chart_with_upwards_trend:
+A clear and concise description of what you expected to happen.
+
+**Screenshots** :crystal_ball:
+If applicable, add screenshots to help explain your problem.
+
+**Desktop (please complete the following information):** :cyclone:
+ - OS:
+    - [ ] Linux
+    - [ ] macOS
+    - [ ] Windows
+    - [ ] Others? Please mention: 
+ - Browser:
+    - [ ] Safari
+    - [ ] Chrome
+    - [ ] Firefox
+    - [ ] Other? Please mention: 
+
+**Smartphone (please complete the following information):** :iphone: :computer:
+ - Device:
+    - [ ] iPhone
+    - [ ] Android
+ - Browser:
+    - [ ] Safari
+    - [ ] Chrome
+    - [ ] Firefox
+    - [ ] Other? Please mention: 
+
+**Version Information**
+- Which branch are you on?
+    - [ ] `master` :star2: 
+    - [ ] `develop` :fire:
+- Frappe Version: 
+- ERPNext Version: 
+
+**Additional context** :page_facing_up:
+Add any other context about the problem here.
+
+**Possible Solution** :bookmark_tabs:
+Any idea what might be causing the issue. Or if you have a proposed solution to the problem,
+
+**Please don't be intimidated by the long list of options you've fill. Try to fill out as much as you can. Remember, the more the information the easier it is for us to replicate and fix the issue** :grin: 
+
diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md
new file mode 100644
index 0000000..e09e5e9
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,21 @@
+---
+name: Feature request
+about: Suggest an idea for this project
+
+---
+
+Issue: Feature Request
+
+**Is your feature request related to a problem? Please describe.**
+A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+
+**Describe the solution you'd like**
+A clear and concise description of what you want to happen.
+
+**Describe alternatives you've considered**
+A clear and concise description of any alternative solutions or features you've considered.
+
+**Additional context**
+Add any other context or screenshots about the feature request here.
+
+
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..8e2bd85
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,28 @@
+Pull-Request
+
+- [ ] Have you followed the guidelines in our Contributing document?
+- [ ] Have you checked to ensure there aren't other open [Pull Requests](../pulls) for the same update/change?
+- [ ] Have you lint your code locally prior to submission?
+- [ ] Have you successfully run tests with your changes locally?
+- [ ] Does your commit message have an explanation for your changes and why you'd like us to include them?
+- [ ] Docs have been added / updated
+- [ ] Tests for the changes have been added (for bug fixes / features)
+- [ ] Did you modify the existing test cases? If yes, why?
+
+---
+
+What type of a PR is this? 
+
+- [ ] Changes to Existing Features
+- [ ] New Feature Submissions
+- [ ] Bug Fix
+- [ ] Breaking Change
+
+--- 
+
+- Motivation and Context (What existing problem does the pull request solve):
+- Related Issue: 
+- Screenshots (if applicable, remember, a picture tells a thousand words): 
+
+**Please don't be intimidated by the long list of options you've fill. Try to fill out as much as you can. Remember, the more the information the easier it is for us to test and get your pull request merged** :grin: 
+
diff --git a/.gitignore b/.gitignore
index 0d39ab2..dcdefa2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@
 *.egg-info
 dist/
 erpnext/docs/current
+*.swp
diff --git a/.swp b/.swp
deleted file mode 100644
index 5a492bd..0000000
--- a/.swp
+++ /dev/null
Binary files differ
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index 3eaf994..4940522 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '10.1.33'
+__version__ = '10.1.40'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 776bacf..940a709 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -588,6 +588,10 @@
 	allocate_party_amount_against_ref_docs: function(frm, paid_amount) {
 		var total_positive_outstanding_including_order = 0;
 		var total_negative_outstanding = 0;
+		var total_deductions = frappe.utils.sum($.map(frm.doc.deductions || [],
+			function(d) { return flt(d.amount) }));
+
+		paid_amount -= total_deductions;
 
 		$.each(frm.doc.references || [], function(i, row) {
 			if(flt(row.outstanding_amount) > 0)
@@ -815,23 +819,30 @@
 
 	reference_name: function(frm, cdt, cdn) {
 		var row = locals[cdt][cdn];
-		return frappe.call({
-			method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_reference_details",
-			args: {
-				reference_doctype: row.reference_doctype,
-				reference_name: row.reference_name,
-				party_account_currency: frm.doc.payment_type=="Receive" ?
-					frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
-			},
-			callback: function(r, rt) {
-				if(r.message) {
-					$.each(r.message, function(field, value) {
-						frappe.model.set_value(cdt, cdn, field, value);
-					})
-					frm.refresh_fields();
+		if (row.reference_name && row.reference_doctype) {
+			return frappe.call({
+				method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_reference_details",
+				args: {
+					reference_doctype: row.reference_doctype,
+					reference_name: row.reference_name,
+					party_account_currency: frm.doc.payment_type=="Receive" ?
+						frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency
+				},
+				callback: function(r, rt) {
+					if(r.message) {
+						$.each(r.message, function(field, value) {
+							frappe.model.set_value(cdt, cdn, field, value);
+						})
+
+						let allocated_amount = frm.doc.unallocated_amount > row.outstanding_amount ?
+							row.outstanding_amount : frm.doc.unallocated_amount;
+
+						frappe.model.set_value(cdt, cdn, 'allocated_amount', allocated_amount);
+						frm.refresh_fields();
+					}
 				}
-			}
-		})
+			})
+		}
 	},
 
 	allocated_amount: function(frm) {
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 2f8e6b8..9d5adda 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -337,14 +337,15 @@
 			total_negative_outstanding = sum([abs(flt(d.outstanding_amount))
 				for d in self.get("references") if flt(d.outstanding_amount) < 0])
 
-			party_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount
+			paid_amount = self.paid_amount if self.payment_type=="Receive" else self.received_amount
+			additional_charges = sum([flt(d.amount) for d in self.deductions])
 
 			if not total_negative_outstanding:
 				frappe.throw(_("Cannot {0} {1} {2} without any negative outstanding invoice")
 					.format(self.payment_type, ("to" if self.party_type=="Customer" else "from"),
 						self.party_type), InvalidPaymentEntry)
 
-			elif party_amount > total_negative_outstanding:
+			elif paid_amount - additional_charges > total_negative_outstanding:
 				frappe.throw(_("Paid Amount cannot be greater than total negative outstanding amount {0}")
 					.format(total_negative_outstanding), InvalidPaymentEntry)
 
@@ -724,8 +725,11 @@
 			exchange_rate = ref_doc.get("conversion_rate") or \
 				get_exchange_rate(party_account_currency, company_currency, ref_doc.posting_date)
 
-		if reference_doctype in ("Sales Invoice", "Purchase Invoice", "Expense Claim"):
+		if reference_doctype in ("Sales Invoice", "Purchase Invoice"):
 			outstanding_amount = ref_doc.get("outstanding_amount")
+		elif reference_doctype == "Expense Claim":
+			outstanding_amount = flt(ref_doc.get("total_sanctioned_amount")) \
+				- flt(ref_doc.get("total_amount+reimbursed")) - flt(ref_doc.get("total_advance_amount"))
 		elif reference_doctype == "Employee Advance":
 			outstanding_amount = ref_doc.advance_amount - flt(ref_doc.paid_amount)
 		else:
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
index f282afe..b940a6a 100755
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
@@ -3410,6 +3410,65 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Group same items",
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 0,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "column_break_112",
+   "fieldtype": "Column Break",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 0,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 1,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
    "fieldname": "select_print_heading", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -3914,7 +3973,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-12-20 17:49:51.230092", 
+ "modified": "2018-05-28 02:38:40.310899",
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice", 
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 5b52bbb..a033bb0 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -3742,12 +3742,12 @@
   },
   {
    "allow_bulk_edit": 0,
-   "allow_on_submit": 0,
+   "allow_on_submit": 1,
    "bold": 0,
    "collapsible": 0,
    "columns": 0,
-   "fieldname": "language",
-   "fieldtype": "Data",
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
    "hidden": 0,
    "ignore_user_permissions": 0,
    "ignore_xss_filter": 0,
@@ -3755,14 +3755,14 @@
    "in_global_search": 0,
    "in_list_view": 0,
    "in_standard_filter": 0,
-   "label": "Print Language",
+   "label": "Group same items",
    "length": 0,
    "no_copy": 0,
    "permlevel": 0,
    "precision": "",
    "print_hide": 1,
    "print_hide_if_no_value": 0,
-   "read_only": 1,
+   "read_only": 0,
    "remember_last_selected_value": 0,
    "report_hide": 0,
    "reqd": 0,
@@ -3835,6 +3835,36 @@
    "allow_bulk_edit": 0,
    "allow_on_submit": 0,
    "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "language",
+   "fieldtype": "Data",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Print Language",
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 1,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 0,
+   "bold": 0,
    "collapsible": 1,
    "columns": 0,
    "depends_on": "customer",
@@ -4683,7 +4713,7 @@
  "istable": 0,
  "max_attachments": 0,
  "menu_index": 0,
- "modified": "2018-03-16 15:19:54.711885",
+ "modified": "2018-05-28 04:47:29.879475",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Sales Invoice",
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 7fc0f67..8ab25a3 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -404,10 +404,21 @@
 	from frappe.desk.form.load import get_communication_data
 
 	out = {}
+	fields = 'date(creation), count(name)'
+	after = add_years(None, -1).strftime('%Y-%m-%d')
+	group_by='group by date(creation)'
+
 	data = get_communication_data(doctype, name,
-		fields = 'date(creation), count(name)',
-		after = add_years(None, -1).strftime('%Y-%m-%d'),
-		group_by='group by date(creation)', as_dict=False)
+		fields=fields, after=after, group_by=group_by, as_dict=False)
+
+	# fetch and append data from Activity Log
+	data += frappe.db.sql("""select {fields}
+		from `tabActivity Log`
+		where reference_doctype="{doctype}" and reference_name="{name}"
+		and status!='Success' and creation > {after}
+		{group_by} order by creation desc
+		""".format(doctype=frappe.db.escape(doctype), name=frappe.db.escape(name), fields=fields,
+			group_by=group_by, after=after), as_dict=False)
 
 	timeline_items = dict(data)
 
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index f722e7f..0befa5d 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -286,7 +286,10 @@
 
 		if party_type == "Supplier":
 			for pi in frappe.db.sql("""select name, due_date, bill_no, bill_date
-				from `tabPurchase Invoice` where docstatus=1""", as_dict=1):
+				from `tabPurchase Invoice` where docstatus = 1
+				union
+				select name, due_date, bill_no, bill_date from `tabJournal Entry`
+				where docstatus = 1 and bill_no is not NULL""", as_dict=1):
 					voucher_details.setdefault(pi.name, pi)
 
 		return voucher_details
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 3dc4fd7..6977512 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -71,8 +71,8 @@
 			if gle_currency:
 				account_currency = gle_currency
 			else:
-				account_currency = None if filters.party_type in ["Employee", "Student", "Shareholder"] else \
-					frappe.db.get_value(filters.party_type, filters.party, "default_currency")
+				account_currency = (None if filters.party_type in ["Employee", "Student", "Shareholder", "Member"] else
+					frappe.db.get_value(filters.party_type, filters.party, "default_currency"))
 
 		filters["account_currency"] = account_currency or filters.company_currency
 
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index 710099e..72661ff 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -49,7 +49,7 @@
 
 		row += [
 			d.credit_to, d.mode_of_payment, d.project, d.company, d.purchase_order,
-			purchase_receipt, expense_account, d.stock_qty, d.stock_uom, d.base_net_rate, d.base_net_amount
+			purchase_receipt, expense_account, d.stock_qty, d.stock_uom, d.base_net_amount / d.stock_qty, d.base_net_amount
 		]
 
 		total_tax = 0
@@ -120,8 +120,7 @@
 			`tabPurchase Invoice Item`.`project`, `tabPurchase Invoice Item`.`purchase_order`,
 			`tabPurchase Invoice Item`.`purchase_receipt`, `tabPurchase Invoice Item`.`po_detail`,
 			`tabPurchase Invoice Item`.`expense_account`, `tabPurchase Invoice Item`.`stock_qty`,
-			`tabPurchase Invoice Item`.`stock_uom`, `tabPurchase Invoice Item`.`base_net_rate`,
-			`tabPurchase Invoice Item`.`base_net_amount`,
+			`tabPurchase Invoice Item`.`stock_uom`, `tabPurchase Invoice Item`.`base_net_amount`,
 			`tabPurchase Invoice`.supplier_name, `tabPurchase Invoice`.mode_of_payment {0}
 		from `tabPurchase Invoice`, `tabPurchase Invoice Item`
 		where `tabPurchase Invoice`.name = `tabPurchase Invoice Item`.`parent` and
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index ac9f4ce..e6216b5 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -53,7 +53,7 @@
 			delivery_note, d.income_account, d.cost_center, d.stock_qty, d.stock_uom
 		]
 
-		row += [d.base_net_rate/d.stock_qty, d.base_net_amount] \
+		row += [(d.base_net_rate * d.qty)/d.stock_qty, d.base_net_amount] \
 			if d.stock_uom != d.uom else [d.base_net_rate, d.base_net_amount]
 
 		total_tax = 0
@@ -133,7 +133,7 @@
 			`tabSales Invoice Item`.stock_uom, `tabSales Invoice Item`.base_net_rate,
 			`tabSales Invoice Item`.base_net_amount, `tabSales Invoice`.customer_name,
 			`tabSales Invoice`.customer_group, `tabSales Invoice Item`.so_detail,
-			`tabSales Invoice`.update_stock, `tabSales Invoice Item`.uom {0}
+			`tabSales Invoice`.update_stock, `tabSales Invoice Item`.uom, `tabSales Invoice Item`.qty {0}
 		from `tabSales Invoice`, `tabSales Invoice Item`
 		where `tabSales Invoice`.name = `tabSales Invoice Item`.parent
 			and `tabSales Invoice`.docstatus = 1 %s %s
diff --git a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
index bdf9054..48757e8 100644
--- a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
+++ b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.json
@@ -3,7 +3,7 @@
  "allow_guest_to_view": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
- "autoname": "field:maintenance_task", 
+ "autoname": "", 
  "beta": 0, 
  "creation": "2017-10-20 07:10:55.903571", 
  "custom": 0, 
@@ -42,7 +42,7 @@
    "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
-   "unique": 1
+   "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
@@ -625,7 +625,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-11-28 12:22:34.151430", 
+ "modified": "2018-06-18 16:12:04.330021", 
  "modified_by": "Administrator", 
  "module": "Assets", 
  "name": "Asset Maintenance Task", 
diff --git a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.py b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.py
index 2a5666d..d98cc31 100644
--- a/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.py
+++ b/erpnext/assets/doctype/asset_maintenance_task/asset_maintenance_task.py
@@ -7,4 +7,5 @@
 from frappe.model.document import Document
 
 class AssetMaintenanceTask(Document):
-	pass
+	def autoname(self):
+		self.name = self.maintenance_task
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
index b94710f..ad47d52 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.json
@@ -2177,6 +2177,65 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Group same items",
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 0,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "column_break_72",
+   "fieldtype": "Column Break",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 0,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 1,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
    "fieldname": "letter_head", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -2490,7 +2549,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-11-29 14:07:56.698355", 
+ "modified": "2018-05-28 02:45:48.616334",
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier Quotation", 
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 4cca720..58073bc 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -82,7 +82,8 @@
 			self.validate_non_invoice_documents_schedule()
 
 	def before_print(self):
-		if self.doctype in ['Purchase Order', 'Sales Order']:
+		if self.doctype in ['Purchase Order', 'Sales Order', 'Sales Invoice', 'Purchase Invoice',
+			'Supplier Quotation', 'Purchase Receipt', 'Delivery Note', 'Quotation']:
 			if self.get("group_same_items"):
 				self.group_similar_items()
 
@@ -663,6 +664,7 @@
 			if item.item_code in group_item_qty:
 				item.qty = group_item_qty[item.item_code]
 				item.amount = group_item_amount[item.item_code]
+				item.rate = flt(flt(item.amount)/flt(item.qty), item.precision("rate"))
 				del group_item_qty[item.item_code]
 			else:
 				duplicate_list.append(item)
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 4b7b43c..38beccd 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -35,6 +35,7 @@
 		if getattr(self, "supplier", None) and not self.supplier_name:
 			self.supplier_name = frappe.db.get_value("Supplier", self.supplier, "supplier_name")
 
+		self.validate_items()
 		self.set_qty_as_per_stock_uom()
 		self.validate_stock_or_nonstock_items()
 		self.validate_warehouse()
@@ -456,3 +457,32 @@
 		else:
 			frappe.throw(_("Please enter Reqd by Date"))
 
+	def validate_items(self):
+		# validate items to see if they have is_purchase_item or is_subcontracted_item enabled
+		if self.doctype=="Material Request": return
+
+		if hasattr(self, "is_subcontracted") and self.is_subcontracted == 'Yes':
+			validate_item_type(self, "is_sub_contracted_item", "subcontracted")
+		else:
+			validate_item_type(self, "is_purchase_item", "purchase")
+
+def validate_item_type(doc, fieldname, message):
+	# iterate through items and check if they are valid sales or purchase items
+	items = [d.item_code for d in doc.items if d.item_code]
+
+	# No validation check inase of creating transaction using 'Opening Invoice Creation Tool'
+	if not items:
+		return
+
+	item_list = ", ".join(["'%s'" % frappe.db.escape(d) for d in items])
+
+	invalid_items = [d[0] for d in frappe.db.sql("""
+		select item_code from tabItem where name in ({0}) and {1}=0
+		""".format(item_list, fieldname), as_list=True)]
+
+	if invalid_items:
+		frappe.throw(_("Following item {items} {verb} not marked as {message} item.\
+			You can enable them as {message} item from its Item master".format(
+				items = ", ".join([d for d in invalid_items]),
+				verb = "are" if len(invalid_items) > 1 else "is",
+				message = message)))
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index 2a22b32..fcc9d75 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -35,6 +35,7 @@
 
 	def validate(self):
 		super(SellingController, self).validate()
+		self.validate_items()
 		self.validate_max_discount()
 		self.validate_selling_price()
 		self.set_qty_as_per_stock_uom()
@@ -337,6 +338,11 @@
 				po_nos = frappe.get_all('Sales Order', 'po_no', filters = {'name': ('in', sales_orders)})
 				self.po_no = ', '.join(list(set([d.po_no for d in po_nos if d.po_no])))
 
+	def validate_items(self):
+		# validate items to see if they have is_sales_item enabled
+		from erpnext.controllers.buying_controller import validate_item_type
+		validate_item_type(self, "is_sales_item", "sales")
+
 def check_active_sales_items(obj):
 	for d in obj.get("items"):
 		if d.item_code:
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index a4d9dae..41ba61b 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -38,6 +38,7 @@
 		self.manipulate_grand_total_for_inclusive_tax()
 		self.calculate_totals()
 		self._cleanup()
+		self.calculate_total_net_weight()
 
 	def validate_conversion_rate(self):
 		# validate conversion rate
@@ -328,6 +329,13 @@
 
 		self.set_rounded_total()
 
+	def calculate_total_net_weight(self):
+		if self.doc.meta.get_field('total_net_weight'):
+			self.doc.total_net_weight = 0.0
+			for d in self.doc.items:
+				if d.total_weight:
+					self.doc.total_net_weight += d.total_weight
+
 	def set_rounded_total(self):
 		if self.doc.meta.get_field("rounded_total"):
 			if self.doc.is_rounded_total_disabled():
@@ -592,16 +600,19 @@
 			for item_code, tax_data in item_tax_map.items():
 				itemised_tax.setdefault(item_code, frappe._dict())
 
+				tax_rate = 0.0
+				tax_amount = 0.0
+
 				if isinstance(tax_data, list):
-					itemised_tax[item_code][tax.description] = frappe._dict(dict(
-						tax_rate=flt(tax_data[0]),
-						tax_amount=flt(tax_data[1])
-					))
+					tax_rate = flt(tax_data[0])
+					tax_amount = flt(tax_data[1])
 				else:
-					itemised_tax[item_code][tax.description] = frappe._dict(dict(
-						tax_rate=flt(tax_data),
-						tax_amount=0.0
-					))
+					tax_rate = flt(tax_data)
+
+				itemised_tax[item_code][tax.description] = frappe._dict(dict(
+					tax_rate = tax_rate,
+					tax_amount = tax_amount
+				))
 
 	return itemised_tax
 
diff --git a/erpnext/healthcare/doctype/consultation/consultation.py b/erpnext/healthcare/doctype/consultation/consultation.py
index ebf80d6..30b3734 100755
--- a/erpnext/healthcare/doctype/consultation/consultation.py
+++ b/erpnext/healthcare/doctype/consultation/consultation.py
@@ -6,7 +6,7 @@
 import frappe
 from frappe import _
 from frappe.model.document import Document
-from frappe.utils import getdate
+from frappe.utils import getdate, cstr
 import json
 from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account, get_income_account
 
@@ -125,7 +125,7 @@
 def set_subject_field(consultation):
 	subject = "No Diagnosis "
 	if(consultation.diagnosis):
-		subject = "Diagnosis: \n"+ str(consultation.diagnosis)+". "
+		subject = "Diagnosis: \n"+ cstr(consultation.diagnosis)+". "
 	if(consultation.drug_prescription):
 		subject +="\nDrug(s) Prescribed. "
 	if(consultation.test_prescription):
diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.py b/erpnext/healthcare/doctype/lab_test/lab_test.py
index 3ad8b53..b3b64f4 100644
--- a/erpnext/healthcare/doctype/lab_test/lab_test.py
+++ b/erpnext/healthcare/doctype/lab_test/lab_test.py
@@ -6,7 +6,7 @@
 import frappe
 from frappe.model.document import Document
 import json
-from frappe.utils import getdate
+from frappe.utils import getdate, cstr
 from erpnext.healthcare.doctype.healthcare_settings.healthcare_settings import get_receivable_account
 from frappe import _
 
@@ -228,9 +228,9 @@
 	return employee
 
 def insert_lab_test_to_medical_record(doc):
-	subject = str(doc.test_name)
+	subject = cstr(doc.test_name)
 	if(doc.test_comment):
-		subject += ", \n"+str(doc.test_comment)
+		subject += ", \n"+ cstr(doc.test_comment)
 	medical_record = frappe.new_doc("Patient Medical Record")
 	medical_record.patient = doc.patient
 	medical_record.subject = subject
diff --git a/erpnext/healthcare/doctype/vital_signs/vital_signs.py b/erpnext/healthcare/doctype/vital_signs/vital_signs.py
index dea848d..9aa055c 100644
--- a/erpnext/healthcare/doctype/vital_signs/vital_signs.py
+++ b/erpnext/healthcare/doctype/vital_signs/vital_signs.py
@@ -5,6 +5,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.model.document import Document
+from frappe.utils import cstr
 
 class VitalSigns(Document):
 	def on_submit(self):
@@ -33,16 +34,16 @@
 def set_subject_field(doc):
 	subject = " "
 	if(doc.temperature):
-		subject += "Temperature: \n"+ str(doc.temperature)+". "
+		subject += "Temperature: \n"+ cstr(doc.temperature)+". "
 	if(doc.pulse):
-		subject += "Pulse: \n"+ str(doc.pulse)+". "
+		subject += "Pulse: \n"+ cstr(doc.pulse)+". "
 	if(doc.respiratory_rate):
-		subject += "Respiratory Rate: \n"+ str(doc.respiratory_rate)+". "
+		subject += "Respiratory Rate: \n"+ cstr(doc.respiratory_rate)+". "
 	if(doc.bp):
-		subject += "BP: \n"+ str(doc.bp)+". "
+		subject += "BP: \n"+ cstr(doc.bp)+". "
 	if(doc.bmi):
-		subject += "BMI: \n"+ str(doc.bmi)+". "
+		subject += "BMI: \n"+ cstr(doc.bmi)+". "
 	if(doc.nutrition_note):
-		subject += "Note: \n"+ str(doc.nutrition_note)+". "
+		subject += "Note: \n"+ cstr(doc.nutrition_note)+". "
 
 	return subject
diff --git a/erpnext/hr/doctype/appraisal/appraisal.js b/erpnext/hr/doctype/appraisal/appraisal.js
index 64d6f40..30317d9 100644
--- a/erpnext/hr/doctype/appraisal/appraisal.js
+++ b/erpnext/hr/doctype/appraisal/appraisal.js
@@ -24,6 +24,7 @@
 }
 
 cur_frm.cscript.kra_template = function(doc, dt, dn) {
+	doc.goals = [];
 	erpnext.utils.map_current_doc({
 		method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template",
 		source_name: cur_frm.doc.kra_template,
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index d0c4a46..f674a61 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -45,8 +45,9 @@
 		}[cstr(self.docstatus or 0)]
 
 		paid_amount = flt(self.total_amount_reimbursed) + flt(self.total_advance_amount)
+		precision = self.precision("total_sanctioned_amount")
 		if (self.is_paid or (flt(self.total_sanctioned_amount) > 0
-			and flt(self.total_sanctioned_amount) ==  paid_amount)) \
+			and flt(self.total_sanctioned_amount, precision) ==  flt(paid_amount, precision))) \
 			and self.docstatus == 1 and self.approval_status == 'Approved':
 				self.status = "Paid"
 		elif flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and self.approval_status == 'Approved':
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index f40b442..8d6db5c 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -60,6 +60,7 @@
 	def on_cancel(self):
 		# notify leave applier about cancellation
 		self.notify_employee("cancelled")
+		self.cancel_attendance()
 
 	def validate_dates(self):
 		if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)):
@@ -116,7 +117,7 @@
 					frappe.db.sql("""update `tabAttendance` set status = %s, leave_type = %s\
 						where name = %s""",(status, self.leave_type, d.name))
 
-			elif self.to_date <= nowdate():
+			elif getdate(self.to_date) <= getdate(nowdate()):
 				for dt in daterange(getdate(self.from_date), getdate(self.to_date)):
 					date = dt.strftime("%Y-%m-%d")
 					if not date == self.half_day_date:
@@ -126,6 +127,7 @@
 						doc.company = self.company
 						doc.status = "On Leave"
 						doc.leave_type = self.leave_type
+						doc.insert(ignore_permissions=True)
 						doc.submit()
 					else:
 						doc = frappe.new_doc("Attendance")
@@ -134,8 +136,16 @@
 						doc.company = self.company
 						doc.status = "Half Day"
 						doc.leave_type = self.leave_type
+						doc.insert(ignore_permissions=True)
 						doc.submit()
 
+	def cancel_attendance(self):
+		if self.docstatus == 2:
+			attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s\
+				and (attendance_date between %s and %s) and docstatus < 2 and status in ('On Leave', 'Half Day')""",(self.employee, self.from_date, self.to_date), as_dict=1)
+			for name in attendance:
+				frappe.db.set_value("Attendance", name, "docstatus", 2)
+
 	def validate_salary_processed_days(self):
 		if not frappe.db.get_value("Leave Type", self.leave_type, "is_lwp"):
 			return
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 5fbd3b1..5f195d9 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -14,8 +14,12 @@
 from frappe.utils.background_jobs import enqueue
 
 class SalarySlip(TransactionBase):
+	def __init__(self, *args, **kwargs):
+		super(SalarySlip, self).__init__(*args, **kwargs)
+		self.series = 'Sal Slip/{0}/.#####'.format(self.employee)
+
 	def autoname(self):
-		self.name = make_autoname('Sal Slip/' +self.employee + '/.#####')
+		self.name = make_autoname(self.series)
 
 	def validate(self):
 		self.status = self.get_status()
@@ -418,6 +422,10 @@
 		self.set_status()
 		self.update_status()
 
+	def on_trash(self):
+		from frappe.model.naming import revert_series_if_last
+		revert_series_if_last(self.series, self.name)
+
 	def email_salary_slip(self):
 		receiver = frappe.db.get_value("Employee", self.employee, "prefered_email")
 
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 060894c..7a2aa8a 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -158,7 +158,7 @@
 					if not self.buying_price_list:
 						frappe.throw(_("Please select Price List"))
 					rate = frappe.db.get_value("Item Price", {"price_list": self.buying_price_list,
-						"item_code": arg["item_code"]}, "price_list_rate")
+						"item_code": arg["item_code"]}, "price_list_rate") or 0.0
 
 					price_list_currency = frappe.db.get_value("Price List",
 						self.buying_price_list, "currency")
@@ -652,4 +652,4 @@
 				bom_list.append(child_bom)
 		count += 1
 
-	return bom_list
\ No newline at end of file
+	return bom_list
diff --git a/erpnext/manufacturing/page/production_analytics/production_analytics.js b/erpnext/manufacturing/page/production_analytics/production_analytics.js
index efbd0a5..21b4293 100644
--- a/erpnext/manufacturing/page/production_analytics/production_analytics.js
+++ b/erpnext/manufacturing/page/production_analytics/production_analytics.js
@@ -64,8 +64,7 @@
 
 		var chart_data = this.get_chart_data ? this.get_chart_data() : null;
 
-		this.chart = new Chart({
-			parent: ".chart",
+		this.chart = new frappeChart.Chart(".chart", {
 			data: chart_data,
 			type: 'line'
 		});
diff --git a/erpnext/non_profit/doctype/membership/membership.json b/erpnext/non_profit/doctype/membership/membership.json
index 42e084d..694a4fa 100644
--- a/erpnext/non_profit/doctype/membership/membership.json
+++ b/erpnext/non_profit/doctype/membership/membership.json
@@ -15,6 +15,7 @@
  "fields": [
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -42,10 +43,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -73,10 +76,12 @@
    "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -102,10 +107,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -133,15 +140,17 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "membership_validaty_section", 
+   "fieldname": "membership_validity_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -150,7 +159,7 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "membership validaty section", 
+   "label": "Validity", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -163,10 +172,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -193,10 +204,12 @@
    "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -223,10 +236,12 @@
    "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -252,10 +267,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -282,10 +299,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -312,10 +331,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -342,10 +363,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -373,10 +396,12 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_in_quick_entry": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -403,6 +428,7 @@
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
+   "translatable": 0, 
    "unique": 0
   }
  ], 
@@ -416,7 +442,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-05 07:02:56.859408", 
+ "modified": "2018-06-26 19:23:17.911121", 
  "modified_by": "Administrator", 
  "module": "Non Profit", 
  "name": "Membership", 
@@ -425,7 +451,6 @@
  "permissions": [
   {
    "amend": 0, 
-   "apply_user_permissions": 0, 
    "cancel": 0, 
    "create": 1, 
    "delete": 1, 
@@ -445,7 +470,6 @@
   }, 
   {
    "amend": 0, 
-   "apply_user_permissions": 0, 
    "cancel": 0, 
    "create": 1, 
    "delete": 1, 
@@ -472,5 +496,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "track_changes": 1, 
- "track_seen": 0
-}
\ No newline at end of file
+ "track_seen": 0, 
+ "track_views": 0
+}
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 2eb0804..ade6217 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -502,3 +502,4 @@
 erpnext.patches.v10_0.taxes_issue_with_pos
 erpnext.patches.v10_0.set_qty_in_transactions_based_on_serial_no_input
 erpnext.patches.v10_0.show_leaves_of_all_department_members_in_calendar
+erpnext.patches.v10_0.update_status_in_purchase_receipt
diff --git a/erpnext/patches/v10_0/update_status_in_purchase_receipt.py b/erpnext/patches/v10_0/update_status_in_purchase_receipt.py
new file mode 100644
index 0000000..69e2bb8
--- /dev/null
+++ b/erpnext/patches/v10_0/update_status_in_purchase_receipt.py
@@ -0,0 +1,7 @@
+import frappe
+
+def execute():
+	frappe.reload_doc("stock", "doctype", "purchase_receipt")
+	frappe.db.sql('''
+		UPDATE `tabPurchase Receipt` SET status = "Completed" WHERE per_billed = 100 AND docstatus = 1
+	''')
\ No newline at end of file
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 060218d..1f4bd00 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 
-from frappe.utils import flt, getdate, get_url
+from frappe.utils import flt, getdate, get_url, now
 from frappe import _
 
 from frappe.model.document import Document
@@ -60,6 +60,7 @@
 		self.validate_weights()
 		self.sync_tasks()
 		self.tasks = []
+		self.load_tasks()
 		self.send_welcome_email()
 
 	def validate_project_name(self):
@@ -83,36 +84,68 @@
 		"""sync tasks and remove table"""
 		if self.flags.dont_sync_tasks: return
 		task_names = []
+
+		existing_task_data = {}
+		for d in frappe.get_all('Project Task',
+			fields = ["title", "status", "start_date", "end_date", "description", "task_weight", "task_id"],
+			filters = {'parent': self.name}):
+			existing_task_data.setdefault(d.task_id, d)
+
 		for t in self.tasks:
 			if t.task_id:
 				task = frappe.get_doc("Task", t.task_id)
 			else:
 				task = frappe.new_doc("Task")
 				task.project = self.name
-			task.update({
-				"subject": t.title,
-				"status": t.status,
-				"exp_start_date": t.start_date,
-				"exp_end_date": t.end_date,
-				"description": t.description,
-				"task_weight": t.task_weight
-			})
 
-			self.map_custom_fields(t, task)
+			if not t.task_id or self.is_row_updated(t, existing_task_data):
+				task.update({
+					"subject": t.title,
+					"status": t.status,
+					"exp_start_date": t.start_date,
+					"exp_end_date": t.end_date,
+					"description": t.description,
+					"task_weight": t.task_weight
+				})
 
-			task.flags.ignore_links = True
-			task.flags.from_project = True
-			task.flags.ignore_feed = True
-			task.save(ignore_permissions = True)
-			task_names.append(task.name)
+				self.map_custom_fields(t, task)
+
+				task.flags.ignore_links = True
+				task.flags.from_project = True
+				task.flags.ignore_feed = True
+
+				if t.task_id:
+					task.update({
+						"modified_by": frappe.session.user,
+						"modified": now()
+					})
+
+					task.validate()
+					task.db_update()
+				else:
+					task.save(ignore_permissions = True)
+				task_names.append(task.name)
+			else:
+				task_names.append(task.name)
 
 		# delete
 		for t in frappe.get_all("Task", ["name"], {"project": self.name, "name": ("not in", task_names)}):
 			frappe.delete_doc("Task", t.name)
 
+	def update_costing_and_percentage_complete(self):
 		self.update_percent_complete()
 		self.update_costing()
 
+	def is_row_updated(self, row, existing_task_data):
+		if self.get("__islocal") or not existing_task_data: return True
+
+		d = existing_task_data.get(row.task_id)
+
+		if (d and (row.title != d.title or row.status != d.status
+			or getdate(row.start_date) != getdate(d.start_date) or getdate(row.end_date) != getdate(d.end_date)
+			or row.description != d.description or row.task_weight != d.task_weight)):
+			return True
+
 	def map_custom_fields(self, source, target):
 		project_task_custom_fields = frappe.get_all("Custom Field", {"dt": "Project Task"}, "fieldname")
 
@@ -207,6 +240,9 @@
 
 		self.total_billed_amount = total_billed_amount and total_billed_amount[0][0] or 0
 
+	def after_rename(self, old_name, new_name, merge=False):
+		if old_name == self.copied_from:
+			frappe.db.set_value('Project', new_name, 'copied_from', new_name)
 
 	def send_welcome_email(self):
 		url = get_url("/project/?name={0}".format(self.name))
@@ -227,8 +263,7 @@
 				user.welcome_email_sent=1
 
 	def on_update(self):
-		self.load_tasks()
-		self.sync_tasks()
+		self.update_costing_and_percentage_complete()
 		self.update_dependencies_on_duplicated_project()
 
 	def update_dependencies_on_duplicated_project(self):
@@ -251,9 +286,7 @@
 					continue
 
 				name = _task.name
-				depends_on_tasks = _task.depends_on_tasks
 
-				depends_on_tasks = [x for x in depends_on_tasks.split(',') if x]
 				dependency_map[task.title] = [ x['subject'] for x in frappe.get_list(
 					'Task Depends On', {"parent": name}, ['subject'])]
 
@@ -264,9 +297,9 @@
 				for dt in value:
 					dt_name = frappe.db.get_value('Task', {"subject": dt, "project": self.name })
 					task_doc.append('depends_on', {"task": dt_name})
-				task_doc.save()
 
-@frappe.whitelist()
+				task_doc.update_db()
+
 def get_timeline_data(doctype, name):
 	'''Return timeline for attendance'''
 	return dict(frappe.db.sql('''select unix_timestamp(from_time), count(*)
diff --git a/erpnext/projects/doctype/project/project_dashboard.py b/erpnext/projects/doctype/project/project_dashboard.py
index be33c9d..0ac7d6f 100644
--- a/erpnext/projects/doctype/project/project_dashboard.py
+++ b/erpnext/projects/doctype/project/project_dashboard.py
@@ -4,7 +4,6 @@
 	return {
 		'heatmap': True,
 		'heatmap_message': _('This is based on the Time Sheets created against this project'),
-		'method' : 'erpnext.projects.doctype.project.project.get_timeline_data',
 		'fieldname': 'project',
 		'transactions': [
 			{
diff --git a/erpnext/projects/doctype/project_task/project_task.json b/erpnext/projects/doctype/project_task/project_task.json
index 79790e5..e5f28b7 100644
--- a/erpnext/projects/doctype/project_task/project_task.json
+++ b/erpnext/projects/doctype/project_task/project_task.json
@@ -371,7 +371,7 @@
    "remember_last_selected_value": 1, 
    "report_hide": 0, 
    "reqd": 0, 
-   "search_index": 0, 
+   "search_index": 1, 
    "set_only_once": 0, 
    "unique": 0
   }
@@ -386,7 +386,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-12-19 14:49:15.886339", 
+ "modified": "2018-06-26 11:46:50.890251", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Project Task", 
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 8e72d03..cf524da 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -38,7 +38,7 @@
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
-   "search_index": 0, 
+   "search_index": 1, 
    "set_only_once": 0, 
    "unique": 0
   }, 
@@ -70,7 +70,7 @@
    "remember_last_selected_value": 1, 
    "report_hide": 0, 
    "reqd": 0, 
-   "search_index": 0, 
+   "search_index": 1, 
    "set_only_once": 0, 
    "unique": 0
   }, 
@@ -1214,7 +1214,7 @@
  "istable": 0, 
  "max_attachments": 5, 
  "menu_index": 0, 
- "modified": "2017-11-10 18:37:19.660293", 
+ "modified": "2018-06-26 11:46:06.678115", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Task", 
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index 98e961d..d2f1868 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -420,9 +420,10 @@
 	# find customer name from contact.
 	customer = frappe.db.sql('''SELECT dl.link_name FROM `tabContact` AS c inner join \
 		`tabDynamic Link` AS dl ON c.first_name=dl.link_name WHERE c.email_id=%s''',user)
-	# find list of Sales Invoice for made for customer.
-	sales_invoice = frappe.db.sql('''SELECT name FROM `tabSales Invoice` WHERE customer = %s''',customer)
+
 	if customer:
+		# find list of Sales Invoice for made for customer.
+		sales_invoice = frappe.db.sql('''SELECT name FROM `tabSales Invoice` WHERE customer = %s''',customer)
 		# Return timesheet related data to web portal.
 		return frappe. db.sql('''SELECT ts.name, tsd.activity_type, ts.status, ts.total_billable_hours, \
 			tsd.sales_invoice, tsd.project  FROM `tabTimesheet` AS ts inner join `tabTimesheet Detail` \
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index f00b84f..b6690cb 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -338,12 +338,14 @@
 
 	set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
 		// store tax breakup for each item
-		var key = item.item_code || item.item_name;
-		var item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
-		if (tax.item_wise_tax_detail && tax.item_wise_tax_detail[key])
-			item_wise_tax_amount += tax.item_wise_tax_detail[key][1];
+		let tax_detail = tax.item_wise_tax_detail;
+		let key = item.item_code || item.item_name;
 
-		tax.item_wise_tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))];
+		let item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
+		if (tax_detail && tax_detail[key])
+			item_wise_tax_amount += tax_detail[key][1];
+
+		tax_detail[key] = [tax_rate, flt(item_wise_tax_amount, precision("base_tax_amount", tax))];
 	},
 
 	round_off_totals: function(tax) {
diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js
index 75d5ce9..0f28d4e 100644
--- a/erpnext/public/js/utils/party.js
+++ b/erpnext/public/js/utils/party.js
@@ -169,21 +169,25 @@
 }
 
 erpnext.utils.get_shipping_address = function(frm, callback){
-	frappe.call({
-		method: "frappe.contacts.doctype.address.address.get_shipping_address",
-		args: {
-			company: frm.doc.company,
-			address: frm.doc.shipping_address
-		},
-		callback: function(r){
-			if(r.message){
-				frm.set_value("shipping_address", r.message[0]) //Address title or name
-				frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page
-			}
+	if (frm.doc.company) {
+		frappe.call({
+			method: "frappe.contacts.doctype.address.address.get_shipping_address",
+			args: {
+				company: frm.doc.company,
+				address: frm.doc.shipping_address
+			},
+			callback: function(r){
+				if(r.message){
+					frm.set_value("shipping_address", r.message[0]) //Address title or name
+					frm.set_value("shipping_address_display", r.message[1]) //Address to be displayed on the page
+				}
 
-			if(callback){
-				return callback();
+				if(callback){
+					return callback();
+				}
 			}
-		}
-	});
+		});
+	} else {
+		frappe.msgprint(__("Select company first"));
+	}
 }
\ No newline at end of file
diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py
index a14500a..9837996 100644
--- a/erpnext/regional/report/gstr_1/gstr_1.py
+++ b/erpnext/regional/report/gstr_1/gstr_1.py
@@ -23,7 +23,7 @@
 			posting_date,
 			base_grand_total,
 			base_rounded_total,
-			customer_gstin,
+			COALESCE(NULLIF(customer_gstin,''), NULLIF(billing_address_gstin, '')) as customer_gstin,
 			place_of_supply,
 			ecommerce_gstin,
 			reverse_charge,
@@ -144,17 +144,10 @@
 		""" % (self.doctype, ', '.join(['%s']*len(self.invoices))), tuple(self.invoices), as_dict=1)
 
 		for d in items:
-			item_details = {}
-			item_details[d.item_code] = d.base_net_amount
-
-			if d.parent in self.invoice_items:
-				parent_dict = self.invoice_items[d.parent]
-				if d.item_code in parent_dict:
-					item_details[d.item_code] += parent_dict[d.item_code]
-				else:
-					item_details.update(parent_dict)
-
-			self.invoice_items[d.parent] = item_details
+			if d.item_code not in self.invoice_items.get(d.parent, {}):
+				self.invoice_items.setdefault(d.parent, {}).setdefault(d.item_code,
+					sum(i.get('base_net_amount', 0) for i in items
+					    if i.item_code == d.item_code and i.parent == d.parent))
 
 	def get_items_based_on_tax_rate(self):
 		self.tax_details = frappe.db.sql("""
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 7232fad..b17345c 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -79,7 +79,7 @@
 	def update_customer_groups(self):
 		ignore_doctypes = ["Lead", "Opportunity", "POS Profile", "Tax Rule", "Pricing Rule"]
 		if frappe.flags.customer_group_changed:
-			update_linked_doctypes('Customer', self.name, 'Customer Group',
+			update_linked_doctypes('Customer', frappe.db.escape(self.name), 'Customer Group',
 				self.customer_group, ignore_doctypes)
 
 	def create_primary_contact(self):
diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json
index 1c40ec3..61973d6 100644
--- a/erpnext/selling/doctype/quotation/quotation.json
+++ b/erpnext/selling/doctype/quotation/quotation.json
@@ -2439,8 +2439,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "select_print_heading", 
-   "fieldtype": "Link", 
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -2448,18 +2448,16 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Print Heading", 
+   "label": "Group same items",
    "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "select_print_heading", 
-   "oldfieldtype": "Link", 
-   "options": "Print Heading", 
+   "no_copy": 0,
    "permlevel": 0, 
+   "precision": "",
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
-   "report_hide": 1, 
+   "report_hide": 0,
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
@@ -2496,6 +2494,38 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_on_submit": 1,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "select_print_heading",
+   "fieldtype": "Link",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Print Heading",
+   "length": 0,
+   "no_copy": 1,
+   "oldfieldname": "select_print_heading",
+   "oldfieldtype": "Link",
+   "options": "Print Heading",
+   "permlevel": 0,
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 1,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -2881,8 +2911,8 @@
  "istable": 0, 
  "max_attachments": 1, 
  "menu_index": 0, 
- "modified": "2017-12-19 14:52:28.966139", 
- "modified_by": "nabinhait@gmail.com", 
+ "modified": "2018-05-28 03:23:15.354674",
+ "modified_by": "Administrator",
  "module": "Selling", 
  "name": "Quotation", 
  "owner": "Administrator", 
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 694b530..709c069 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -185,6 +185,7 @@
 		target.run_method("calculate_taxes_and_totals")
 
 	def update_item(obj, target, source_parent):
+		target.cost_center = None
 		target.stock_qty = flt(obj.qty) * flt(obj.conversion_factor)
 
 	doclist = get_mapped_doc("Quotation", source_name, {
diff --git a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.json b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.json
index 0eb6228..7f9ef88 100644
--- a/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.json
+++ b/erpnext/selling/report/item_wise_sales_history/item_wise_sales_history.json
@@ -7,12 +7,12 @@
  "doctype": "Report", 
  "idx": 3, 
  "is_standard": "Yes", 
- "modified": "2017-02-24 20:08:44.614482", 
+ "modified": "2018-06-18 16:42:05.860309", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Item-wise Sales History", 
  "owner": "Administrator", 
- "query": "select\n    so_item.item_code as \"Item Code:Link/Item:120\",\n\tso_item.item_name as \"Item Name::120\",\n        so_item.item_group as \"Item Group:Link/Item Group:120\",\n\tso_item.description as \"Description::150\",\n\tso_item.qty as \"Qty:Float:100\",\n\tso_item.stock_uom as \"UOM:Link/UOM:80\",\n\tso_item.base_rate as \"Rate:Currency:120\",\n\tso_item.base_amount as \"Amount:Currency:120\",\n\tso.name as \"Sales Order:Link/Sales Order:120\",\n\tso.transaction_date as \"Transaction Date:Date:140\",\n\tso.customer as \"Customer:Link/Customer:130\",\n        cu.customer_name as \"Customer Name::150\",\n\tso.territory as \"Territory:Link/Territory:130\",\n    so.project as \"Project:Link/Project:130\",\n\tifnull(so_item.delivered_qty, 0) as \"Delivered Qty:Float:120\",\n\tifnull(so_item.billed_amt, 0) as \"Billed Amount:Currency:120\",\n\tso.company as \"Company:Link/Company:\"\nfrom\n\t`tabSales Order` so, `tabSales Order Item` so_item, `tabCustomer` cu\nwhere\n\tso.name = so_item.parent and so.customer=cu.name\n\tand so.docstatus = 1\norder by so.name desc", 
+ "query": "select\n    so_item.item_code as \"Item Code:Link/Item:120\",\n\tso_item.item_name as \"Item Name::120\",\n        so_item.item_group as \"Item Group:Link/Item Group:120\",\n\tso_item.description as \"Description::150\",\n\tso_item.qty as \"Qty:Data:100\",\n\tso_item.uom as \"UOM:Link/UOM:80\",\n\tso_item.base_rate as \"Rate:Currency:120\",\n\tso_item.base_amount as \"Amount:Currency:120\",\n\tso.name as \"Sales Order:Link/Sales Order:120\",\n\tso.transaction_date as \"Transaction Date:Date:140\",\n\tso.customer as \"Customer:Link/Customer:130\",\n        cu.customer_name as \"Customer Name::150\",\n\tso.territory as \"Territory:Link/Territory:130\",\n    so.project as \"Project:Link/Project:130\",\n\tifnull(so_item.delivered_qty, 0) as \"Delivered Qty:Float:120\",\n\tifnull(so_item.billed_amt, 0) as \"Billed Amount:Currency:120\",\n\tso.company as \"Company:Link/Company:\"\nfrom\n\t`tabSales Order` so, `tabSales Order Item` so_item, `tabCustomer` cu\nwhere\n\tso.name = so_item.parent and so.customer=cu.name\n\tand so.docstatus = 1\norder by so.name desc", 
  "ref_doctype": "Sales Order", 
  "report_name": "Item-wise Sales History", 
  "report_type": "Query Report", 
diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index e7bb5b4..fd5bc4e 100644
--- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -98,7 +98,7 @@
 		END as qty,
 		CASE
 			WHEN so.status = "Closed" THEN sum(soi.delivered_qty * soi.conversion_factor * soi.base_net_rate * (st.allocated_percentage/100))
-			ELSE soi.base_net_amount * (st.allocated_percentage/100))
+			ELSE sum(soi.base_net_amount * (st.allocated_percentage/100))
 		END as amount
 		from
 			`tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
diff --git a/erpnext/setup/doctype/authorization_control/authorization_control.py b/erpnext/setup/doctype/authorization_control/authorization_control.py
index 7d5e80b..b419850 100644
--- a/erpnext/setup/doctype/authorization_control/authorization_control.py
+++ b/erpnext/setup/doctype/authorization_control/authorization_control.py
@@ -40,7 +40,7 @@
 		chk = 1
 		add_cond1,add_cond2	= '',''
 		if based_on == 'Itemwise Discount':
-			add_cond1 += " and master_name = '"+cstr(item).replace("'", "\\'")+"'"
+			add_cond1 += " and master_name = '"+frappe.db.escape(cstr(item))+"'"
 			itemwise_exists = frappe.db.sql("""select value from `tabAuthorization Rule`
 				where transaction = %s and value <= %s
 				and based_on = %s and company = %s and docstatus != 2 %s %s""" %
diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
index 6d5848a..c488b99 100644
--- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
+++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py
@@ -2,6 +2,7 @@
 # License: GNU General Public License v3. See license.txt
 from __future__ import unicode_literals
 import frappe, unittest
+from frappe.utils import flt
 from erpnext.setup.utils import get_exchange_rate
 
 test_records = frappe.get_test_records('Currency Exchange')
@@ -44,7 +45,7 @@
 
 		# Start with allow_stale is True
 		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01")
-		self.assertEqual(exchange_rate, 60.0)
+		self.assertEqual(flt(exchange_rate, 3), 60.0)
 
 		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
 		self.assertEqual(exchange_rate, 65.1)
@@ -56,7 +57,7 @@
 		self.clear_cache()
 		exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15")
 		self.assertFalse(exchange_rate == 60)
-		self.assertEqual(exchange_rate, 66.894)
+		self.assertEqual(flt(exchange_rate, 3), 66.894)
 
 	def test_exchange_rate_strict(self):
 		# strict currency settings
@@ -69,7 +70,7 @@
 		# Will fetch from fixer.io
 		self.clear_cache()
 		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
-		self.assertEqual(exchange_rate, 67.79)
+		self.assertEqual(flt(exchange_rate, 3), 67.79)
 
 		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30")
 		self.assertEqual(exchange_rate, 62.9)
@@ -77,7 +78,7 @@
 		# Exchange rate as on 15th Dec, 2015, should be fetched from fixer.io
 		self.clear_cache()
 		exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15")
-		self.assertEqual(exchange_rate, 66.894)
+		self.assertEqual(flt(exchange_rate, 3), 66.894)
 
 		exchange_rate = get_exchange_rate("INR", "NGN", "2016-01-10")
 		self.assertEqual(exchange_rate, 65.1)
@@ -100,4 +101,4 @@
 		# Will fetch from fixer.io
 		self.clear_cache()
 		exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15")
-		self.assertEqual(exchange_rate, 67.79)
\ No newline at end of file
+		self.assertEqual(flt(exchange_rate, 3), 67.79)
\ No newline at end of file
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 5fcc3a2..4f62815 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -95,7 +95,7 @@
 
 		if not value:
 			import requests
-			api_url = "http://api.fixer.io/{0}".format(transaction_date)
+			api_url = "https://exchangeratesapi.io/api/{0}".format(transaction_date)
 			response = requests.get(api_url, params={
 				"base": from_currency,
 				"symbols": to_currency
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 9c1373b..e377783 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -3157,6 +3157,36 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_on_submit": 1,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Group same items",
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 1, 
@@ -3701,7 +3731,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2018-03-13 15:35:02.234116", 
+ "modified": "2018-05-28 03:03:35.035396",
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 909fa2c..70a0612 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -82,6 +82,8 @@
 			for f in fieldname:
 				toggle_print_hide(self.meta if key == "parent" else item_meta, f)
 
+		super(DeliveryNote, self).before_print()
+
 	def set_actual_qty(self):
 		for d in self.get('items'):
 			if d.item_code and d.warehouse:
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index 74dfa05..0c55b43 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -49,7 +49,8 @@
 	pi.qty = flt(qty)
 	pi.description = description
 	if not pi.warehouse:
-		pi.warehouse = item.default_warehouse or main_item_row.warehouse
+		pi.warehouse = (main_item_row.warehouse
+			if (doc.get('is_pos') or not item.default_warehouse) else item.default_warehouse)
 	if not pi.batch_no:
 		pi.batch_no = cstr(main_item_row.get("batch_no"))
 	if not pi.target_warehouse:
diff --git a/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json b/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
index 009244c..d240b7d 100644
--- a/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
+++ b/erpnext/stock/doctype/packing_slip_item/packing_slip_item.json
@@ -88,6 +88,7 @@
    "label": "Item Name", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "item_code.item_name",
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -435,7 +436,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-02-20 13:30:26.818408", 
+ "modified": "2018-06-01 07:21:58.220980",
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Packing Slip Item", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
index 8c86c8b..3f4337f 100755
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json
@@ -2978,10 +2978,69 @@
   }, 
   {
    "allow_bulk_edit": 0, 
+   "allow_on_submit": 1,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
+   "fieldname": "group_same_items",
+   "fieldtype": "Check",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "label": "Group same items",
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 1,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "column_break_97",
+   "fieldtype": "Column Break",
+   "hidden": 0,
+   "ignore_user_permissions": 0,
+   "ignore_xss_filter": 0,
+   "in_filter": 0,
+   "in_global_search": 0,
+   "in_list_view": 0,
+   "in_standard_filter": 0,
+   "length": 0,
+   "no_copy": 0,
+   "permlevel": 0,
+   "precision": "",
+   "print_hide": 0,
+   "print_hide_if_no_value": 0,
+   "read_only": 0,
+   "remember_last_selected_value": 0,
+   "report_hide": 0,
+   "reqd": 0,
+   "search_index": 0,
+   "set_only_once": 0,
+   "unique": 0
+  },
+  {
+   "allow_bulk_edit": 0,
+   "allow_on_submit": 0,
+   "bold": 0,
+   "collapsible": 0,
+   "columns": 0,
    "fieldname": "other_details", 
    "fieldtype": "HTML", 
    "hidden": 1, 
@@ -3242,7 +3301,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-11-29 14:15:10.309900", 
+ "modified": "2018-05-28 02:59:59.609643",
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt", 
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 2a962cc..80dc4e1 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -120,6 +120,8 @@
 		self.update_prevdoc_status()
 		if self.per_billed < 100:
 			self.update_billing_status()
+		else:
+			self.status = "Completed"
 
 		# Updating stock ledger should always be called after updating prevdoc status,
 		# because updating ordered qty, reserved_qty_for_subcontract in bin
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index d1dcb31..5ed8ada 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -263,7 +263,7 @@
 			d.actual_qty = previous_sle.get("qty_after_transaction") or 0
 
 			# validate qty during submit
-			if d.docstatus==1 and d.s_warehouse and not allow_negative_stock and d.actual_qty < d.transfer_qty:
+			if d.docstatus==1 and d.s_warehouse and not allow_negative_stock and flt(d.actual_qty, d.precision("actual_qty")) < flt(d.transfer_qty, d.precision("actual_qty")):
 				frappe.throw(_("Row {0}: Qty not available for {4} in warehouse {1} at posting time of the entry ({2} {3})").format(d.idx,
 					frappe.bold(d.s_warehouse), formatdate(self.posting_date),
 					format_time(self.posting_time), frappe.bold(d.item_code))
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index b5d2e3f..085e87f 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -77,8 +77,8 @@
 				elif not frappe.db.get_value("Batch",{"item": self.item_code, "name": self.batch_no}):
 					frappe.throw(_("{0} is not a valid Batch Number for Item {1}").format(self.batch_no, self.item_code))
 
-			elif item_det.has_batch_no ==0 and self.batch_no:
-					frappe.throw(_("The Item {0} cannot have Batch").format(self.item_code))
+			elif item_det.has_batch_no ==0 and self.batch_no and self.is_cancelled == "No":
+				frappe.throw(_("The Item {0} cannot have Batch").format(self.item_code))
 
 		if item_det.has_variants:
 			frappe.throw(_("Stock cannot exist for Item {0} since has variants").format(self.item_code),
diff --git a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js
index 2482cf8..c0535bf 100644
--- a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js
+++ b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.js
@@ -14,6 +14,19 @@
 			"label": __("To Date"),
 			"fieldtype": "Date",
 			"default": frappe.datetime.get_today()
+		},
+		{
+			"fieldname":"item_group",
+			"label": __("Item Group"),
+			"fieldtype": "Link",
+			"options": "Item Group",
+			"reqd": 1
+		},
+		{
+			"fieldname":"brand",
+			"label": __("Brand"),
+			"fieldtype": "Link",
+			"options": "Brand"
 		}
 	]
 }
\ No newline at end of file
diff --git a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
index cc47ad9..618fd15 100644
--- a/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
+++ b/erpnext/stock/report/itemwise_recommended_reorder_level/itemwise_recommended_reorder_level.py
@@ -10,7 +10,7 @@
 	if not filters: filters = {}
 	float_preceision = frappe.db.get_default("float_preceision")
 
-	condition =get_condition(filters)
+	condition = get_condition(filters)
 
 	avg_daily_outgoing = 0
 	diff = ((getdate(filters.get("to_date")) - getdate(filters.get("from_date"))).days)+1
@@ -18,7 +18,7 @@
 		frappe.throw(_("'From Date' must be after 'To Date'"))
 
 	columns = get_columns()
-	items = get_item_info()
+	items = get_item_info(filters)
 	consumed_item_map = get_consumed_items(condition)
 	delivered_item_map = get_delivered_items(condition)
 
@@ -28,23 +28,31 @@
 		avg_daily_outgoing = flt(total_outgoing / diff, float_preceision)
 		reorder_level = (avg_daily_outgoing * flt(item.lead_time_days)) + flt(item.safety_stock)
 
-		data.append([item.name, item.item_name, item.description, item.safety_stock, item.lead_time_days,
-			consumed_item_map.get(item.name, 0), delivered_item_map.get(item.name,0), total_outgoing,
-			avg_daily_outgoing, reorder_level])
+		data.append([item.name, item.item_name, item.item_group, item.brand, item.description,
+			item.safety_stock, item.lead_time_days, consumed_item_map.get(item.name, 0),
+			delivered_item_map.get(item.name,0), total_outgoing, avg_daily_outgoing, reorder_level])
 
 	return columns , data
 
 def get_columns():
 	return[
-			_("Item") + ":Link/Item:120", _("Item Name") + ":Data:120", _("Description") + "::160",
+			_("Item") + ":Link/Item:120", _("Item Name") + ":Data:120", _("Item Group") + ":Link/Item Group:100",
+			_("Brand") + ":Link/Brand:100", _("Description") + "::160",
 			_("Safety Stock") + ":Float:160", _("Lead Time Days") + ":Float:120", _("Consumed") + ":Float:120",
 			_("Delivered") + ":Float:120", _("Total Outgoing") + ":Float:120", _("Avg Daily Outgoing") + ":Float:160",
 			_("Reorder Level") + ":Float:120"
 	]
 
-def get_item_info():
-	return frappe.db.sql("""select name, item_name, description, safety_stock,
-		lead_time_days from tabItem""", as_dict=1)
+def get_item_info(filters):
+	from erpnext.stock.report.stock_ledger.stock_ledger import get_item_group_condition
+	conditions = [get_item_group_condition(filters.get("item_group"))]
+	if filters.get("brand"):
+		conditions.append("item.brand=%(brand)s")
+
+	return frappe.db.sql("""select name, item_name, description, brand, item_group,
+		safety_stock, lead_time_days from `tabItem` item where {}"""
+		.format(" and ".join(conditions)), filters, as_dict=1)
+
 
 def get_consumed_items(condition):
 	cn_items = frappe.db.sql("""select se_item.item_code,
diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py
index 1a91ab4..ec95561 100644
--- a/erpnext/stock/report/stock_ledger/stock_ledger.py
+++ b/erpnext/stock/report/stock_ledger/stock_ledger.py
@@ -56,7 +56,7 @@
 	item_conditions_sql = ''
 	if items:
 		item_conditions_sql = 'and sle.item_code in ({})'\
-			.format(', '.join(['"' + frappe.db.escape(i,percent=False) + '"' for i in items]))
+			.format(', '.join(['"' + frappe.db.escape(i) + '"' for i in items]))
 
 	return frappe.db.sql("""select concat_ws(" ", posting_date, posting_time) as date,
 			item_code, warehouse, actual_qty, qty_after_transaction, incoming_rate, valuation_rate,
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html
index 3a6d225..7980189 100644
--- a/erpnext/templates/pages/order.html
+++ b/erpnext/templates/pages/order.html
@@ -20,7 +20,7 @@
 <div class="row transaction-subheading">
     <div class="col-xs-6">
         <span class="indicator {{ doc.indicator_color or ("blue" if doc.docstatus==1 else "darkgrey") }}">
-            {{ _(doc.indicator_title) or _(doc.status) or _("Submitted") }}
+            {{ _(doc.get("status")) or _(doc.get("indicator_title")) or _("Submitted") }}
         </span>
 	</div>
     <div class="col-xs-6 text-muted text-right small">
diff --git a/erpnext/utilities/page/leaderboard/leaderboard.js b/erpnext/utilities/page/leaderboard/leaderboard.js
index 1a9efd5..c5f2e87 100644
--- a/erpnext/utilities/page/leaderboard/leaderboard.js
+++ b/erpnext/utilities/page/leaderboard/leaderboard.js
@@ -85,7 +85,7 @@
 
 		this.$sidebar_list.on('click', 'li', function(e) {
 			let $li = $(this);
-			let doctype = $li.find('span').html();
+			let doctype = $li.find('span').attr("doctype-value");
 
 			me.options.selected_company = frappe.defaults.get_default('company');
 			me.options.selected_doctype = doctype;
@@ -146,7 +146,6 @@
 
 				me.$graph_area.show().empty();
 				let args = {
-					parent: '.leaderboard-graph',
 					data: {
 						datasets: [
 							{
@@ -160,7 +159,7 @@
 					type: 'bar',
 					height: 140
 				};
-				new Chart(args);
+				new frappeChart.Chart('.leaderboard-graph', args);
 
 				notify(me, r, $container);
 			}
@@ -173,7 +172,7 @@
 			$container.find(".leaderboard-list").html(me.render_list_view(res.message));
 		} else {
 			me.$graph_area.hide();
-			me.message = "No items found.";
+			me.message = __("No items found.");
 			$container.find(".leaderboard-list").html(me.render_list_view());
 		}
 	},
@@ -280,7 +279,7 @@
 			fields.map(col => {
 					let val = item[col];
 					if(col=="name") {
-						var formatted_value = `<a class="grey list-id ellipsis" 
+						var formatted_value = `<a class="grey list-id ellipsis"
 							href="#Form/${me.options.selected_doctype}/${item["name"]}"> ${val} </a>`
 					} else {
 						var formatted_value = `<span class="text-muted ellipsis">
@@ -302,7 +301,7 @@
 	get_sidebar_item: function(item) {
 		return $(`<li class="strong module-sidebar-item">
 			<a class="module-link">
-			<span>${ item }</span></a>
+			<span doctype-value="${item}">${ __(item) }</span></a>
 		</li>`);
 	}
 });