[minor] merge master
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index e4adcea..b017f04 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -150,12 +150,22 @@
 		
 	def set_missing_values(self, for_validate=False):
 		self.set_pos_fields(for_validate)
+		
+		if not self.doc.debit_to:
+			self.doc.debit_to = self.get_customer_account()
+		if not self.doc.due_date:
+			self.doc.due_date = self.get_due_date()
+		
 		super(DocType, self).set_missing_values(for_validate)
 		
 	def set_customer_defaults(self):
 		# TODO cleanup these methods
-		self.doc.fields.update(self.get_debit_to())
-		self.get_cust_and_due_date()
+		if self.doc.customer:
+			self.doc.debit_to = self.get_customer_account()
+		elif self.doc.debit_to:
+			self.doc.customer = webnotes.conn.get_value('Account', self.doc.debit_to, 'master_name')
+		
+		self.doc.due_date = self.get_due_date()
 		
 		super(DocType, self).set_customer_defaults()
 			
@@ -231,16 +241,9 @@
 					You must first create it from the Customer Master" % 
 					(self.doc.customer, self.doc.company))
 
-	def get_debit_to(self):
-		acc_head = self.get_customer_account()
-		return acc_head and {'debit_to' : acc_head} or {}
-
-
-	def get_cust_and_due_date(self):
+	def get_due_date(self):
 		"""Set Due Date = Posting Date + Credit Days"""
-		if self.doc.debit_to:
-			self.doc.customer = webnotes.conn.get_value('Account', self.doc.debit_to, 'master_name')
-			
+		due_date = None
 		if self.doc.posting_date:
 			credit_days = 0
 			if self.doc.debit_to:
@@ -251,9 +254,11 @@
 				credit_days = webnotes.conn.get_value("Company", self.doc.company, "credit_days")
 				
 			if credit_days:
-				self.doc.due_date = add_days(self.doc.posting_date, credit_days)
+				due_date = add_days(self.doc.posting_date, credit_days)
 			else:
-				self.doc.due_date = self.doc.posting_date
+				due_date = self.doc.posting_date
+
+		return due_date
 
 	def get_barcode_details(self, barcode):
 		return get_obj('Sales Common').get_barcode_details(barcode)
diff --git a/accounts/page/financial_statements/financial_statements.txt b/accounts/page/financial_statements/financial_statements.txt
index 78c2c30..18f8904 100644
--- a/accounts/page/financial_statements/financial_statements.txt
+++ b/accounts/page/financial_statements/financial_statements.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-27 16:30:52", 
   "docstatus": 0, 
-  "modified": "2013-07-11 14:41:59", 
+  "modified": "2013-08-14 12:47:45", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -19,14 +19,18 @@
   "name": "__common__", 
   "parent": "Financial Statements", 
   "parentfield": "roles", 
-  "parenttype": "Page", 
-  "role": "Accounts Manager"
+  "parenttype": "Page"
  }, 
  {
   "doctype": "Page", 
   "name": "Financial Statements"
  }, 
  {
-  "doctype": "Page Role"
+  "doctype": "Page Role", 
+  "role": "Accounts Manager"
+ }, 
+ {
+  "doctype": "Page Role", 
+  "role": "Analytics"
  }
 ]
\ No newline at end of file
diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js
index 9ffec3a..594b015 100644
--- a/accounts/page/general_ledger/general_ledger.js
+++ b/accounts/page/general_ledger/general_ledger.js
@@ -389,7 +389,8 @@
 			grid: { hoverable: true, clickable: true },
 			xaxis: { mode: "time", 
 				min: dateutil.str_to_obj(this.from_date).getTime(),
-				max: dateutil.str_to_obj(this.to_date).getTime() }
+				max: dateutil.str_to_obj(this.to_date).getTime() },
+			series: { downsample: { threshold: 1000 } }
 		}
 	},
 });
\ No newline at end of file
diff --git a/controllers/js/contact_address_common.js b/controllers/js/contact_address_common.js
index 82dad0e..7589947 100644
--- a/controllers/js/contact_address_common.js
+++ b/controllers/js/contact_address_common.js
@@ -16,11 +16,14 @@
 	if(doc.__islocal) {
 		var last_route = wn.route_history.slice(-2, -1)[0];
 		if(last_route && last_route[0]==="Form") {
+			var doctype = last_route[1],
+				docname = last_route.slice(2).join("/");
+			
 			if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
 				"Installation Note", "Opportunity", "Customer Issue", "Maintenance Visit",
 				"Maintenance Schedule"]
-				.indexOf(last_route[1])!==-1) {
-				var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
+				.indexOf(doctype)!==-1) {
+				var refdoc = wn.model.get_doc(doctype, docname);
 
 				if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Customer" : true) {
 					cur_frm.set_value("customer", refdoc.customer || refdoc.name);
@@ -30,16 +33,16 @@
 				}
 			}
 			if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
