profile: form is now my settings page, removed (Page, profile-settings)
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index 5dbe20d..3763abb 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -395,6 +395,11 @@
 			if not d.item_code:
 				msgprint("Please enter Item Code at line no : %s to update stock for POS or remove check from Update Stock in Basic Info Tab." % (d.idx))
 				raise Exception
+				
+	def validate_delivery_note(self):
+		for d in self.doclist.get({"parentfield": "entries"}):
+			if d.delivery_note:
+				msgprint("""POS can not be made against Delivery Note""", raise_exception=1)
 
 
 	def validate_write_off_account(self):
@@ -447,6 +452,7 @@
 				sl.validate_serial_no(self, 'packing_details')
 				self.validate_item_code()
 				self.update_current_stock()
+				self.validate_delivery_note()
 		self.set_in_words()
 		if not self.doc.is_opening:
 			self.doc.is_opening = 'No'
@@ -505,7 +511,9 @@
 			self.doclist = self.doc.clear_table(self.doclist, 'packing_details')
 			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))
+		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 check_prev_docstatus(self):
@@ -533,7 +541,7 @@
 			'posting_time'				: self.doc.posting_time,
 			'voucher_type'				: 'Sales Invoice',
 			'voucher_no'					: cstr(self.doc.name),
-			'voucher_detail_no'	 : cstr(d['name']), 
+			'voucher_detail_no'	 		: cstr(d['name']), 
 			'actual_qty'					: qty, 
 			'stock_uom'					 : st_uom and st_uom[0][0] or '',
 			'incoming_rate'			 : in_value,
@@ -604,13 +612,13 @@
 				
 				self.update_stock_ledger(update_stock=1)
 		else:
-			self.check_prev_docstatus()
-			get_obj("Sales Common").update_prevdoc_detail(1,self)
-
 			# Check for Approving Authority
 			if not self.doc.recurring_id:
 				get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self)
 
+		self.check_prev_docstatus()
+		get_obj("Sales Common").update_prevdoc_detail(1,self)
+		
 		# this sequence because outstanding may get -ve		
 		self.make_gl_entries()
 
@@ -628,11 +636,11 @@
 				sl.update_serial_record(self, 'packing_details', is_submit = 0, is_incoming = 0)
 				
 				self.update_stock_ledger(update_stock = -1)
-		else:
-			sales_com_obj = get_obj(dt = 'Sales Common')
-			sales_com_obj.check_stop_sales_order(self)
-			self.check_next_docstatus()
-			sales_com_obj.update_prevdoc_detail(0,self)
+		
+		sales_com_obj = get_obj(dt = 'Sales Common')
+		sales_com_obj.check_stop_sales_order(self)
+		self.check_next_docstatus()
+		sales_com_obj.update_prevdoc_detail(0, self)
 
 		self.make_gl_entries(is_cancel=1)
 
diff --git a/patches/november_2012/update_delivered_billed_percentage_for_pos.py b/patches/november_2012/update_delivered_billed_percentage_for_pos.py
new file mode 100644
index 0000000..502a36a
--- /dev/null
+++ b/patches/november_2012/update_delivered_billed_percentage_for_pos.py
@@ -0,0 +1,15 @@
+def execute():
+	import webnotes
+	from webnotes.model.code import get_obj
+	
+	sc_obj = get_obj("Sales Common")
+	
+	si = webnotes.conn.sql("""select distinct si.name 
+		from `tabSales Invoice` si, `tabSales Invoice Item` si_item
+		where si_item.parent = si.name
+		and si.docstatus = 1
+		and ifnull(si.is_pos, 0) = 1
+		and ifnull(si_item.sales_order, '') != ''
+	""")
+	for d in si:
+		sc_obj.update_prevdoc_detail(1, get_obj("Sales Invoice", d[0], with_children=1))
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index 7a60938..0bf4d3c 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -693,6 +693,10 @@
 	},
 	{
 		'patch_module': 'patches.november_2012',
+		'patch_file': 'update_delivered_billed_percentage_for_pos',
+	},
+	{
+		'patch_module': 'patches.november_2012',
 		'patch_file': 'add_theme_to_profile',
 	},
 ]
\ No newline at end of file
diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py
index 2a8182d..8ea4fe4 100644
--- a/selling/doctype/sales_common/sales_common.py
+++ b/selling/doctype/sales_common/sales_common.py
@@ -829,7 +829,22 @@
 				'status_field'			:'billing_status',
 				'keyword'				:'Billed'
 			})
-
+			
+			if cint(self.obj.doc.is_pos) == 1:
+				self.update_qty({
+					'target_field'			:'delivered_qty',
+					'target_dt'				:'Sales Order Item',
+					'target_parent_dt'		:'Sales Order',
+					'target_parent_field'	:'per_delivered',
+					'target_ref_field'		:'qty',
+					'source_dt'				:'Sales Invoice Item',
+					'source_field'			:'qty',
+					'join_field'			:'so_detail',
+					'percent_join_field'	:'sales_order',
+					'status_field'			:'delivery_status',
+					'keyword'				:'Delivered'
+				})
+				
 		if self.obj.doc.doctype=='Installation Note':
 			self.update_qty({
 				'target_field'			:'installed_qty',