Merge pull request #1867 from nabinhait/v4-hotfix

Multiple fixes
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 2706603..9141697 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -131,6 +131,8 @@
 
 	if not (args.item_group and args.brand):
 		args.item_group, args.brand = frappe.db.get_value("Item", args.item_code, ["item_group", "brand"])
+		if not args.item_group:
+			frappe.throw(_("Item Group not mentioned in item master for item {0}").format(args.item_code))
 
 	if args.customer and not (args.customer_group and args.territory):
 		args.customer_group, args.territory = frappe.db.get_value("Customer", args.customer,
@@ -188,12 +190,15 @@
 		conditions += """ and %(transaction_date)s between ifnull(valid_from, '2000-01-01')
 			and ifnull(valid_upto, '2500-12-31')"""
 
+	item_group_condition = _get_tree_conditions("Item Group", False)
+	if item_group_condition: item_group_condition = " or " + item_group_condition
+
 	return frappe.db.sql("""select * from `tabPricing Rule`
-		where (item_code=%(item_code)s or {item_group_condition} or brand=%(brand)s)
+		where (item_code=%(item_code)s {item_group_condition} or brand=%(brand)s)
 			and docstatus < 2 and ifnull(disable, 0) = 0
 			and ifnull({transaction_type}, 0) = 1 {conditions}
 		order by priority desc, name desc""".format(
-			item_group_condition=_get_tree_conditions("Item Group", False),
+			item_group_condition=item_group_condition,
 			transaction_type=args.transaction_type, conditions=conditions), args, as_dict=1)
 
 def filter_pricing_rules(args, pricing_rules):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 262ac22..834865b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -262,7 +262,7 @@
 		"""Validate Fixed Asset and whether Income Account Entered Exists"""
 		for d in self.get('entries'):
 			item = frappe.db.sql("""select name,is_asset_item,is_sales_item from `tabItem`
-				where name = %s and (ifnull(end_of_life,'')='' or end_of_life > now())""", d.item_code)
+				where name = %s""", d.item_code)
 			acc = frappe.db.sql("""select account_type from `tabAccount`
 				where name = %s and docstatus != 2""", d.income_account)
 			if item and item[0][1] == 'Yes' and acc and acc[0][0] != 'Fixed Asset':
diff --git a/erpnext/setup/doctype/sales_person/sales_person.py b/erpnext/setup/doctype/sales_person/sales_person.py
index bbd5690..f37b139 100644
--- a/erpnext/setup/doctype/sales_person/sales_person.py
+++ b/erpnext/setup/doctype/sales_person/sales_person.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-
+from frappe import _
 from frappe.utils import flt
 from frappe.utils.nestedset import NestedSet
 
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 173a1cf..93c1191 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -169,13 +169,9 @@
 }
 
 cur_frm.cscript.copy_from_item_group = function(doc) {
-	frappe.model.with_doc("Item Group", doc.item_group, function(name, r) {
-		$.each((r.docs[0].item_website_specifications || []), function(i, d) {
-			var n = frappe.model.add_child(doc, "Item Website Specification", "item_website_specifications");
-			n.label = d.label;
-			n.description = d.description;
-		});
-		cur_frm.refresh();
+	return cur_frm.call({
+		doc: doc,
+		method: "copy_specification_from_item_group"
 	});
 }
 
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 8140f40..185fe31 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -270,6 +270,15 @@
 			frappe.db.get_value("Stock Settings", None, "allow_negative_stock"))
 		frappe.db.auto_commit_on_many_writes = 0
 
+	def copy_specification_from_item_group(self):
+		self.set("item_website_specifications", [])
+		if self.item_group:
+			for label, desc in frappe.db.get_values("Item Website Specification",
+				{"parent": self.item_group}, ["label", "description"]):
+					row = self.append("item_website_specifications")
+					row.label = label
+					row.description = desc
+
 def validate_end_of_life(item_code, end_of_life=None, verbose=1):
 	if not end_of_life:
 		end_of_life = frappe.db.get_value("Item", item_code, "end_of_life")
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 9597392..1024198 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -213,11 +213,7 @@
 					if(!r.exc) {
 						var jv_name = frappe.model.make_new_doc_and_get_name('Journal Voucher');
 						var jv = locals["Journal Voucher"][jv_name];
-						$.extend(jv, r.message[0]);
-						$.each(r.message.slice(1), function(i, jvd) {
-							var child = frappe.model.add_child(jv, "Journal Voucher Detail", "entries");
-							$.extend(child, jvd);
-						});
+						$.extend(jv, r.message);
 						loaddoc("Journal Voucher", jv_name);
 					}
 				}
diff --git a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
index a0eba19..f276b56 100644
--- a/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
+++ b/erpnext/support/doctype/maintenance_schedule/maintenance_schedule.py
@@ -40,9 +40,8 @@
 				child.idx = count
 				count = count + 1
 				child.sales_person = d.sales_person
-				child.save(1)
 
-		self.on_update()
+		self.save()
 
 	def on_submit(self):
 		if not self.get('maintenance_schedule_detail'):