Merge branch 'master' of github.com:webnotes/erpnext into unicode

Conflicts:
	erpnext/accounts/doctype/sales_invoice/sales_invoice.py
	erpnext/patches/patch_list.py
	public/js/report-legacy.js
diff --git a/erpnext/accounts/doctype/gl_control/gl_control.py b/erpnext/accounts/doctype/gl_control/gl_control.py
index 37c22d1..2acb5ef 100644
--- a/erpnext/accounts/doctype/gl_control/gl_control.py
+++ b/erpnext/accounts/doctype/gl_control/gl_control.py
@@ -555,6 +555,9 @@
 
 def assign_task_to_owner(inv, msg, users):
 	for d in users:
+		if d.lower() == 'administrator':
+			d = webnotes.conn.sql("select ifnull(email_id, '') \
+				from `tabProfile` where name = 'Administrator'")[0][0]
 		from webnotes.widgets.form import assign_to
 		args = {
 			'assign_to' 	:	d,
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index c69c5f8..4563532 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -499,12 +499,9 @@
 }
 
 // Default values for recurring invoices
-cur_frm.cscript.convert_into_recurring_invoice = function(doc) {
-	if (doc.convert_into_recurring_invoice) {
-		doc.repeat_on_day_of_month = doc.posting_date.split('-')[2];
-		doc.notification_email_address = [doc.owner, doc.contact_email].join(', ');
-		refresh_field(['repeat_on_day_of_month', 'notification_email_address']);
-	}		
+cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) {
+	if (doc.convert_into_recurring_invoice)
+		get_server_fields('set_default_recurring_values','','',doc, dt, dn, 0);
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
@@ -514,3 +511,17 @@
 	}
 	cur_frm.cscript.notify(doc, args);
 }
