Merge pull request #7417 from KanchanChauhan/quick-entry-for-item

[Minor] Valuation rate in Quick entry for Item
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index c6a8ea1..3338d3f 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.2.6'
+__version__ = '7.2.7'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index c092695..d7dce92 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -2212,7 +2212,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -2360,7 +2360,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "% Billed", 
    "length": 0, 
    "no_copy": 1, 
@@ -3062,7 +3062,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 06:01:00.233621", 
+ "modified": "2017-01-06 12:51:56.556331", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
diff --git a/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.py b/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.py
index f627b4a..44e247e 100644
--- a/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.py
+++ b/erpnext/buying/report/quoted_item_comparison/quoted_item_comparison.py
@@ -3,6 +3,7 @@
 
 from __future__ import unicode_literals
 from erpnext.setup.utils import get_exchange_rate
+from frappe.utils import flt, cint
 import frappe
 
 def execute(filters=None):
@@ -20,6 +21,7 @@
 		price_data = []
 		suppliers = []
 		company_currency = frappe.db.get_default("currency")
+		float_precision = cint(frappe.db.get_default("float_precision")) or 2 
 		# Get the list of suppliers
 		for root in frappe.db.sql("""select parent, qty, rate from `tabSupplier Quotation Item` where item_code=%s and docstatus < 2""", item, as_dict=1):
 			for splr in frappe.db.sql("""SELECT supplier from `tabSupplier Quotation` where name =%s and docstatus < 2""", root.parent, as_dict=1):
@@ -46,7 +48,7 @@
 				# Get the quantity for this row
 				for item_price in price_data:
 					if str(item_price.qty) == col.key and item_price.supplier == root:
-						row[col.key] = item_price.rate * exchange_rate
+						row[col.key] = flt(item_price.rate * exchange_rate, float_precision)
 						row[col.key + "QUOTE"] = item_price.parent
 						break
 					else:
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.js b/erpnext/hr/doctype/process_payroll/process_payroll.js
index 0ad8cec..cfb646d 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.js
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.js
@@ -7,6 +7,7 @@
 		frm.doc.start_date = '';
 		frm.doc.end_date = '';
 		frm.doc.payroll_frequency = '';
+		frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
 	},
 
 	refresh: function(frm) {
@@ -25,6 +26,10 @@
 		frm.trigger("set_start_end_dates");
 	},
 
+	salary_slip_based_on_timesheet: function(frm) {
+		frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
+	},
+
 	payment_account: function(frm) {
 		frm.toggle_display(['make_bank_entry'], (frm.doc.payment_account!="" && frm.doc.payment_account!="undefined"));
 	},
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py
index 45030cb..7741263 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.py
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.py
@@ -68,7 +68,7 @@
 
 
 	def check_mandatory(self):
-		for fieldname in ['company', 'payroll_frequency', 'start_date', 'end_date']:
+		for fieldname in ['company', 'start_date', 'end_date']:
 			if not self.get(fieldname):
 				frappe.throw(_("Please set {0}").format(self.meta.get_label(fieldname)))
 
diff --git a/erpnext/patches/v5_0/portal_fixes.py b/erpnext/patches/v5_0/portal_fixes.py
index d7e3b44..260222e 100644
--- a/erpnext/patches/v5_0/portal_fixes.py
+++ b/erpnext/patches/v5_0/portal_fixes.py
@@ -2,5 +2,5 @@
 import erpnext.setup.install
 
 def execute():
-	frappe.reload_doc("website", "doctype", "web_form_field", force=True)
+	frappe.reload_doc("website", "doctype", "web_form_field", force=True, reset_permissions=True)
 	#erpnext.setup.install.add_web_forms()
diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py
index 0ae2f8b..2bdcaf9 100644
--- a/erpnext/projects/doctype/task/task.py
+++ b/erpnext/projects/doctype/task/task.py
@@ -55,7 +55,8 @@
 	def update_depends_on(self):
 		depends_on_tasks = ""
 		for d in self.depends_on:
