Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/accounts/doctype/pos_setting/pos_setting.txt b/accounts/doctype/pos_setting/pos_setting.txt
index 36b9b94..73b9246 100755
--- a/accounts/doctype/pos_setting/pos_setting.txt
+++ b/accounts/doctype/pos_setting/pos_setting.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 12:15:51", 
   "docstatus": 0, 
-  "modified": "2013-08-09 14:45:28", 
+  "modified": "2013-08-09 16:35:03", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -131,12 +131,12 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "customer_account", 
+  "fieldname": "customer", 
   "fieldtype": "Link", 
-  "label": "Customer Account", 
+  "label": "Customer", 
   "oldfieldname": "customer_account", 
   "oldfieldtype": "Link", 
-  "options": "Account", 
+  "options": "Customer", 
   "read_only": 0, 
   "reqd": 0
  }, 
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index 6979f1f..87afd74 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -197,18 +197,10 @@
 		if pos:
 			self.doc.conversion_rate = flt(pos.conversion_rate)
 			
-			if not self.doc.debit_to:
-				self.doc.debit_to = self.doc.customer and webnotes.conn.get_value("Account", {
-					"name": self.doc.customer + " - " + self.get_company_abbr(), 
-					"docstatus": ["!=", 2]
-				}) or pos.customer_account
-				
-			if self.doc.debit_to and not self.doc.customer:
-				self.doc.customer = webnotes.conn.get_value("Account", {
-					"name": self.doc.debit_to,
-					"master_type": "Customer"
-				}, "master_name")
-				
+			if not for_validate:
+				self.doc.customer = pos.customer
+				self.set_customer_defaults()
+
 			for fieldname in ('territory', 'naming_series', 'currency', 'charge', 'letter_head', 'tc_name',
 				'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account'):
 					if (not for_validate) or (for_validate and not self.doc.fields.get(fieldname)):
diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py
index 690bd55..f1646f7 100644
--- a/hr/doctype/employee/employee.py
+++ b/hr/doctype/employee/employee.py
@@ -45,6 +45,7 @@
 		if self.doc.user_id:
 			self.update_user_default()
 			self.update_profile()
+		self.update_dob_event()
 				
 	def update_user_default(self):
 		webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id)
@@ -154,6 +155,35 @@
 				msgprint(_("Invalid Leave Approver") + ": \"" + l.leave_approver + "\"",
 					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' 
+				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]))
+			else:
+				webnotes.bean({
+					"doctype": "Event",
+					"subject": _("Birthday") + ": " + self.doc.employee_name,
+					"starts_on": starts_on,
+					"ends_on": ends_on,
+					"event_type": "Public",
+					"all_day": 1,
+					"send_reminder": 1,
+					"repeat_this_event": 1,
+					"repeat_on": "Every Year",
+					"ref_type": "Employee",
+					"ref_name": self.doc.name
+				}).insert()
+		else:
+			webnotes.conn.sql("""delete from `tabEvent` where repeat_on='Every Year' and
+				ref_type='Employee' and ref_name=%s""", self.doc.name)
+
 @webnotes.whitelist()
 def get_retirement_date(date_of_birth=None):
 	import datetime
diff --git a/patches/august_2013/p02_rename_price_list.py b/patches/august_2013/p02_rename_price_list.py
index cea7c79..a66a0c2 100644
--- a/patches/august_2013/p02_rename_price_list.py
+++ b/patches/august_2013/p02_rename_price_list.py
@@ -1,3 +1,7 @@
+# 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():
diff --git a/patches/august_2013/p03_pos_setting_replace_customer_account.py b/patches/august_2013/p03_pos_setting_replace_customer_account.py
new file mode 100644
index 0000000..c3a21e4
--- /dev/null
+++ b/patches/august_2013/p03_pos_setting_replace_customer_account.py
@@ -0,0 +1,24 @@
+# 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.reload_doc("accounts", "doctype", "pos_setting")
+	if "customer_account" in webnotes.conn.get_table_columns("POS Setting"):
+		customer_account = webnotes.conn.sql("""select customer_account, name from `tabPOS Setting` 
+			where ifnull(customer_account, '')!=''""")
+
+		for cust_acc, pos_name in customer_account:
+			customer = webnotes.conn.sql("""select master_name, account_name from `tabAccount` 
+				where name=%s""", (cust_acc), as_dict=1)
+
+			if not customer[0].master_name:
+				customer_name = webnotes.conn.get_value('Customer', customer[0].account_name, 'name')
+			else:
+				customer_name = customer[0].master_name
+
+			webnotes.conn.set_value('POS Setting', pos_name, 'customer', customer_name)
+		
+		webnotes.conn.sql_ddl("""alter table `tabPOS Setting` drop column `customer_account`""")
diff --git a/patches/august_2013/p04_employee_birthdays.py b/patches/august_2013/p04_employee_birthdays.py
new file mode 100644
index 0000000..6e8481d
--- /dev/null
+++ b/patches/august_2013/p04_employee_birthdays.py
@@ -0,0 +1,11 @@
+# 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/patch_list.py b/patches/patch_list.py
index 95b10b7..9e6938b 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -253,4 +253,6 @@
 	"execute:webnotes.bean('Selling Settings').save() #2013-07-29",
 	"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",
 ]
\ No newline at end of file