Merge pull request #1233 from nabinhait/hotfix

Removed country field from Search Fields
diff --git a/config.json b/config.json
index cf1b11c..b57ba61 100644
--- a/config.json
+++ b/config.json
@@ -1,6 +1,6 @@
 {
  "app_name": "ERPNext", 
- "app_version": "3.3.0", 
+ "app_version": "3.3.8", 
  "base_template": "app/portal/templates/base.html", 
  "modules": {
   "Accounts": {
@@ -74,5 +74,5 @@
    "type": "module"
   }
  }, 
- "requires_framework_version": "==3.3.0"
+ "requires_framework_version": "==3.3.2"
 }
\ No newline at end of file
diff --git a/manufacturing/doctype/production_order/production_order.js b/manufacturing/doctype/production_order/production_order.js
index 2277262..31900ea 100644
--- a/manufacturing/doctype/production_order/production_order.js
+++ b/manufacturing/doctype/production_order/production_order.js
@@ -1,28 +1,56 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-cur_frm.cscript.onload = function(doc, dt, dn) {
-	if (!doc.status) doc.status = 'Draft';
-	cfn_set_fields(doc, dt, dn);
-}
+$.extend(cur_frm.cscript, {
+	onload: function (doc, dt, dn) {
 
-cur_frm.cscript.refresh = function(doc, dt, dn) {
-	cur_frm.dashboard.reset();
-	erpnext.hide_naming_series();
-	cur_frm.set_intro("");
-	cfn_set_fields(doc, dt, dn);
+		if (!doc.status) doc.status = 'Draft';
+		cfn_set_fields(doc, dt, dn);
 
-	if(doc.docstatus===0 && !doc.__islocal) {
-		cur_frm.set_intro(wn._("Submit this Production Order for further processing."));
-	} else if(doc.docstatus===1) {
-		var percent = flt(doc.produced_qty) / flt(doc.qty) * 100;
-		cur_frm.dashboard.add_progress(cint(percent) + "% " + wn._("Complete"), percent);
+		this.frm.add_fetch("sales_order", "delivery_date", "expected_delivery_date");
+	},
 
-		if(doc.status === "Stopped") {
-			cur_frm.dashboard.set_headline_alert(wn._("Stopped"), "alert-danger", "icon-stop");
+	refresh: function(doc, dt, dn) {
+		this.frm.dashboard.reset();
+		erpnext.hide_naming_series();
+		this.frm.set_intro("");
+		cfn_set_fields(doc, dt, dn);
+
+		if (doc.docstatus === 0 && !doc.__islocal) {
+			this.frm.set_intro(wn._("Submit this Production Order for further processing."));
+		} else if (doc.docstatus === 1) {
+			var percent = flt(doc.produced_qty) / flt(doc.qty) * 100;
+			this.frm.dashboard.add_progress(cint(percent) + "% " + wn._("Complete"), percent);
+
+			if(doc.status === "Stopped") {
+				this.frm.dashboard.set_headline_alert(wn._("Stopped"), "alert-danger", "icon-stop");
+			}
 		}
+	},
+
+	production_item: function(doc) {
+		return this.frm.call({
+			method: "get_item_details",
+			args: { item: doc.production_item }
+		});
+	},
+
+	make_se: function(purpose) {
+		var me = this;
+
+		wn.call({
+			method:"manufacturing.doctype.production_order.production_order.make_stock_entry",
+			args: {
+				"production_order_id": me.frm.doc.name,
+				"purpose": purpose
+			},
+			callback: function(r) {
+				var doclist = wn.model.sync(r.message);
+				wn.set_route("Form", doclist[0].doctype, doclist[0].name);
+			}
+		});
 	}
-}
+});
 
 var cfn_set_fields = function(doc, dt, dn) {
 	if (doc.docstatus == 1) {
@@ -38,13 +66,6 @@
 	}
 }
 
-cur_frm.cscript.production_item = function(doc) {
-	return cur_frm.call({
-		method: "get_item_details",
-		args: { item: doc.production_item }
-	});
-}
-
 cur_frm.cscript['Stop Production Order'] = function() {
 	var doc = cur_frm.doc;
 	var check = confirm(wn._("Do you really want to stop production order: " + doc.name));
@@ -57,7 +78,7 @@
 	var doc = cur_frm.doc;
 	var check = confirm(wn._("Do really want to unstop production order: " + doc.name));
 	if (check)
-			return $c_obj(make_doclist(doc.doctype, doc.name), 'stop_unstop', 'Unstopped', function(r, rt) {cur_frm.refresh();});
+		return $c_obj(make_doclist(doc.doctype, doc.name), 'stop_unstop', 'Unstopped', function(r, rt) {cur_frm.refresh();});
 }
 
 cur_frm.cscript['Transfer Raw Materials'] = function() {
@@ -68,20 +89,6 @@
 	cur_frm.cscript.make_se('Manufacture/Repack');
 }
 
-cur_frm.cscript.make_se = function(purpose) {
-	wn.call({
-		method:"manufacturing.doctype.production_order.production_order.make_stock_entry",
-		args: {
-			"production_order_id": cur_frm.doc.name,
-			"purpose": purpose
-		},
-		callback: function(r) {
-			var doclist = wn.model.sync(r.message);
-			wn.set_route("Form", doclist[0].doctype, doclist[0].name);
-		}
-	})
-}
-
 cur_frm.fields_dict['production_item'].get_query = function(doc) {
 	return {
 		filters:[
@@ -98,7 +105,6 @@
 	}	
 }
 
-
 cur_frm.set_query("bom_no", function(doc) {
 	if (doc.production_item) {
 		return{
diff --git a/manufacturing/doctype/production_order/production_order.py b/manufacturing/doctype/production_order/production_order.py
index c5b2b04..bcb13f8 100644
--- a/manufacturing/doctype/production_order/production_order.py
+++ b/manufacturing/doctype/production_order/production_order.py
@@ -8,7 +8,6 @@
 from webnotes.model.code import get_obj
 from webnotes import msgprint, _
 
-
 class OverProductionError(webnotes.ValidationError): pass
 
 class DocType:
@@ -37,15 +36,20 @@
 				and is_active=1 and item=%s"""
 				, (self.doc.bom_no, self.doc.production_item), as_dict =1)
 			if not bom:
-				msgprint("""Incorrect BOM: %s entered. 
+				webnotes.throw("""Incorrect BOM: %s entered. 
 					May be BOM not exists or inactive or not submitted 
-					or for some other item.""" % cstr(self.doc.bom_no), raise_exception=1)
+					or for some other item.""" % cstr(self.doc.bom_no))
 					
 	def validate_sales_order(self):
 		if self.doc.sales_order:
-			if not webnotes.conn.sql("""select name from `tabSales Order` 
-					where name=%s and docstatus = 1""", self.doc.sales_order):
-				msgprint("Sales Order: %s is not valid" % self.doc.sales_order, raise_exception=1)
+			so = webnotes.conn.sql("""select name, delivery_date from `tabSales Order` 
+				where name=%s and docstatus = 1""", self.doc.sales_order, as_dict=1)[0]
+
+			if not so.name:
+				webnotes.throw("Sales Order: %s is not valid" % self.doc.sales_order)
+
+			if not self.doc.expected_delivery_date:
+				self.doc.expected_delivery_date = so.delivery_date
 			
 			self.validate_production_order_against_so()
 			
@@ -76,11 +80,11 @@
 		so_qty = flt(so_item_qty) + flt(dnpi_qty)
 				
 		if total_qty > so_qty:
-			webnotes.msgprint(_("Total production order qty for item") + ": " + 
+			webnotes.throw(_("Total production order qty for item") + ": " + 
 				cstr(self.doc.production_item) + _(" against sales order") + ": " + 
 				cstr(self.doc.sales_order) + _(" will be ") + cstr(total_qty) + ", " + 
 				_("which is greater than sales order qty ") + "(" + cstr(so_qty) + ")" + 
-				_("Please reduce qty."), raise_exception=OverProductionError)
+				_("Please reduce qty."), exc=OverProductionError)
 
 	def stop_unstop(self, status):
 		""" Called from client side on Stop/Unstop event"""
@@ -114,8 +118,8 @@
 		stock_entry = webnotes.conn.sql("""select name from `tabStock Entry` 
 			where production_order = %s and docstatus = 1""", self.doc.name)
 		if stock_entry:
-			msgprint("""Submitted Stock Entry %s exists against this production order. 
-				Hence can not be cancelled.""" % stock_entry[0][0], raise_exception=1)
+			webnotes.throw("""Submitted Stock Entry %s exists against this production order. 
+				Hence can not be cancelled.""" % stock_entry[0][0])
 
 		webnotes.conn.set(self.doc,'status', 'Cancelled')
 		self.update_planned_qty(-self.doc.qty)
diff --git a/manufacturing/doctype/production_order/production_order.txt b/manufacturing/doctype/production_order/production_order.txt
index 85c7c83..5e76c0e 100644
--- a/manufacturing/doctype/production_order/production_order.txt
+++ b/manufacturing/doctype/production_order/production_order.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-10 16:34:16", 
   "docstatus": 0, 
-  "modified": "2013-11-02 14:05:44", 
+  "modified": "2013-12-18 13:22:14", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -137,6 +137,14 @@
   "read_only": 1
  }, 
  {
+  "depends_on": "sales_order", 
+  "doctype": "DocField", 
+  "fieldname": "expected_delivery_date", 
+  "fieldtype": "Date", 
+  "label": "Expected Delivery Date", 
+  "read_only": 1
+ }, 
+ {
   "doctype": "DocField", 
   "fieldname": "warehouses", 
   "fieldtype": "Section Break", 
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index c1185a1..29232f5 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -186,7 +186,6 @@
 		else :
 			msgprint(_("No Production Order created."))
 
-
 	def get_distinct_items_and_boms(self):
 		""" Club similar BOM and item for processing
 			bom_dict {
diff --git a/patches/1311/p07_scheduler_errors_digest.py b/patches/1311/p07_scheduler_errors_digest.py
index b1fa78e..4527f18 100644
--- a/patches/1311/p07_scheduler_errors_digest.py
+++ b/patches/1311/p07_scheduler_errors_digest.py
@@ -12,14 +12,21 @@
 	if not system_managers: 
 		return
 	
+	# no default company
+	company = webnotes.conn.sql_list("select name from `tabCompany`")
+	if company:
+		company = company[0]
+	if not company:
+		return
+	
 	# scheduler errors digest
 	edigest = webnotes.new_bean("Email Digest")
 	edigest.doc.fields.update({
 		"name": "Scheduler Errors",
-		"company": webnotes.conn.get_default("company"),
+		"company": company,
 		"frequency": "Daily",
 		"enabled": 1,
 		"recipient_list": "\n".join(system_managers),
 		"scheduler_errors": 1
 	})
-	edigest.insert()
\ No newline at end of file
+	edigest.insert()
diff --git a/patches/1312/p02_update_item_details_in_item_price.py b/patches/1312/p02_update_item_details_in_item_price.py
new file mode 100644
index 0000000..c19988c
--- /dev/null
+++ b/patches/1312/p02_update_item_details_in_item_price.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	webnotes.conn.sql("""update `tabItem Price` ip INNER JOIN `tabItem` i 
+		ON (ip.item_code = i.name) 
+		set ip.item_name = i.item_name, ip.item_description = i.description""")
\ No newline at end of file
diff --git a/patches/july_2013/p07_repost_billed_amt_in_sales_cycle.py b/patches/july_2013/p07_repost_billed_amt_in_sales_cycle.py
index 6419315..95004c0 100644
--- a/patches/july_2013/p07_repost_billed_amt_in_sales_cycle.py
+++ b/patches/july_2013/p07_repost_billed_amt_in_sales_cycle.py
@@ -5,7 +5,8 @@
 
 def execute():
 	import webnotes
+	webnotes.reload_doc('stock', 'doctype', 'packed_item')
 	for si in webnotes.conn.sql("""select name from `tabSales Invoice` where docstatus = 1"""):
 		webnotes.get_obj("Sales Invoice", si[0], 
 			with_children=1).update_qty(change_modified=False)
-		webnotes.conn.commit()
\ No newline at end of file
+		webnotes.conn.commit()
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 2782c58..608ba77 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -261,4 +261,6 @@
 	"execute:webnotes.delete_doc('Report', 'Payment Made With Ageing')",
 	"patches.1311.p07_scheduler_errors_digest",
 	"patches.1311.p08_email_digest_recipients",
+	"execute:webnotes.delete_doc('DocType', 'Warehouse Type')",
+	"patches.1312.p02_update_item_details_in_item_price",
 ]
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_dropbox.py b/setup/doctype/backup_manager/backup_dropbox.py
index bbd33b5..1583f7e 100644
--- a/setup/doctype/backup_manager/backup_dropbox.py
+++ b/setup/doctype/backup_manager/backup_dropbox.py
@@ -16,8 +16,6 @@
 from webnotes.utils import get_request_site_address, cstr
 from webnotes import _
 
-from backup_manager import ignore_list
-
 @webnotes.whitelist()
 def get_dropbox_authorize_url():
 	sess = get_dropbox_session()
@@ -100,9 +98,7 @@
 	path = get_files_path()
 	for filename in os.listdir(path):
 		filename = cstr(filename)
-		if filename in ignore_list:
-			continue
-		
+
 		found = False
 		filepath = os.path.join(path, filename)
 		for file_metadata in response["contents"]:
diff --git a/setup/doctype/backup_manager/backup_manager.js b/setup/doctype/backup_manager/backup_manager.js
index c011757..6fdb9e4 100644
--- a/setup/doctype/backup_manager/backup_manager.js
+++ b/setup/doctype/backup_manager/backup_manager.js
@@ -87,7 +87,7 @@
 		cur_frm.save();
 	},
 	
-	upload_backups_to_gdrive: function() {
-		cur_frm.save();
-	},
+	// upload_backups_to_gdrive: function() {
+	// 	cur_frm.save();
+	// },
 });
\ No newline at end of file
diff --git a/setup/doctype/backup_manager/backup_manager.py b/setup/doctype/backup_manager/backup_manager.py
index 0a83dea..b094464 100644
--- a/setup/doctype/backup_manager/backup_manager.py
+++ b/setup/doctype/backup_manager/backup_manager.py
@@ -7,8 +7,6 @@
 import webnotes
 from webnotes import _
 
-ignore_list = []
-
 class DocType:
 	def __init__(self, d, dl):
 		self.doc, self.doclist = d, dl
@@ -39,10 +37,6 @@
 		file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
 		error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
 		webnotes.errprint(error_message)
-		
-		if not webnotes.conn:
-			webnotes.connect()
-			
 		send_email(False, "Dropbox", error_message)
 
 #backup to gdrive 
@@ -62,6 +56,7 @@
 		send_email(False, "Google Drive", error_message)
 
 def send_email(success, service_name, error_status=None):
+	from webnotes.utils.email_lib import sendmail
 	if success:
 		subject = "Backup Upload Successful"
 		message ="""<h3>Backup Uploaded Successfully</h3><p>Hi there, this is just to inform you 
@@ -76,7 +71,8 @@
 		<p>Please contact your system manager for more information.</p>
 		""" % (service_name, error_status)
 	
-	# email system managers
-	from webnotes.utils.email_lib import sendmail
-	sendmail(webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(","),
-		subject=subject, msg=message)
+	if not webnotes.conn:
+		webnotes.connect()
+	
+	recipients = webnotes.conn.get_value("Backup Manager", None, "send_notifications_to").split(",")
+	sendmail(recipients, subject=subject, msg=message)
diff --git a/setup/doctype/email_digest/email_digest.py b/setup/doctype/email_digest/email_digest.py
index 082b92f..f01c8a8 100644
--- a/setup/doctype/email_digest/email_digest.py
+++ b/setup/doctype/email_digest/email_digest.py
@@ -9,6 +9,7 @@
 from webnotes.utils.dateutils import datetime_in_user_format
 from datetime import timedelta
 from dateutil.relativedelta import relativedelta
+from webnotes.utils.email_lib import sendmail
 
 content_sequence = [
 	["Income / Expenses", ["income_year_to_date", "bank_balance",
@@ -80,15 +81,15 @@
 			for user_id in recipients:
 				msg_for_this_receipient = self.get_msg_html(self.get_user_specific_content(user_id) + \
 					common_msg)
-				from webnotes.utils.email_lib import sendmail
-				sendmail(recipients=user_id, 
-					subject="[ERPNext] [{frequency} Digest] {name}".format(
-						frequency=self.doc.frequency, name=self.doc.name), 
-					msg=msg_for_this_receipient)
+				if msg_for_this_receipient:
+					sendmail(recipients=user_id, 
+						subject="[ERPNext] [{frequency} Digest] {name}".format(
+							frequency=self.doc.frequency, name=self.doc.name), 
+						msg=msg_for_this_receipient)
 			
 	def get_digest_msg(self):
 		return self.get_msg_html(self.get_user_specific_content(webnotes.session.user) + \
-			self.get_common_content())
+			self.get_common_content(), send_only_if_updates=False)
 	
 	def get_common_content(self):
 		out = []
@@ -119,14 +120,19 @@
 		
 		return out
 				
-	def get_msg_html(self, out):
+	def get_msg_html(self, out, send_only_if_updates=True):
 		with_value = [o[1] for o in out if o[0]]
 		
 		if with_value:
+			has_updates = True
 			with_value = "\n".join(with_value)
 		else:
+			has_updates = False
 			with_value = "<p>There were no updates in the items selected for this digest.</p><hr>"
 		
+		if not has_updates and send_only_if_updates:
+			return
+			
 		# seperate out no value items
 		no_value = [o[1] for o in out if not o[0]]
 		if no_value:
diff --git a/setup/page/setup_wizard/setup_wizard.py b/setup/page/setup_wizard/setup_wizard.py
index b5133ef..c1d3571 100644
--- a/setup/page/setup_wizard/setup_wizard.py
+++ b/setup/page/setup_wizard/setup_wizard.py
@@ -158,6 +158,10 @@
 	hr_settings.doc.emp_created_by = "Naming Series"
 	hr_settings.save()
 
+	email_settings = webnotes.bean("Email Settings")
+	email_settings.doc.send_print_in_body_and_attachment = 1
+	email_settings.save()
+
 	# control panel
 	cp = webnotes.doc("Control Panel", "Control Panel")
 	cp.company_name = args["company_name"]
@@ -175,7 +179,8 @@
 	if not system_managers: 
 		return
 	
-	for company in webnotes.conn.sql_list("select name FROM `tabCompany`"):
+	companies = webnotes.conn.sql_list("select name FROM `tabCompany`")
+	for company in companies:
 		if not webnotes.conn.exists("Email Digest", "Default Weekly Digest - " + company):
 			edigest = webnotes.bean({
 				"doctype": "Email Digest",
@@ -192,16 +197,17 @@
 			edigest.insert()
 	
 	# scheduler errors digest
-	edigest = webnotes.new_bean("Email Digest")
-	edigest.doc.fields.update({
-		"name": "Scheduler Errors",
-		"company": webnotes.conn.get_default("company"),
-		"frequency": "Daily",
-		"recipient_list": "\n".join(system_managers),
-		"scheduler_errors": 1,
-		"enabled": 1
-	})
-	edigest.insert()
+	if companies:
+		edigest = webnotes.new_bean("Email Digest")
+		edigest.doc.fields.update({
+			"name": "Scheduler Errors",
+			"company": companies[0],
+			"frequency": "Daily",
+			"recipient_list": "\n".join(system_managers),
+			"scheduler_errors": 1,
+			"enabled": 1
+		})
+		edigest.insert()
 	
 def get_fy_details(fy_start_date, fy_end_date):
 	start_year = getdate(fy_start_date).year
diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py
index 8dbfef7..4ebf9c4 100644
--- a/stock/doctype/item/item.py
+++ b/stock/doctype/item/item.py
@@ -49,6 +49,7 @@
 	def on_update(self):
 		self.validate_name_with_item_group()
 		self.update_website()
+		self.update_item_price()
 
 	def check_warehouse_is_set_for_stock_item(self):
 		if self.doc.is_stock_item=="Yes" and not self.doc.default_warehouse:
@@ -210,6 +211,11 @@
 
 		WebsiteGenerator.on_update(self)
 
+	def update_item_price(self):
+		webnotes.conn.sql("""update `tabItem Price` set item_name=%s, 
+			item_description=%s, modified=NOW() where item_code=%s""",
+			(self.doc.item_name, self.doc.description, self.doc.name))
+
 	def get_page_title(self):
 		if self.doc.name==self.doc.item_name:
 			page_name_from = self.doc.name
diff --git a/stock/doctype/price_list/price_list.py b/stock/doctype/price_list/price_list.py
index 226b9da..d0e5d2b 100644
--- a/stock/doctype/price_list/price_list.py
+++ b/stock/doctype/price_list/price_list.py
@@ -44,5 +44,5 @@
 
 	def update_item_price(self):
 		webnotes.conn.sql("""update `tabItem Price` set currency=%s, 
-			buying_or_selling=%s where price_list=%s""", 
+			buying_or_selling=%s, modified=NOW() where price_list=%s""", 
 			(self.doc.currency, self.doc.buying_or_selling, self.doc.name))
\ No newline at end of file
diff --git a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
index 22ded6d..9a641c2 100755
--- a/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
+++ b/stock/doctype/purchase_receipt_item/purchase_receipt_item.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:10", 
   "docstatus": 0, 
-  "modified": "2013-11-02 19:41:45", 
+  "modified": "2013-12-18 10:38:39", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -326,7 +326,7 @@
   "fieldname": "schedule_date", 
   "fieldtype": "Date", 
   "label": "Required By", 
-  "no_copy": 1, 
+  "no_copy": 0, 
   "oldfieldname": "schedule_date", 
   "oldfieldtype": "Date", 
   "print_hide": 1,