[sales invoice] [fetching] fetch customer info, pos settings and item details if not fetched
diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py
index f0222a0..1861179 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/accounts/doctype/sales_invoice/sales_invoice.py
@@ -45,15 +45,7 @@
 		
 	def validate(self):
 		super(DocType, self).validate()
-		
-		if not (self.doc.contact_person and self.doc.customer_address):
-			for fieldname, val in self.get_default_address_and_contact("customer").items():
-				if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
-					self.doc.fields[fieldname] = val
-					
-		if cint(self.doc.is_pos):
-			self.set_pos_fields(for_validate=True)
-		
+		self.fetch_missing_values()
 		self.validate_posting_time()
 		self.so_dn_required()
 		self.validate_proj_cust()
@@ -145,6 +137,26 @@
 	def on_update_after_submit(self):
 		self.validate_recurring_invoice()
 		self.convert_to_recurring()
+		
+	def fetch_missing_values(self):
+		# fetch contact and address details for customer, if they are not mentioned
+		if not (self.doc.contact_person and self.doc.customer_address):
+			for fieldname, val in self.get_default_address_and_contact("customer").items():
+				if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
+					self.doc.fields[fieldname] = val
+					
+		# fetch missing item values
+		for item in self.doclist.get({"parentfield": "entries"}):
+			if item.fields.get("item_code"):
+				ret = get_obj('Sales Common').get_item_details(item.fields, self)
+				for fieldname, value in ret.items():
+					if self.meta.get_field(fieldname, parentfield="entries") and \
+						not item.fields.get(fieldname):
+							item.fields[fieldname] = value
+		
+		# fetch pos details, if they are not fetched
+		if cint(self.doc.is_pos):
+			self.set_pos_fields(for_validate=True)
 
 	def update_time_log_batch(self, sales_invoice):
 		for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
@@ -294,6 +306,7 @@
 				ret = self.apply_pos_settings(args, ret)
 			
 			return ret
+		
 		elif cint(self.doc.is_pos) == 1 and self.pos_settings:
 			for doc in self.doclist.get({"parentfield": "entries"}):
 				if doc.fields.get('item_code'):
diff --git a/accounts/doctype/sales_invoice/test_sales_invoice.py b/accounts/doctype/sales_invoice/test_sales_invoice.py
index 31bf024..b46cdd1 100644
--- a/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -90,6 +90,9 @@
 		webnotes.conn.sql("delete from `tabStock Ledger Entry`")
 		webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
 		
+		old_default_company = webnotes.conn.get_default("company")
+		webnotes.conn.set_default("company", "_Test Company")
+		
 		self._insert_purchase_receipt()
 		self._insert_pos_settings()
 		
@@ -106,7 +109,8 @@
 		
 		# check stock ledger entries
 		sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry` 
-			where voucher_type = 'Sales Invoice' and voucher_no = %s""", si.doc.name, as_dict=1)[0]
+			where voucher_type = 'Sales Invoice' and voucher_no = %s""", 
+			si.doc.name, as_dict=1)[0]
 		self.assertTrue(sle)
 		self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty], 
 			["_Test Item", "_Test Warehouse", -5.0])
@@ -145,6 +149,7 @@
 		self.assertEquals(gl_count[0][0], 16)
 			
 		webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
+		webnotes.conn.set_default("company", old_default_company)
 		
 	def test_sales_invoice_gl_entry_with_aii_no_item_code(self):		
 		webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
@@ -337,7 +342,7 @@
 		# change posting date but keep recuring day to be today
 		si7 = webnotes.bean(copy=base_si.doclist)
 		si7.doc.fields.update({
-			"posting_date": add_to_date(today, days=-3)
+			"posting_date": add_to_date(today, days=-1)
 		})
 		si7.insert()
 		si7.submit()
@@ -345,7 +350,7 @@
 		# setting so that _test function works
 		si7.doc.posting_date = today
 		self._test_recurring_invoice(si7, True)
-			
+
 	def _test_recurring_invoice(self, base_si, first_and_last_day):
 		from webnotes.utils import add_months, get_last_day, getdate
 		from accounts.doctype.sales_invoice.sales_invoice import manage_recurring_invoices
@@ -361,7 +366,8 @@
 			manage_recurring_invoices(next_date=next_date, commit=False)
 			
 			recurred_invoices = webnotes.conn.sql("""select name from `tabSales Invoice`
-				where recurring_id=%s and docstatus=1 order by name desc""", base_si.doc.recurring_id)
+				where recurring_id=%s and docstatus=1 order by name desc""",
+				base_si.doc.recurring_id)
 			
 			self.assertEquals(i+2, len(recurred_invoices))
 			
diff --git a/setup/doctype/global_defaults/global_defaults.py b/setup/doctype/global_defaults/global_defaults.py
index 191a47e..dc7f6b4 100644
--- a/setup/doctype/global_defaults/global_defaults.py
+++ b/setup/doctype/global_defaults/global_defaults.py
@@ -21,6 +21,7 @@
 from webnotes.utils import cint
 
 keydict = {
+	# "key in defaults": "key in Global Defaults"
 	"print_style": "print_style",
 	"fiscal_year": "current_fiscal_year",
 	'company': 'default_company',