-				.indexOf(last_route[1])!==-1) {
-				var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
+				.indexOf(doctype)!==-1) {
+				var refdoc = wn.model.get_doc(doctype, docname);
 				cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
 				cur_frm.set_value("supplier_name", refdoc.supplier_name);
 				if(cur_frm.doc.doctype==="Address")
 					cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
 			}
 			if(["Lead", "Quotation"]
-				.indexOf(last_route[1])!==-1) {
-				var refdoc = wn.model.get_doc(last_route[1], last_route[2]);
+				.indexOf(doctype)!==-1) {
+				var refdoc = wn.model.get_doc(doctype, docname);
 				
 				if(refdoc.doctype == "Quotation" ? refdoc.quotation_to=="Lead" : true) {
 					cur_frm.set_value("lead", refdoc.lead || refdoc.name);
diff --git a/controllers/queries.py b/controllers/queries.py
index 381d2c8..0e23d5c 100644
--- a/controllers/queries.py
+++ b/controllers/queries.py
@@ -207,4 +207,4 @@
 				"fcond": get_filters_cond(doctype, filters, []),
 				"mcond": get_match_cond(doctype),
 				"start": "%(start)s", "page_len": "%(page_len)s", "txt": "%(txt)s"
-			}, { "start": start, "page_len": page_len, "txt": ("%%%s%%" % txt) }, debug=True)
\ No newline at end of file
+			}, { "start": start, "page_len": page_len, "txt": ("%%%s%%" % txt) })
\ No newline at end of file
diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py
index 2e1f1ea..621feaf 100644
--- a/controllers/selling_controller.py
+++ b/controllers/selling_controller.py
@@ -14,12 +14,8 @@
 	def onload_post_render(self):
 		# contact, address, item details and pos details (if applicable)
 		self.set_missing_values()
-		
 		self.set_taxes("other_charges", "charge")
 		
-		if self.meta.get_field("debit_to") and not self.doc.debit_to:
-			self.doc.debit_to = self.get_debit_to().get("debit_to")
-			
 	def set_missing_values(self, for_validate=False):
 		super(SellingController, self).set_missing_values(for_validate)
 		
diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py
index f1646f7..e28e02d 100644
--- a/hr/doctype/employee/employee.py
+++ b/hr/doctype/employee/employee.py
@@ -156,20 +156,23 @@
 					raise_exception=InvalidLeaveApproverError)
 
 	def update_dob_event(self):