+
+cur_frm.cscript.invoice_period_from_date = function(doc, dt, dn) {
+	if(doc.invoice_period_from_date) {
+		var recurring_type_map = { 'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6, 'Yearly': 12 };
+
+		var months = $(recurring_type_map).attr(doc.recurring_type);
+		if(months) {
+			var to_date = wn.datetime.add_months(doc.invoice_period_from_date,
+				months);
+			doc.invoice_period_to_date = wn.datetime.add_days(to_date, -1);
+			refresh_field('invoice_period_to_date');
+		}
+	}
+}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 7b6feaf..700c585 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -636,10 +636,82 @@
 			sales_com_obj.update_prevdoc_detail(0,self)
 
 		self.make_gl_entries(is_cancel=1)
-		
 
+	# Get Warehouse
+	def get_warehouse(self):
+		w = webnotes.conn.sql("select warehouse from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company))
+		w = w and w[0][0] or ''
+		if not w:
+			ps = webnotes.conn.sql("select name, warehouse from `tabPOS Setting` where ifnull(user,'') = '' and company = '%s'" % self.doc.company)
+			if not ps:
+				msgprint("To make POS entry, please create POS Setting from Setup --> Accounts --> POS Setting and refresh the system.")
+				raise Exception
+			elif not ps[0][1]:
+				msgprint("Please enter warehouse in POS Setting")
+			else:
+				w = ps[0][1]
+		return w
+
+	# on update
+	def on_update(self):
+		# Set default warehouse from pos setting
+		#----------------------------------------
+		if cint(self.doc.is_pos) == 1:
+			self.set_actual_qty()
+			w = self.get_warehouse()
+			if w:
+				for d in getlist(self.doclist, 'entries'):
+					if not d.warehouse:
+						d.warehouse = cstr(w)
+
+			if flt(self.doc.paid_amount) == 0:
+				if self.doc.cash_bank_account: 
+					webnotes.conn.set(self.doc, 'paid_amount', 
+						(flt(self.doc.grand_total) - flt(self.doc.write_off_amount)))
+				else:
+					# show message that the amount is not paid
+					webnotes.conn.set(self.doc,'paid_amount',0)
+					webnotes.msgprint("Note: Payment Entry not created since 'Cash/Bank Account' was not specified.")
+
+		else:
+			webnotes.conn.set(self.doc,'paid_amount',0)
+
+		webnotes.conn.set(self.doc,'outstanding_amount',flt(self.doc.grand_total) - flt(self.doc.total_advance) - flt(self.doc.paid_amount) - flt(self.doc.write_off_amount))
+
+	#-------------------------------------------------------------------------------------
+
+	def set_default_recurring_values(self):
+		from webnotes.utils import cstr
+
+		owner_email = self.doc.owner
+		if owner_email.lower() == 'administrator':
+			owner_email = cstr(webnotes.conn.get_value("Profile", "Administrator", "email"))
+		
+		ret = {
+			'repeat_on_day_of_month' : getdate(self.doc.posting_date).day,
+			'notification_email_address' : ', '.join([owner_email, cstr(self.doc.contact_email)]),
+		}
+		return ret
+		
+	def validate_notification_email_id(self):
+		if self.doc.notification_email_address:
+			from webnotes.utils import validate_email_add
+			for add in self.doc.notification_email_address.replace('\n', '').replace(' ', '').split(","):
+				if add and not validate_email_add(add):
+					msgprint("%s is not a valid email address" % add, raise_exception=1)
+		else:
+			msgprint("Notification Email Addresses not specified for recurring invoice",
+				raise_exception=1)
+		
+		
+	def on_update_after_submit(self):
+		self.convert_into_recurring()
+		
+		
 	def convert_into_recurring(self):
 		if self.doc.convert_into_recurring_invoice:
+			self.validate_notification_email_id()
+			
 			if not self.doc.recurring_type:
 				msgprint("Please select recurring type", raise_exception=1)
 			elif not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date:
@@ -673,6 +745,3 @@
 
 		webnotes.conn.set(self.doc, 'next_date', next_date)
 
-
-	def on_update_after_submit(self):
-		self.convert_into_recurring()
\ No newline at end of file
diff --git a/erpnext/accounts/search_criteria/trial_balance/trial_balance.txt b/erpnext/accounts/search_criteria/trial_balance/trial_balance.txt
index 63e7b49..175c8e6 100644
--- a/erpnext/accounts/search_criteria/trial_balance/trial_balance.txt
+++ b/erpnext/accounts/search_criteria/trial_balance/trial_balance.txt
@@ -5,7 +5,7 @@
 	{
 		'creation': '2012-04-03 12:49:53',
 		'docstatus': 0,
-		'modified': '2012-04-03 12:49:53',
+		'modified': '2012-07-23 11:49:53',
 		'modified_by': u'Administrator',
 		'owner': u'Administrator'
 	},
@@ -14,7 +14,6 @@
 	{
 		'columns': u'Account\x01ID',
 		'criteria_name': u'Trial Balance',
-		'description': u'Trial Balance',
 		'dis_filters': u'transaction_date',
 		'doc_type': u'Account',
 		'doctype': 'Search Criteria',
diff --git a/erpnext/patches/july_2012/sync_trial_balance.py b/erpnext/patches/july_2012/sync_trial_balance.py
new file mode 100644
index 0000000..41e4cdf
--- /dev/null
+++ b/erpnext/patches/july_2012/sync_trial_balance.py
@@ -0,0 +1,4 @@
+def execute():
+	import webnotes
+	from webnotes.modules import reload_doc
+	reload_doc('accounts', 'search_criteria', 'trial_balance')
\ No newline at end of file
diff --git a/erpnext/patches/patch_list.py b/erpnext/patches/patch_list.py
index e15b6dc..2cb0896 100644
--- a/erpnext/patches/patch_list.py
+++ b/erpnext/patches/patch_list.py
@@ -516,4 +516,9 @@
 		'patch_file': 'unicode_conf',
 		'description': "appends from __future__ import unicode_literals to py files if necessary"
 	},
-]
\ No newline at end of file
+	{
+		'patch_module': 'patches.july_2012',
+		'patch_file': 'sync_trial_balance',
+		'description': "sync trial balance"
+	},
+]
diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py
index 76b73da..f0e85e9 100644
--- a/erpnext/selling/doctype/lead/lead.py
+++ b/erpnext/selling/doctype/lead/lead.py
@@ -69,7 +69,7 @@
 	def validate(self):
 		import string		
 		if self.doc.status == 'Lead Lost' and not self.doc.order_lost_reason:
-			msgprint("Please Enter Quotation Lost Reason")
+			msgprint("Please Enter Lost Reason under More Info section")
 			raise Exception	
 		
 		if self.doc.source == 'Campaign' and not self.doc.campaign_name and session['user'] != 'Guest':
diff --git a/erpnext/startup/js/toolbar.js b/erpnext/startup/js/toolbar.js
index 7ce9942..d0b2d88 100644
--- a/erpnext/startup/js/toolbar.js
+++ b/erpnext/startup/js/toolbar.js
@@ -34,7 +34,7 @@
 		<ul class="dropdown-menu" id="toolbar-help">\
 		</ul></li>')
 