-			depends_on_tasks += d.task + ","
+			if d.task:
+				depends_on_tasks += d.task + ","
 		self.depends_on_tasks = depends_on_tasks
 
 	def on_update(self):
diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py
index c3dbcd4..490a707 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.py
+++ b/erpnext/projects/doctype/timesheet/timesheet.py
@@ -199,13 +199,22 @@
 				(%(to_time)s > tsd.from_time and %(to_time)s < tsd.to_time) or
 				(%(from_time)s <= tsd.from_time and %(to_time)s >= tsd.to_time))
 			and tsd.name!=%(name)s
+			and ts.name!=%(parent)s
 			and ts.docstatus < 2""".format(cond),
 			{
 				"val": value,
 				"from_time": args.from_time,
 				"to_time": args.to_time,
-				"name": args.name or "No Name"
+				"name": args.name or "No Name",
+				"parent": args.parent or "No Name"
 			}, as_dict=True)
+		# check internal overlap
+		for time_log in self.time_logs:
+			if (fieldname != 'workstation' or args.get(fieldname) == time_log.get(fieldname)) and \
+				args.idx != time_log.idx and ((args.from_time > time_log.from_time and args.from_time < time_log.to_time) or 
+				(args.to_time > time_log.from_time and args.to_time < time_log.to_time) or 
+				(args.from_time <= time_log.from_time and args.to_time >= time_log.to_time)):
+				return self
 
 		return existing[0] if existing else None
 
@@ -359,7 +368,8 @@
 	conditions = get_conditions(filters)
 	return frappe.db.sql("""select `tabTimesheet Detail`.name as name, 
 			`tabTimesheet Detail`.docstatus as status, `tabTimesheet Detail`.parent as parent,
-			from_time as start_date, hours, activity_type, project, to_time as end_date
+			from_time as start_date, hours, activity_type, project, to_time as end_date, 
+			CONCAT(`tabTimesheet Detail`.parent, ' (', ROUND(hours,2),' hrs)') as title 
 		from `tabTimesheet Detail`, `tabTimesheet` 
 		where `tabTimesheet Detail`.parent = `tabTimesheet`.name 
 			and `tabTimesheet`.docstatus < 2 
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 04f5f95..74e9fb6 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -153,22 +153,37 @@
 			frappe.get_meta(items_doctype).fields.forEach(function(d) { 
 				if(d.options===opts.source_doctype) link_fieldname = d.fieldname; });
 
-			// search in existing items if the source_name is already set
+			// search in existing items if the source_name is already set and full qty fetched
 			var already_set = false;
-
+			var item_qty_map = {};
+			
 			$.each(cur_frm.doc.items, function(i, d) {
 				if(d[link_fieldname]==opts.source_name) {
 					already_set = true;
-					return false;
+					if (item_qty_map[d.item_code])
+						item_qty_map[d.item_code] += flt(d.qty);
+					else
+						item_qty_map[d.item_code] = flt(d.qty);
 				}
 			});
-
+			
 			if(already_set) {
-				frappe.msgprint(__("You have already selected items from {0} {1}", 
-					[opts.source_doctype, opts.source_name]));
-				return;
-			}
+				frappe.model.with_doc(opts.source_doctype, opts.source_name, function(r) {
+					var source_doc = frappe.model.get_doc(opts.source_doctype, opts.source_name);
+					$.each(source_doc.items || [], function(i, row) {
+						if(row.qty > flt(item_qty_map[row.item_code])) {
+							already_set = false;
+							return false;
+						}
+					})
+				})
 
+				if(already_set) {
+					frappe.msgprint(__("You have already selected items from {0} {1}", 
+						[opts.source_doctype, opts.source_name]));
+					return;
+				}
+			}
 		}
 
 