-		if self.doc.date_of_birth:
-			get_events = webnotes.conn.sql("""select name from `tabEvent` where repeat_on='Every Year' 
+		if self.doc.status == "Active" and self.doc.date_of_birth:
+			birthday_event = webnotes.conn.sql("""select name from `tabEvent` where repeat_on='Every Year' 
 				and ref_type='Employee' and ref_name=%s""", self.doc.name)
 
 			starts_on = self.doc.date_of_birth + " 00:00:00"
 			ends_on = self.doc.date_of_birth + " 00:15:00"
 
-			if get_events:
-				webnotes.conn.sql("""update `tabEvent` set starts_on=%s, ends_on=%s 
-					where name=%s""", (starts_on, ends_on, get_events[0][0]))
+			if birthday_event:
+				event = webnotes.bean("Event", birthday_event[0][0])
+				event.doc.starts_on = starts_on
+				event.doc.ends_on = ends_on
+				event.save()
 			else:
 				webnotes.bean({
 					"doctype": "Event",
 					"subject": _("Birthday") + ": " + self.doc.employee_name,
+					"description": _("Happy Birthday!") + " " + self.doc.employee_name,
 					"starts_on": starts_on,
 					"ends_on": ends_on,
 					"event_type": "Public",
diff --git a/install_erpnext.py b/install_erpnext.py
index 1a802ae..105faa0 100644
--- a/install_erpnext.py
+++ b/install_erpnext.py
@@ -59,7 +59,7 @@
 	return is_redhat, is_debian
 		
 def install_using_yum():
-	packages = "python python-setuptools MySQL-python httpd git memcached ntp vim-enhanced screen"
+	packages = "python python-setuptools gcc python-devel MySQL-python httpd git memcached ntp vim-enhanced screen"
 	
 	print "-"*80
 	print "Installing Packages: (This may take some time)"
@@ -108,7 +108,7 @@
 	
 def install_using_apt():
 	exec_in_shell("apt-get update")
-	packages = "python python-setuptools python-mysqldb apache2 git memcached ntp vim screen htop"
+	packages = "python python-setuptools python-dev build-essential python-pip python-mysqldb apache2 git memcached ntp vim screen htop"
 	print "-"*80
 	print "Installing Packages: (This may take some time)"
 	print packages
@@ -145,7 +145,11 @@
 	print python_modules
 	print "-"*80
 	
-	exec_in_shell("easy_install pip")
+	if not exec_in_shell("which pip"):
+		exec_in_shell("easy_install pip")
+	
+	exec_in_shell("pip install --upgrade pip")
+	exec_in_shell("pip install --upgrade virtualenv")
 	exec_in_shell("pip install -q %s" % python_modules)
 	
 def install_erpnext(install_path):
diff --git a/manufacturing/doctype/production_order/production_order.py b/manufacturing/doctype/production_order/production_order.py
index 90a74e9..f86a55d 100644
--- a/manufacturing/doctype/production_order/production_order.py
+++ b/manufacturing/doctype/production_order/production_order.py
@@ -148,6 +148,7 @@
 	stock_entry.doc.production_order = production_order_id
 	stock_entry.doc.company = production_order.doc.company
 	stock_entry.doc.bom_no = production_order.doc.bom_no
+	stock_entry.doc.use_multi_level_bom = production_order.doc.use_multi_level_bom
 	stock_entry.doc.fg_completed_qty = flt(production_order.doc.qty) - flt(production_order.doc.produced_qty)
 	
 	if purpose=="Material Transfer":
@@ -155,5 +156,5 @@
 	else:
 		stock_entry.doc.from_warehouse = production_order.doc.wip_warehouse
 		stock_entry.doc.to_warehouse = production_order.doc.fg_warehouse
-		
+
 	return [d.fields for d in stock_entry.doclist]
diff --git a/patches/august_2013/p04_employee_birthdays.py b/patches/august_2013/p04_employee_birthdays.py
deleted file mode 100644
index 6e8481d..0000000
--- a/patches/august_2013/p04_employee_birthdays.py
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import webnotes
-
-def execute():
-	for employee in webnotes.conn.sql_list("""select name from `tabEmployee` where ifnull(date_of_birth, '')!=''"""):
-		obj = webnotes.get_obj("Employee", employee)
-		obj.update_dob_event()
-		
\ No newline at end of file
diff --git a/patches/august_2013/p05_employee_birthdays.py b/patches/august_2013/p05_employee_birthdays.py
new file mode 100644
index 0000000..9ad0c99
--- /dev/null
+++ b/patches/august_2013/p05_employee_birthdays.py
@@ -0,0 +1,13 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+
+def execute():
+	webnotes.conn.sql("""delete from `tabEvent` where repeat_on='Every Year' and ref_type='Employee'""")
+	for employee in webnotes.conn.sql_list("""select name from `tabEmployee` where status='Active' and 
+		ifnull(date_of_birth, '')!=''"""):
+			obj = webnotes.get_obj("Employee", employee)
+			obj.update_dob_event()
+		
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 99514d2..d8b9c72 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -253,6 +253,6 @@
 	"patches.august_2013.p01_hr_settings",
 	"patches.august_2013.p02_rename_price_list",
 	"patches.august_2013.p03_pos_setting_replace_customer_account",
-	"patches.august_2013.p04_employee_birthdays",
 	"patches.august_2013.p05_update_serial_no_status",
+	"patches.august_2013.p05_employee_birthdays",
 ]
\ No newline at end of file
diff --git a/selling/utils.py b/selling/utils.py
index 86b1b9d..1c0ed84 100644
--- a/selling/utils.py
+++ b/selling/utils.py
@@ -69,12 +69,18 @@
 	
 	if cint(args.is_pos):
 		pos_settings = get_pos_settings(args.company)
+<<<<<<< HEAD
 		out.update(apply_pos_settings(pos_settings, out))
 		
 	if args.doctype in ("Sales Invoice", "Delivery Note"):
 		if item_bean.doc.has_serial_no and not args.serial_no:
 			out.serial_no = _get_serial_nos_by_fifo(args, item_bean)
 		
+=======
+		if pos_settings:
+			out.update(apply_pos_settings(pos_settings, out))
+
+>>>>>>> 3d1ecf5254c5887a48c04003c7dce8a218136ddd
 	return out
 
 def _get_serial_nos_by_fifo(args, item_bean):
diff --git a/stock/page/stock_ageing/stock_ageing.js b/stock/page/stock_ageing/stock_ageing.js
index fe2c0d6..920ac84 100644
--- a/stock/page/stock_ageing/stock_ageing.js
+++ b/stock/page/stock_ageing/stock_ageing.js
@@ -176,7 +176,8 @@
 			xaxis: {  
 				ticks: $.map(me.data, function(item, idx) { return [[idx+1, item.name]] }),
 				max: 20
-			}
+			},
+			series: { downsample: { threshold: 1000 } }
 		}
 	}	
 });
\ No newline at end of file
diff --git a/stock/page/stock_ledger/stock_ledger.js b/stock/page/stock_ledger/stock_ledger.js
index 33bceeb..dacd78c 100644
--- a/stock/page/stock_ledger/stock_ledger.js
+++ b/stock/page/stock_ledger/stock_ledger.js
@@ -235,6 +235,7 @@
 				min: dateutil.str_to_obj(this.from_date).getTime(),
 				max: dateutil.str_to_obj(this.to_date).getTime(),
 			},
+			series: { downsample: { threshold: 1000 } }
 		}
 	},
 	get_tooltip_text: function(label, x, y) {