-	$('#toolbar-help').append('<li><a href="http://erpnext.blogspot.com/2011/03/erpnext-help.html" target="_blank">\
+	$('#toolbar-help').append('<li><a href="https://erpnext.com/manual" target="_blank">\
 		Documentation</a></li>')
 
 	$('#toolbar-help').append('<li><a href="http://groups.google.com/group/erpnext-user-forum" target="_blank">\
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index 9a901af..1cd4081 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -227,5 +227,7 @@
 			
 
 	def on_cancel(self):
+		msgprint("Cancellation of stock reconciliation is temporarily suspended. The feature will come back within 2-3 days.")
+		raise Exception
 		self.get_reconciliation_data(submit = 0)
 		self.do_stock_reco(is_submit = -1)
\ No newline at end of file
diff --git a/erpnext/website/templates/html/blog_page.html b/erpnext/website/templates/html/blog_page.html
index e9c1646..3b8348d 100644
--- a/erpnext/website/templates/html/blog_page.html
+++ b/erpnext/website/templates/html/blog_page.html
@@ -34,9 +34,8 @@
 					{% endif %}
 					
 					{% include 'html/comment.html' %}
-					
-					<button class="btn add-comment">Add Comment</button>
 				</div>
+				<button class="btn add-comment">Add Comment</button>
 			</div>
 
 			<div class="layout-side-section">
diff --git a/public/js/all-app.js b/public/js/all-app.js
index 6be9a41..6e391ae 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -353,7 +353,7 @@
 this.add_field_option(this.filter_fields[i])}else{this.build_options();}},build_options:function(){var me=this;me.table_fields=[];var std_filters=[{fieldname:'name',fieldtype:'Data',label:'ID',parent:me.doctype},{fieldname:'modified',fieldtype:'Date',label:'Last Modified',parent:me.doctype},{fieldname:'owner',fieldtype:'Data',label:'Created By',parent:me.doctype},{fieldname:'creation',fieldtype:'Date',label:'Created On',parent:me.doctype},{fieldname:'_user_tags',fieldtype:'Data',label:'Tags',parent:me.doctype},{fieldname:'docstatus',fieldtype:'Int',label:'Doc Status',parent:me.doctype},];var doctype_obj=locals['DocType'][me.doctype];if(doctype_obj&&cint(doctype_obj.istable)){std_filters=std_filters.concat([{fieldname:'parent',fieldtype:'Data',label:'Parent',parent:me.doctype}]);}
 if(this.with_blank){this.$select.append($('<option>',{value:''}).text(''));}
 $.each(std_filters.concat(wn.meta.docfield_list[me.doctype]),function(i,df){me.add_field_option(df);});$.each(me.table_fields,function(i,table_df){if(table_df.options){$.each(wn.meta.docfield_list[table_df.options],function(i,df){me.add_field_option(df);});}});},add_field_option:function(df){var me=this;if(me.doctype&&df.parent==me.doctype){var label=df.label;var table=me.doctype;if(df.fieldtype=='Table')me.table_fields.push(df);}else{var label=df.label+' ('+df.parent+')';var table=df.parent;}
-if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!me.fields_by_name[df.fieldname]){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}}})
+if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!(me.fields_by_name[df.fieldname]&&me.fields_by_name[df.fieldname]['parent']==df.parent)){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}}})
 /*
  *	lib/js/wn/views/container.js
  */
@@ -2296,7 +2296,7 @@
    onclick="return false;">Help<b class="caret"></b></a>\
   <ul class="dropdown-menu" id="toolbar-help">\
   </ul></li>')
-$('#toolbar-help').append('<li><a href="http://erpnext.blogspot.com/2011/03/erpnext-help.html" target="_blank">\
+$('#toolbar-help').append('<li><a href="https://erpnext.com/manual" target="_blank">\
   Documentation</a></li>')
 $('#toolbar-help').append('<li><a href="http://groups.google.com/group/erpnext-user-forum" target="_blank">\
   Forum</a></li>')
diff --git a/public/js/all-web.js b/public/js/all-web.js
index 8f22c80..ed1fddc 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -240,7 +240,7 @@
 this.add_field_option(this.filter_fields[i])}else{this.build_options();}},build_options:function(){var me=this;me.table_fields=[];var std_filters=[{fieldname:'name',fieldtype:'Data',label:'ID',parent:me.doctype},{fieldname:'modified',fieldtype:'Date',label:'Last Modified',parent:me.doctype},{fieldname:'owner',fieldtype:'Data',label:'Created By',parent:me.doctype},{fieldname:'creation',fieldtype:'Date',label:'Created On',parent:me.doctype},{fieldname:'_user_tags',fieldtype:'Data',label:'Tags',parent:me.doctype},{fieldname:'docstatus',fieldtype:'Int',label:'Doc Status',parent:me.doctype},];var doctype_obj=locals['DocType'][me.doctype];if(doctype_obj&&cint(doctype_obj.istable)){std_filters=std_filters.concat([{fieldname:'parent',fieldtype:'Data',label:'Parent',parent:me.doctype}]);}
 if(this.with_blank){this.$select.append($('<option>',{value:''}).text(''));}
 $.each(std_filters.concat(wn.meta.docfield_list[me.doctype]),function(i,df){me.add_field_option(df);});$.each(me.table_fields,function(i,table_df){if(table_df.options){$.each(wn.meta.docfield_list[table_df.options],function(i,df){me.add_field_option(df);});}});},add_field_option:function(df){var me=this;if(me.doctype&&df.parent==me.doctype){var label=df.label;var table=me.doctype;if(df.fieldtype=='Table')me.table_fields.push(df);}else{var label=df.label+' ('+df.parent+')';var table=df.parent;}
-if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!me.fields_by_name[df.fieldname]){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}}})
+if(wn.model.no_value_type.indexOf(df.fieldtype)==-1&&!(me.fields_by_name[df.fieldname]&&me.fields_by_name[df.fieldname]['parent']==df.parent)){this.$select.append($('<option>',{value:df.fieldname,table:table}).text(label));me.fields_by_name[df.fieldname]=df;}}})
 /*
  *	lib/js/wn/views/container.js
  */