diff --git a/erpnext/schools/doctype/academic_term/academic_term.py b/erpnext/schools/doctype/academic_term/academic_term.py
index 4a1a941..3aa0be15 100644
--- a/erpnext/schools/doctype/academic_term/academic_term.py
+++ b/erpnext/schools/doctype/academic_term/academic_term.py
@@ -5,7 +5,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
-from frappe.utils import get_datetime
+from frappe.utils import getdate
 from frappe.model.document import Document
 
 class AcademicTerm(Document):
@@ -18,16 +18,18 @@
         self.title = self.academic_year + " ({})".format(self.term_name) if self.term_name else ""
 
         #Check that start of academic year is earlier than end of academic year
-        if self.term_start_date and self.term_end_date and self.term_start_date > self.term_end_date:
+        if self.term_start_date and self.term_end_date \
+				and getdate(self.term_start_date) > getdate(self.term_end_date):
             frappe.throw(_("The Term End Date cannot be earlier than the Term Start Date. Please correct the dates and try again."))
 
-        """Check that the start of the term is not before the start of the academic year and end of term is not after
-            the end of the academic year"""
+        # Check that the start of the term is not before the start of the academic year 
+		# and end of term is not after the end of the academic year"""
+			
         year = frappe.get_doc("Academic Year",self.academic_year)
-        if self.term_start_date and get_datetime(year.year_start_date) and (self.term_start_date < get_datetime(year.year_start_date)):
+        if self.term_start_date and getdate(year.year_start_date) and (getdate(self.term_start_date) < getdate(year.year_start_date)):
             frappe.throw(_("The Term Start Date cannot be earlier than the Year Start Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
 
-        if self.term_end_date and get_datetime(year.year_end_date) and (self.term_end_date > get_datetime(year.year_end_date)):
+        if self.term_end_date and getdate(year.year_end_date) and (getdate(self.term_end_date) > getdate(year.year_end_date)):
             frappe.throw(_("The Term End Date cannot be later than the Year End Date of the Academic Year to which the term is linked (Academic Year {}). Please correct the dates and try again.").format(self.academic_year))
 
 
diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json
index f171007..51e68fb 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.json
+++ b/erpnext/selling/doctype/sales_order/sales_order.json
@@ -2580,7 +2580,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Delivery Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -2610,7 +2610,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "%  Delivered", 
    "length": 0, 
    "no_copy": 1, 
@@ -2668,7 +2668,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "% Amount Billed", 
    "length": 0, 
    "no_copy": 1, 
@@ -2698,7 +2698,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Billing Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -3369,7 +3369,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-16 04:06:28.675876", 
+ "modified": "2017-01-06 12:51:17.847227", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Sales Order", 
@@ -3383,7 +3383,7 @@
    "delete": 1, 
    "email": 1, 
    "export": 0, 
-   "if_owner": 1, 
+   "if_owner": 0, 
    "import": 0, 
    "is_custom": 0, 
    "permlevel": 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 37f114b..85cf4dd 100644
--- a/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
+++ b/erpnext/setup/doctype/terms_and_conditions/terms_and_conditions.py
@@ -18,4 +18,6 @@
 		doc = json.loads(doc)
 
 	terms_and_conditions = frappe.get_doc("Terms and Conditions", template_name)
-	return frappe.render_template(terms_and_conditions.terms, doc)
\ No newline at end of file
+	
+	if terms_and_conditions.terms:
+		return frappe.render_template(terms_and_conditions.terms, doc)
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 8272977..6be4ad8 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -2705,7 +2705,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
+   "in_standard_filter": 1, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -3120,7 +3120,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-12-16 03:56:08.745185", 
+ "modified": "2017-01-06 12:52:48.960308", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 0ed6952..9b944fa 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -143,7 +143,7 @@
 	user_default_warehouse = user_default_warehouse_list[0] \
 		if len(user_default_warehouse_list)==1 else ""
 
-	warehouse = user_default_warehouse or args.warehouse or item.default_warehouse
+	warehouse = user_default_warehouse or item.default_warehouse or args.warehouse
 
 	out = frappe._dict({
 		"item_code": item.name,