diff --git a/public/js/report-legacy.js b/public/js/report-legacy.js
index 4228c86..d2d67c5 100644
--- a/public/js/report-legacy.js
+++ b/public/js/report-legacy.js
@@ -28,7 +28,7 @@
 _r.ReportBuilder.prototype.clear_criteria=function(){this.column_picker.clear();this.column_picker.set_defaults();for(var i=0;i<this.filter_fields.length;i++){this.filter_fields[i].df.filter_hide=0;this.filter_fields[i].df.ignore=0;if(this.filter_fields[i].is_custom){this.filter_fields[i].df.filter_hide=1;this.filter_fields[i].df.ignore=1;}
 this.filter_fields[i].set_input(null);}
 this.set_sort_options();this.set_main_title('Report: '+get_doctype_label(this.doctype));this.current_loaded=null;this.customized_filters=null;this.sc=null;this.has_index=1;this.has_headings=1;for(var i in this.fn_list)this[this.fn_list[i]]=null;}
-_r.ReportBuilder.prototype.set_main_title=function(t,t1){var title=t+(t1?t1:'');_r.rb_con.appframe.$titlebar.find('.report-title').html(title);set_title(title);}
+_r.ReportBuilder.prototype.set_main_title=function(title){_r.rb_con.appframe.$titlebar.find('.report-title').html(title);set_title(title);}
 _r.ReportBuilder.prototype.select_column=function(dt,label,value){if(value==null)value=1;this.column_picker.set(dt,label,value);}
 _r.ReportBuilder.prototype.set_filter=function(dt,label,value){if(this.filter_fields_dict[dt+'\1'+label])
 this.filter_fields_dict[dt+'\1'+label].set_input(value);}
@@ -44,7 +44,7 @@
 this.set_sort_options(new_sl);if(sc&&sc.sort_by){this.dt.sort_sel.value=sc.sort_by;}
 if(sc&&sc.sort_order){sc.sort_order=='ASC'?this.dt.set_asc():this.dt.set_desc();}
 if(sc&&sc.page_len){this.dt.page_len_sel.inp.value=sc.page_len;}
-this.current_loaded=criteria_name;this.set_main_title(criteria_name,sc.description);}
+this.current_loaded=criteria_name;this.set_main_title(criteria_name);}
 _r.ReportBuilder.prototype.setup_filters_and_cols=function(){function can_dt_be_submitted(dt){return locals.DocType[dt]&&locals.DocType[dt].is_submittable||0;}
 var me=this;var dt=me.parent_dt?me.parent_dt:me.doctype;var fl=[{'fieldtype':'Data','label':'ID','fieldname':'name','in_filter':1,'parent':dt},{'fieldtype':'Data','label':'Owner','fieldname':'owner','in_filter':1,'parent':dt},{'fieldtype':'Date','label':'Created on','fieldname':'creation','in_filter':0,'parent':dt},{'fieldtype':'Date','label':'Last modified on','fieldname':'modified','in_filter':0,'parent':dt},];if(can_dt_be_submitted(dt)){fl[fl.length]={'fieldtype':'Check','label':'Saved','fieldname':'docstatus','search_index':1,'in_filter':1,'def_filter':1,'parent':dt};fl[fl.length]={'fieldtype':'Check','label':'Submitted','fieldname':'docstatus','search_index':1,'in_filter':1,'def_filter':1,'parent':dt};fl[fl.length]={'fieldtype':'Check','label':'Cancelled','fieldname':'docstatus','search_index':1,'in_filter':1,'parent':dt};}
 me.make_datatable();me.orig_sort_list=[];if(me.parent_dt){me.setup_dt_filters_and_cols(fl,me.parent_dt);var fl=[];}