updated update_feed method in init file of home
diff --git a/material_management/__init__.pyc b/material_management/__init__.pyc
new file mode 100644
index 0000000..38edace
--- /dev/null
+++ b/material_management/__init__.pyc
Binary files differ
diff --git a/material_management/doctype/__init__.pyc b/material_management/doctype/__init__.pyc
new file mode 100644
index 0000000..ceda4b0
--- /dev/null
+++ b/material_management/doctype/__init__.pyc
Binary files differ
diff --git a/material_management/doctype/stock_entry/stock_entry.py b/material_management/doctype/stock_entry/stock_entry.py
index b671781..a07f769 100644
--- a/material_management/doctype/stock_entry/stock_entry.py
+++ b/material_management/doctype/stock_entry/stock_entry.py
@@ -16,7 +16,6 @@
 	
 # -----------------------------------------------------------------------------------------
 
-
 class DocType:
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc
@@ -59,6 +58,7 @@
 
 
 	# Get UOM Details
+	# ----------------
 	def get_uom_details(self, arg = ''):
 		arg, ret = eval(arg), {}
 		uom = sql("select conversion_factor from `tabUOM Conversion Detail` where parent = %s and uom = %s", (arg['item_code'],arg['uom']), as_dict = 1)
@@ -252,7 +252,7 @@
 		self.validate_for_production_order(pro_obj)
 		self.validate_incoming_rate()
 		self.validate_warehouse(pro_obj)
-		self.get_current_stock(pro_obj.doc.bom_no)
+		self.get_stock_and_rate(pro_obj and pro_obj.doc.bom_no or '')
 		self.calc_amount()
 		get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
 				
diff --git a/material_management/doctype/stock_entry/stock_entry.py~ b/material_management/doctype/stock_entry/stock_entry.py~
new file mode 100644
index 0000000..e90cdce
--- /dev/null
+++ b/material_management/doctype/stock_entry/stock_entry.py~
@@ -0,0 +1,429 @@
+# Please edit this list and import only required elements
+import webnotes
+
+from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.model import db_exists, delete_doc
+from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
+from webnotes.model.doclist import getlist, copy_doclist
+from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
+from webnotes import session, form, is_testing, msgprint, errprint
+
+set = webnotes.conn.set
+sql = webnotes.conn.sql
+get_value = webnotes.conn.get_value
+in_transaction = webnotes.conn.in_transaction
+convert_to_lists = webnotes.conn.convert_to_lists
+	
+# -----------------------------------------------------------------------------------------
+
+class DocType:
+	def __init__(self, doc, doclist=[]):
+		self.doc = doc
+		self.doclist = doclist
+		self.item_dict = {}
+		self.fname = 'mtn_details' 
+
+	# Autoname
+	# ---------
+	def autoname(self):
+		self.doc.name = make_autoname(self.doc.naming_series+'.#####')
+
+  
+	# get item details
+	# ----------------
+	def get_item_details(self, arg):
+		arg, actual_qty, in_rate = eval(arg), 0, 0
+
+		item = sql("select stock_uom, description, item_name from `tabItem` where name = %s and (ifnull(end_of_life,'')='' or end_of_life ='0000-00-00' or end_of_life >	now())", (arg.get('item_code')), as_dict = 1)
+		if not item: 
+			msgprint("Item is not active", raise_exception=1)
+			
+		if arg.get('warehouse'):
+			actual_qty = self.get_as_on_stock(arg.get('item_code'), arg.get('warehouse'), self.doc.posting_date, self.doc.posting_time)
+			in_rate = self.get_incoming_rate(arg.get('item_code'), arg.get('warehouse'), self.doc.posting_date, self.doc.posting_time, arg.get('transfer_qty'), arg.get('serial_no')) or 0
+			
+		ret = {
+			'uom'			      	: item and item[0]['stock_uom'] or '',
+			'stock_uom'			  	: item and item[0]['stock_uom'] or '',
+			'description'		  	: item and item[0]['description'] or '',
+			'item_name' 		  	: item and item[0]['item_name'] or '',
+			'actual_qty'		  	: actual_qty,
+			'qty'					: 0,
+			'transfer_qty'			: 0,
+			'incoming_rate'	  		: in_rate,
+			'conversion_factor'		: 1,
+     		'batch_no'          	: ''
+		}
+		return str(ret)
+
+
+	# Get UOM Details
+	# ----------------
+	def get_uom_details(self, arg = ''):
+		arg, ret = eval(arg), {}
+		uom = sql("select conversion_factor from `tabUOM Conversion Detail` where parent = %s and uom = %s", (arg['item_code'],arg['uom']), as_dict = 1)
+		if not uom:
+			msgprint("There is no Conversion Factor for UOM '%s' in Item '%s'" % (arg['uom'], arg['item_code']))
+			ret = {'uom' : ''}
+		else:
+			ret = {
+				'conversion_factor'		: flt(uom[0]['conversion_factor']),
+				'transfer_qty'			: flt(arg['qty']) * flt(uom[0]['conversion_factor']),
+			}
+		return str(ret)
+
+		
+	# get stock and incoming rate on posting date
+	# ---------------------------------------------
+	def get_stock_and_rate(self, bom_no = ''):
+		for d in getlist(self.doclist, 'mtn_details'):
+			# assign parent warehouse
+			d.s_warehouse = cstr(d.s_warehouse) or self.doc.purpose != 'Production Order' and self.doc.from_warehouse or ''
+			d.t_warehouse = cstr(d.t_warehouse) or self.doc.purpose != 'Production Order' and self.doc.to_warehouse or ''
+			
+			# get current stock at source warehouse
+			d.actual_qty = d.s_warehouse and self.get_as_on_stock(d.item_code, d.s_warehouse, self.doc.posting_date, self.doc.posting_time) or 0
+
+			# get incoming rate
+			if not flt(d.incoming_rate):
+				msgprint(1)
+				d.incoming_rate = self.get_incoming_rate(d.item_code, d.s_warehouse, self.doc.posting_date, self.doc.posting_time, d.transfer_qty, d.serial_no, d.fg_item, bom_no)
+			
+	# Get stock qty on any date
+	# ---------------------------
+	def get_as_on_stock(self, item, wh, dt, tm):
+		bin = sql("select name from tabBin where item_code = %s and warehouse = %s", (item, wh))
+		bin_id = bin and bin[0][0] or ''
+		prev_sle = get_obj('Bin', bin_id).get_prev_sle(dt, tm)
+		qty = flt(prev_sle.get('bin_aqat', 0))
+		return qty
+
+	# Get incoming rate
+	# -------------------
+	def get_incoming_rate(self, item, wh, dt, tm, qty = 0, serial_no = '', fg_item = 'No', bom_no = ''):
+		msgprint(wh)
+		in_rate = 0
+		if fg_item == 'Yes':
+			# re-calculate cost for production item from bom
+			get_obj('BOM Control').calculate_cost(bom_no)
+			in_rate = get_value('Bill Of Materials', bom_no, 'cost_as_per_mar')
+		elif wh:
+			msgprint(1)
+			in_rate = get_obj('Valuation Control').get_incoming_rate(dt, tm, item, wh, qty, serial_no)
+		
+		return in_rate
+
+	# makes dict of unique items with it's qty
+	#-----------------------------------------
+	def make_items_dict(self, items_list):
+		# items_list = [[item_name, qty]]
+		for i in items_list:
+			if self.item_dict.has_key(i[0]):
+				self.item_dict[i[0]][0] = flt(self.item_dict[i[0]][0]) + flt(i[1])
+			else:
+				self.item_dict[i[0]] = [flt(i[1]), cstr(i[2]), cstr(i[3])]
+				
+	def get_raw_materials(self,pro_obj):
+		# get all items from flat bom except, child items of sub-contracted and sub assembly items and sub assembly items itself.
+		flat_bom_items = sql("select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom	from `tabFlat BOM Detail` where parent = '%s' and parent_bom = '%s' and is_pro_applicable = 'No' and docstatus < 2 group by item_code" % ((self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) or flt(pro_obj.doc.qty), cstr(pro_obj.doc.bom_no), cstr(pro_obj.doc.bom_no)))
+		self.make_items_dict(flat_bom_items)
+		if pro_obj.doc.consider_sa_items == 'Yes':
+			# get all Sub Assembly items only from flat bom
+			fl_bom_sa_items = sql("select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom from `tabFlat BOM Detail` where parent = '%s' and parent_bom != '%s' and is_pro_applicable = 'Yes' and docstatus < 2 group by item_code" % ((self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) or flt(pro_obj.doc.qty), cstr(pro_obj.doc.bom_no), cstr(pro_obj.doc.bom_no)))
+			self.make_items_dict(fl_bom_sa_items)
+		
+		if pro_obj.doc.consider_sa_items == 'No':
+			# get all sub assembly childs only from flat bom
+			fl_bom_sa_child_item = sql("select item_code, ifnull(sum(qty_consumed_per_unit), 0) * '%s', description, stock_uom from `tabFlat BOM Detail` where parent = '%s' and parent_bom in (select distinct parent_bom from `tabFlat BOM Detail` where parent = '%s' and parent_bom != '%s' and is_pro_applicable = 'Yes' and docstatus < 2 ) and is_pro_applicable = 'No' and docstatus < 2 group by item_code" % ((self.doc.process == 'Backflush') and flt(self.doc.fg_completed_qty) or flt(pro_obj.doc.qty), cstr(pro_obj.doc.bom_no), cstr(pro_obj.doc.bom_no), cstr(pro_obj.doc.bom_no)))
+			self.make_items_dict(fl_bom_sa_child_item)
+
+	def add_to_stock_entry_detail(self, pro_obj, item_dict, fg_item = 0):
+		sw, tw = '', ''
+		if self.doc.process == 'Material Transfer':
+			tw = cstr(pro_obj.doc.wip_warehouse)
+		if self.doc.process == 'Backflush':
+			tw = fg_item and cstr(pro_obj.doc.fg_warehouse) or ''
+			if not fg_item: sw = cstr(pro_obj.doc.wip_warehouse)
+		for d in item_dict:
+			se_child = addchild(self.doc, 'mtn_details', 'Stock Entry Detail', 0, self.doclist)
+			se_child.s_warehouse = sw
+			se_child.t_warehouse = tw
+			se_child.fg_item	= fg_item
+			se_child.item_code = cstr(d)
+			se_child.description = item_dict[d][1]
+			se_child.uom = item_dict[d][2]
+			se_child.stock_uom = item_dict[d][2]
+			se_child.reqd_qty = flt(item_dict[d][0])
+			se_child.qty = flt(item_dict[d][0])
+			se_child.transfer_qty = flt(item_dict[d][0])
+			se_child.conversion_factor = 1.00
+
+	
+	# get items 
+	#------------------
+	def get_items(self):
+		pro_obj = self.doc.production_order and get_obj('Production Order', self.doc.production_order) or ''
+		
+		self.validate_for_production_order(pro_obj)
+		self.get_raw_materials(pro_obj)
+		
+		self.doc.clear_table(self.doclist, 'mtn_details', 1)
+		
+		self.add_to_stock_entry_detail(pro_obj, self.item_dict)
+		if self.doc.process == 'Backflush':
+			item_dict = {cstr(pro_obj.doc.production_item) : [self.doc.fg_completed_qty, pro_obj.doc.description, pro_obj.doc.stock_uom]}
+			self.add_to_stock_entry_detail(pro_obj, item_dict, fg_item = 1)
+
+	def validate_transfer_qty(self):
+		for d in getlist(self.doclist, 'mtn_details'):
+			if flt(d.transfer_qty) <= 0:
+				msgprint("Transfer Quantity can not be less than or equal to zero at Row No " + cstr(d.idx))
+				raise Exception
+			if d.s_warehouse:
+				if flt(d.transfer_qty) > flt(d.actual_qty):
+					msgprint("Transfer Quantity is more than Available Qty at Row No " + cstr(d.idx))
+					raise Exception
+	
+	def calc_amount(self):
+		total_amount = 0
+		for d in getlist(self.doclist, 'mtn_details'):
+			d.amount = flt(d.transfer_qty) * flt(d.incoming_rate)
+			total_amount += flt(d.amount)
+		self.doc.total_amount = flt(total_amount)
+
+	def add_to_values(self, d, wh, qty, is_cancelled):
+		self.values.append({
+				'item_code'			    : d.item_code,
+				'warehouse'			    : wh,
+				'transaction_date'	: self.doc.transfer_date,
+				'posting_date'		  : self.doc.posting_date,
+				'posting_time'		  : self.doc.posting_time,
+				'voucher_type'		  : 'Stock Entry',
+				'voucher_no'		    : self.doc.name, 
+				'voucher_detail_no'	: d.name,
+				'actual_qty'		    : qty,
+				'incoming_rate'		  : flt(d.incoming_rate) or 0,
+				'stock_uom'			    : d.stock_uom,
+				'company'			      : self.doc.company,
+				'fiscal_year'		    : self.doc.fiscal_year,
+				'is_cancelled'		  : (is_cancelled ==1) and 'Yes' or 'No',
+				'batch_no'			    : d.batch_no,
+        'serial_no'         : d.serial_no
+		})
+
+	
+	def update_stock_ledger(self, is_cancelled=0):
+		self.values = []			
+		for d in getlist(self.doclist, 'mtn_details'):
+			if cstr(d.s_warehouse):
+				self.add_to_values(d, cstr(d.s_warehouse), -flt(d.transfer_qty), is_cancelled)
+			if cstr(d.t_warehouse):
+				self.add_to_values(d, cstr(d.t_warehouse), flt(d.transfer_qty), is_cancelled)
+		get_obj('Stock Ledger', 'Stock Ledger').update_stock(self.values)
+
+	
+	def validate_for_production_order(self, pro_obj):
+		if self.doc.purpose == 'Production Order' or self.doc.process or self.doc.production_order or flt(self.doc.fg_completed_qty):
+			if self.doc.purpose != 'Production Order':
+				msgprint("Purpose should be 'Production Order'.")
+				raise Exception
+			if not self.doc.process:
+				msgprint("Process Field is mandatory.")
+				raise Exception
+			if self.doc.process == 'Backflush' and not flt(self.doc.fg_completed_qty):
+				msgprint("FG Completed Qty is mandatory as the process selected is 'Backflush'")
+				raise Exception
+			if self.doc.process == 'Material Transfer' and flt(self.doc.fg_completed_qty):
+				msgprint("FG Completed Qty should be zero. As the Process selected is 'Material Transfer'.")
+				raise Exception
+			if not self.doc.production_order:
+				msgprint("Production Order field is mandatory")
+				raise Exception
+			if flt(pro_obj.doc.qty) < flt(pro_obj.doc.produced_qty) + flt(self.doc.fg_completed_qty) :
+				msgprint("error:Already Produced Qty for %s is %s and maximum allowed Qty is %s" % (pro_obj.doc.production_item, cstr(pro_obj.doc.produced_qty) or 0.00 , cstr(pro_obj.doc.qty)))
+				raise Exception
+	
+	# Validate
+	# ------------------
+	def validate(self):
+		sl_obj = get_obj("Stock Ledger", "Stock Ledger")
+		sl_obj.scrub_serial_nos(self)
+		sl_obj.validate_serial_no(self, 'mtn_details')
+		pro_obj = ''
+		if self.doc.production_order:
+			pro_obj = get_obj('Production Order', self.doc.production_order)
+		self.validate_for_production_order(pro_obj)
+		self.validate_incoming_rate()
+		self.validate_warehouse(pro_obj)
+		self.get_stock_and_rate(pro_obj and pro_obj.doc.bom_no or '')
+		self.calc_amount()
+		get_obj('Sales Common').validate_fiscal_year(self.doc.fiscal_year,self.doc.posting_date,'Posting Date')
+				
+	# If target warehouse exists, incoming rate is mandatory
+	# --------------------------------------------------------
+	def validate_incoming_rate(self):
+		for d in getlist(self.doclist, 'mtn_details'):
+			if not flt(d.incoming_rate) and d.t_warehouse:
+				msgprint("Rate is mandatory for Item: %s at row %s" % (d.item_code, d.idx), raise_exception=1)
+
+	# Validate warehouse
+	# -----------------------------------
+	def validate_warehouse(self, pro_obj):
+		fg_qty = 0
+		for d in getlist(self.doclist, 'mtn_details'):
+			if not d.s_warehouse and not d.t_warehouse:
+				d.s_warehouse = self.doc.from_warehouse
+				d.t_warehouse = self.doc.to_warehouse
+
+			if not (d.s_warehouse or d.t_warehouse):
+				msgprint("Atleast one warehouse is mandatory for Stock Entry ")
+				raise Exception
+			if d.s_warehouse and not sql("select name from tabWarehouse where name = '%s'" % d.s_warehouse):
+				msgprint("Invalid Warehouse: %s" % self.doc.s_warehouse)
+				raise Exception
+			if d.t_warehouse and not sql("select name from tabWarehouse where name = '%s'" % d.t_warehouse):
+				msgprint("Invalid Warehouse: %s" % self.doc.t_warehouse)
+				raise Exception
+			if d.s_warehouse == d.t_warehouse:
+				msgprint("Source and Target Warehouse Cannot be Same.")
+				raise Exception
+			if self.doc.purpose == 'Material Issue':
+				if not cstr(d.s_warehouse):
+					msgprint("Source Warehouse is Mandatory for Purpose => 'Material Issue'")
+					raise Exception
+				if cstr(d.t_warehouse):
+					msgprint("Target Warehouse is not Required for Purpose => 'Material Issue'")
+					raise Exception
+			if self.doc.purpose == 'Material Transfer':
+				if not cstr(d.s_warehouse) or not cstr(d.t_warehouse):
+					msgprint("Source Warehouse and Target Warehouse both are Mandatory for Purpose => 'Material Transfer'")
+					raise Exception
+			if self.doc.purpose == 'Material Receipt':
+				if not cstr(d.t_warehouse):
+					msgprint("Target Warehouse is Mandatory for Purpose => 'Material Receipt'")
+					raise Exception
+				if cstr(d.s_warehouse):
+					msgprint("Source Warehouse is not Required for Purpose => 'Material Receipt'")
+					raise Exception
+			if self.doc.process == 'Material Transfer':
+				if cstr(d.t_warehouse) != (pro_obj.doc.wip_warehouse):
+					msgprint(" Target Warehouse should be same as WIP Warehouse %s in Production Order %s at Row No %s" % (cstr(pro_obj.doc.wip_warehouse), cstr(pro_obj.doc.name), cstr(d.idx)) )
+					raise Exception
+				if not cstr(d.s_warehouse):
+					msgprint("Please Enter Source Warehouse at Row No %s is mandatory." % (cstr(d.idx)))
+					raise Exception
+			if self.doc.process == 'Backflush':
+				if flt(d.fg_item):
+					if cstr(pro_obj.doc.production_item) != cstr(d.item_code):
+						msgprint("Item %s in Stock Entry Detail as Row No %s do not match with Item %s in Production Order %s" % (cstr(d.item_code), cstr(d.idx), cstr(pro_obj.doc.production_item), cstr(pro_obj.doc.name)))
+						raise Exception
+					fg_qty = flt(fg_qty) + flt(d.transfer_qty)
+					if cstr(d.t_warehouse) != cstr(pro_obj.doc.fg_warehouse):
+						msgprint("As Item %s is FG Item. Target Warehouse should be same as FG Warehouse %s in Production Order %s, at Row No %s. " % ( cstr(d.item_code), cstr(pro_obj.doc.fg_warehouse), cstr(pro_obj.doc.name), cstr(d.idx)))
+						raise Exception
+					if cstr(d.s_warehouse):
+						msgprint("As Item %s is a FG Item. There should be no Source Warehouse at Row No %s" % (cstr(d.item_code), cstr(d.idx)))
+						raise Exception
+				if not flt(d.fg_item):
+					if cstr(d.t_warehouse):
+						msgprint("As Item %s is not a FG Item. There should no Tareget Warehouse at Row No %s" % (cstr(d.item_code), cstr(d.idx)))
+						raise Exception
+					if cstr(d.s_warehouse) != cstr(pro_obj.doc.wip_warehouse):
+						msgprint("As Item %s is Raw Material. Source Warehouse should be same as WIP Warehouse %s in Production Order %s, at Row No %s. " % ( cstr(d.item_code), cstr(pro_obj.doc.wip_warehouse), cstr(pro_obj.doc.name), cstr(d.idx)))
+						raise Exception
+			d.save()
+		if self.doc.fg_completed_qty and flt(self.doc.fg_completed_qty) != flt(fg_qty):
+			msgprint("The Total of FG Qty %s in Stock Entry Detail do not match with FG Completed Qty %s" % (flt(fg_qty), flt(self.doc.fg_completed_qty)))
+			raise Exception
+
+	def update_production_order(self, is_submit):
+		if self.doc.production_order:
+			pro_obj = get_obj("Production Order", self.doc.production_order)
+			if flt(pro_obj.doc.docstatus) != 1:
+				msgprint("One cannot do any transaction against Production Order : %s, as it's not submitted" % (pro_obj.doc.name))
+				raise Exception
+			if pro_obj.doc.status == 'Stopped':
+				msgprint("One cannot do any transaction against Production Order : %s, as it's status is 'Stopped'" % (pro_obj.doc.name))
+				raise Exception
+			if getdate(pro_obj.doc.posting_date) > getdate(self.doc.posting_date):
+				msgprint("Posting Date of Stock Entry cannot be before Posting Date of Production Order "+ cstr(self.doc.production_order))
+				raise Exception
+			if self.doc.process == 'Backflush':
+				pro_obj.doc.produced_qty = flt(pro_obj.doc.produced_qty) + (is_submit and 1 or -1 ) * flt(self.doc.fg_completed_qty)
+				get_obj('Warehouse',	pro_obj.doc.fg_warehouse).update_bin(0, 0, 0, 0, (is_submit and 1 or -1 ) *	flt(self.doc.fg_completed_qty), pro_obj.doc.production_item, now())
+			pro_obj.doc.status = (flt(pro_obj.doc.qty) == flt(pro_obj.doc.produced_qty)) and	'Completed' or 'In Process'
+			pro_obj.doc.save()
+	
+	# Create / Update Serial No
+	# ----------------------------------
+	def update_serial_no(self, is_submit):
+		sl_obj = get_obj('Stock Ledger')
+		for d in getlist(self.doclist, 'mtn_details'):
+			if d.serial_no:
+				serial_nos = sl_obj.get_sr_no_list(d.serial_no)
+				for x in serial_nos:
+					serial_no = x.strip()
+					if d.s_warehouse:
+						sl_obj.update_serial_delivery_details(self, d, serial_no, is_submit)
+					if d.t_warehouse:
+						sl_obj.update_serial_purchase_details(self, d, serial_no, is_submit, (self.doc.purpose in ['Material Transfer', 'Sales Return']) and 1 or 0)
+					
+					if self.doc.purpose == 'Purchase Return':
+						delete_doc("Serial No", serial_no)
+
+	# On Submit
+	# ------------------
+	def on_submit(self):
+		self.validate_transfer_qty()
+		# Check for Approving Authority
+		get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.total_amount)
+		self.update_serial_no(1)
+		self.update_stock_ledger(0)
+		# update Production Order
+		self.update_production_order(1)
+
+	# On Cancel
+	# -------------------
+	def on_cancel(self):
+		self.update_serial_no(0)
+		self.update_stock_ledger(1)
+		# update Production Order
+		self.update_production_order(0)
+		
+	def get_cust_values(self):
+		tbl = self.doc.delivery_note_no and 'Delivery Note' or 'Receivable Voucher'
+		record_name = self.doc.delivery_note_no or self.doc.sales_invoice_no
+		res = sql("select customer,customer_name, customer_address from `tab%s` where name = '%s'" % (tbl, record_name))
+		ret = {
+			'customer'				 : res and res[0][0] or '',
+			'customer_name'		: res and res[0][1] or '',
+			'customer_address' : res and res[0][2] or ''}
+
+		return str(ret)
+
+
+	def get_cust_addr(self):
+		res = sql("select customer_name,address from `tabCustomer` where name = '%s'"%self.doc.customer)
+		ret = { 
+			'customer_name'		: res and res[0][0] or '',
+			'customer_address' : res and res[0][1] or ''}
+
+		return str(ret)
+
+
+		
+	def get_supp_values(self):
+		res = sql("select supplier,supplier_name,supplier_address from `tabPurchase Receipt` where name = '%s'"%self.doc.purchase_receipt_no)
+		ret = {
+			'supplier' : res and res[0][0] or '',
+			'supplier_name' :res and res[0][1] or '',
+			'supplier_address' : res and res[0][2] or ''}
+		return str(ret)
+		
+
+	def get_supp_addr(self):
+		res = sql("select supplier_name,address from `tabSupplier` where name = '%s'"%self.doc.supplier)
+		ret = {
+			'supplier_name' : res and res[0][0] or '',
+			'supplier_address' : res and res[0][1] or ''}
+		return str(ret)
diff --git a/material_management/doctype/stock_entry/stock_entry.txt b/material_management/doctype/stock_entry/stock_entry.txt
index 09617ab..448693c 100644
--- a/material_management/doctype/stock_entry/stock_entry.txt
+++ b/material_management/doctype/stock_entry/stock_entry.txt
@@ -1,6 +1,6 @@
 [
 	{
-		'_last_update': '1301989672',
+		'_last_update': '1308034183',
 		'allow_attach': None,
 		'allow_copy': None,
 		'allow_email': None,
@@ -29,7 +29,7 @@
 		'istable': None,
 		'max_attachments': None,
 		'menu_index': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'module': 'Material Management',
 		'name': 'Stock Entry',
@@ -50,10 +50,10 @@
 		'server_code_error': ' ',
 		'show_in_menu': 0,
 		'smallicon': None,
-		'subject': 'eval:"%(remarks)s | " + ("%(from_warehouse)s" ? "From %(from_warehouse)s" : "") + ("%(to_warehouse)s" ? "To %(to_warehouse)s" : "")',
+		'subject': '%(remarks)s',
 		'tag_fields': 'purpose',
 		'use_template': None,
-		'version': 227
+		'version': 243
 	},
 	{
 		'amend': 1,
@@ -65,7 +65,7 @@
 		'execute': None,
 		'idx': 1,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00541',
 		'owner': 'Administrator',
@@ -88,7 +88,7 @@
 		'execute': None,
 		'idx': 2,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00542',
 		'owner': 'Administrator',
@@ -111,7 +111,7 @@
 		'execute': None,
 		'idx': 3,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00543',
 		'owner': 'Administrator',
@@ -134,7 +134,7 @@
 		'execute': None,
 		'idx': 4,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00544',
 		'owner': 'Administrator',
@@ -157,7 +157,7 @@
 		'execute': None,
 		'idx': 5,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00545',
 		'owner': 'jai@webnotestech.com',
@@ -180,7 +180,7 @@
 		'execute': None,
 		'idx': 6,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00546',
 		'owner': 'jai@webnotestech.com',
@@ -203,7 +203,7 @@
 		'execute': None,
 		'idx': 7,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00547',
 		'owner': 'jai@webnotestech.com',
@@ -226,7 +226,7 @@
 		'execute': None,
 		'idx': 8,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00548',
 		'owner': 'jai@webnotestech.com',
@@ -249,7 +249,7 @@
 		'execute': None,
 		'idx': 9,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00549',
 		'owner': 'jai@webnotestech.com',
@@ -272,7 +272,7 @@
 		'execute': None,
 		'idx': 10,
 		'match': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'PERM00550',
 		'owner': 'jai@webnotestech.com',
@@ -301,7 +301,7 @@
 		'idx': 1,
 		'in_filter': None,
 		'label': 'Warehouse',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03366',
 		'no_column': None,
@@ -337,7 +337,7 @@
 		'idx': 2,
 		'in_filter': None,
 		'label': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03367',
 		'no_column': None,
@@ -361,7 +361,7 @@
 		'allow_on_submit': None,
 		'colour': 'White:FFF',
 		'creation': '2010-08-08 17:09:25',
-		'default': 'STE',
+		'default': None,
 		'depends_on': None,
 		'description': 'To manage multiple series please go to Setup > Manage Series',
 		'docstatus': 0,
@@ -373,7 +373,7 @@
 		'idx': 3,
 		'in_filter': None,
 		'label': 'Series',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03368',
 		'no_column': None,
@@ -409,7 +409,7 @@
 		'idx': 4,
 		'in_filter': None,
 		'label': 'Amendment Date',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03369',
 		'no_column': None,
@@ -445,7 +445,7 @@
 		'idx': 5,
 		'in_filter': 1,
 		'label': 'Purpose',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03370',
 		'no_column': None,
@@ -481,7 +481,7 @@
 		'idx': 6,
 		'in_filter': None,
 		'label': 'Delivery Note No',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03371',
 		'no_column': None,
@@ -517,7 +517,7 @@
 		'idx': 7,
 		'in_filter': None,
 		'label': 'Purchase Receipt No',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03372',
 		'no_column': None,
@@ -540,7 +540,7 @@
 	{
 		'allow_on_submit': None,
 		'colour': None,
-		'creation': '2011-02-04 17:22:22',
+		'creation': '2011-02-01 14:10:05',
 		'default': None,
 		'depends_on': None,
 		'description': None,
@@ -553,9 +553,9 @@
 		'idx': 8,
 		'in_filter': None,
 		'label': 'Sales Invoice No',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
-		'name': 'FL04499',
+		'name': 'FL04464',
 		'no_column': None,
 		'no_copy': None,
 		'oldfieldname': None,
@@ -589,7 +589,7 @@
 		'idx': 9,
 		'in_filter': None,
 		'label': 'Supplier',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03373',
 		'no_column': None,
@@ -612,7 +612,7 @@
 	{
 		'allow_on_submit': None,
 		'colour': None,
-		'creation': '2010-09-01 15:47:54',
+		'creation': '2010-09-01 15:48:04',
 		'default': None,
 		'depends_on': None,
 		'description': None,
@@ -625,9 +625,9 @@
 		'idx': 10,
 		'in_filter': None,
 		'label': 'Supplier Name',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
-		'name': 'FL03788',
+		'name': 'FL03800',
 		'no_column': None,
 		'no_copy': None,
 		'oldfieldname': 'supplier_name',
@@ -661,7 +661,7 @@
 		'idx': 11,
 		'in_filter': None,
 		'label': 'Supplier Address',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03374',
 		'no_column': None,
@@ -697,7 +697,7 @@
 		'idx': 12,
 		'in_filter': None,
 		'label': 'Customer',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03375',
 		'no_column': None,
@@ -720,7 +720,7 @@
 	{
 		'allow_on_submit': None,
 		'colour': None,
-		'creation': '2010-09-01 15:47:54',
+		'creation': '2010-09-01 15:48:04',
 		'default': None,
 		'depends_on': None,
 		'description': None,
@@ -733,9 +733,9 @@
 		'idx': 13,
 		'in_filter': None,
 		'label': 'Customer Name',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
-		'name': 'FL03789',
+		'name': 'FL03801',
 		'no_column': None,
 		'no_copy': None,
 		'oldfieldname': 'customer_name',
@@ -769,7 +769,7 @@
 		'idx': 14,
 		'in_filter': None,
 		'label': 'Customer Address',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03376',
 		'no_column': None,
@@ -805,7 +805,7 @@
 		'idx': 15,
 		'in_filter': 1,
 		'label': 'Process',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03377',
 		'no_column': None,
@@ -841,7 +841,7 @@
 		'idx': 16,
 		'in_filter': 1,
 		'label': 'Production Order',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03378',
 		'no_column': None,
@@ -877,7 +877,7 @@
 		'idx': 17,
 		'in_filter': None,
 		'label': 'FG Completed Qty',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03379',
 		'no_column': None,
@@ -913,7 +913,7 @@
 		'idx': 18,
 		'in_filter': None,
 		'label': 'Warehouse HTML',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03380',
 		'no_column': None,
@@ -949,7 +949,7 @@
 		'idx': 19,
 		'in_filter': None,
 		'label': 'Source Warehouse',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03381',
 		'no_column': None,
@@ -985,7 +985,7 @@
 		'idx': 20,
 		'in_filter': 0,
 		'label': 'Target Warehouse',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03382',
 		'no_column': None,
@@ -1008,42 +1008,6 @@
 	{
 		'allow_on_submit': None,
 		'colour': None,
-		'creation': '2010-12-14 10:33:05',
-		'default': None,
-		'depends_on': None,
-		'description': None,
-		'docstatus': 0,
-		'doctype': 'DocField',
-		'fieldname': 'project_name',
-		'fieldtype': 'Link',
-		'hidden': None,
-		'icon': None,
-		'idx': 21,
-		'in_filter': 1,
-		'label': 'Project Name',
-		'modified': '2011-05-19 09:46:27',
-		'modified_by': 'Administrator',
-		'name': 'FL04203',
-		'no_column': None,
-		'no_copy': None,
-		'oldfieldname': 'project_name',
-		'oldfieldtype': 'Link',
-		'options': 'Project',
-		'owner': 'ashwini@webnotestech.com',
-		'parent': 'Stock Entry',
-		'parentfield': 'fields',
-		'parenttype': 'DocType',
-		'permlevel': 0,
-		'print_hide': None,
-		'report_hide': None,
-		'reqd': None,
-		'search_index': None,
-		'trigger': None,
-		'width': None
-	},
-	{
-		'allow_on_submit': None,
-		'colour': None,
 		'creation': '2010-08-08 17:09:25',
 		'default': None,
 		'depends_on': None,
@@ -1054,10 +1018,10 @@
 		'fieldtype': 'Column Break',
 		'hidden': None,
 		'icon': None,
-		'idx': 22,
+		'idx': 21,
 		'in_filter': None,
 		'label': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03383',
 		'no_column': None,
@@ -1090,10 +1054,10 @@
 		'fieldtype': 'Date',
 		'hidden': None,
 		'icon': None,
-		'idx': 23,
+		'idx': 22,
 		'in_filter': 1,
 		'label': 'Transfer Date',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03384',
 		'no_column': None,
@@ -1126,10 +1090,10 @@
 		'fieldtype': 'Date',
 		'hidden': None,
 		'icon': None,
-		'idx': 24,
+		'idx': 23,
 		'in_filter': 1,
 		'label': 'Posting Date',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03385',
 		'no_column': None,
@@ -1162,10 +1126,10 @@
 		'fieldtype': 'Time',
 		'hidden': None,
 		'icon': None,
-		'idx': 25,
+		'idx': 24,
 		'in_filter': 0,
 		'label': 'Posting Time',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03386',
 		'no_column': None,
@@ -1198,10 +1162,10 @@
 		'fieldtype': 'Link',
 		'hidden': None,
 		'icon': None,
-		'idx': 26,
+		'idx': 25,
 		'in_filter': None,
 		'label': 'Amended From',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03387',
 		'no_column': None,
@@ -1234,10 +1198,10 @@
 		'fieldtype': 'Data',
 		'hidden': None,
 		'icon': None,
-		'idx': 27,
+		'idx': 26,
 		'in_filter': None,
 		'label': 'Transporter',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03388',
 		'no_column': None,
@@ -1270,10 +1234,10 @@
 		'fieldtype': 'Select',
 		'hidden': None,
 		'icon': None,
-		'idx': 28,
+		'idx': 27,
 		'in_filter': None,
 		'label': 'Is Excisable Goods',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03389',
 		'no_column': None,
@@ -1306,10 +1270,10 @@
 		'fieldtype': 'Select',
 		'hidden': None,
 		'icon': None,
-		'idx': 29,
+		'idx': 28,
 		'in_filter': None,
 		'label': 'Excisable Goods',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03390',
 		'no_column': None,
@@ -1342,10 +1306,10 @@
 		'fieldtype': 'Select',
 		'hidden': 1,
 		'icon': None,
-		'idx': 30,
+		'idx': 29,
 		'in_filter': None,
 		'label': 'Under Rule',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03391',
 		'no_column': None,
@@ -1378,10 +1342,10 @@
 		'fieldtype': 'Text',
 		'hidden': None,
 		'icon': None,
-		'idx': 31,
+		'idx': 30,
 		'in_filter': None,
 		'label': 'Remarks',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03392',
 		'no_column': None,
@@ -1414,10 +1378,10 @@
 		'fieldtype': 'Data',
 		'hidden': 1,
 		'icon': None,
-		'idx': 32,
+		'idx': 31,
 		'in_filter': 0,
 		'label': 'Cancel Reason',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03393',
 		'no_column': None,
@@ -1450,10 +1414,10 @@
 		'fieldtype': 'Section Break',
 		'hidden': None,
 		'icon': None,
-		'idx': 33,
+		'idx': 32,
 		'in_filter': None,
 		'label': 'Items',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03394',
 		'no_column': None,
@@ -1486,17 +1450,17 @@
 		'fieldtype': 'Button',
 		'hidden': None,
 		'icon': None,
-		'idx': 34,
+		'idx': 33,
 		'in_filter': None,
-		'label': 'Get Current Stock',
-		'modified': '2011-05-19 09:46:27',
+		'label': 'Get Stock and Rate',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03395',
 		'no_column': None,
 		'no_copy': None,
 		'oldfieldname': None,
 		'oldfieldtype': 'Button',
-		'options': 'get_current_stock',
+		'options': 'get_stock_and_rate',
 		'owner': 'Administrator',
 		'parent': 'Stock Entry',
 		'parentfield': 'fields',
@@ -1522,10 +1486,10 @@
 		'fieldtype': 'Column Break',
 		'hidden': None,
 		'icon': None,
-		'idx': 35,
+		'idx': 34,
 		'in_filter': None,
 		'label': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03396',
 		'no_column': None,
@@ -1558,10 +1522,10 @@
 		'fieldtype': 'Button',
 		'hidden': 0,
 		'icon': None,
-		'idx': 36,
+		'idx': 35,
 		'in_filter': None,
 		'label': 'Get Items',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03397',
 		'no_column': None,
@@ -1594,10 +1558,10 @@
 		'fieldtype': 'Section Break',
 		'hidden': None,
 		'icon': None,
-		'idx': 37,
+		'idx': 36,
 		'in_filter': None,
 		'label': None,
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03398',
 		'no_column': None,
@@ -1630,10 +1594,10 @@
 		'fieldtype': 'Table',
 		'hidden': None,
 		'icon': None,
-		'idx': 38,
+		'idx': 37,
 		'in_filter': None,
 		'label': 'MTN Details',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03399',
 		'no_column': None,
@@ -1666,10 +1630,10 @@
 		'fieldtype': 'Currency',
 		'hidden': None,
 		'icon': None,
-		'idx': 39,
+		'idx': 38,
 		'in_filter': None,
 		'label': 'Total Amount',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03400',
 		'no_column': None,
@@ -1702,10 +1666,10 @@
 		'fieldtype': 'Section Break',
 		'hidden': None,
 		'icon': None,
-		'idx': 40,
+		'idx': 39,
 		'in_filter': None,
 		'label': 'Other Details',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03401',
 		'no_column': None,
@@ -1738,10 +1702,10 @@
 		'fieldtype': 'Link',
 		'hidden': None,
 		'icon': None,
-		'idx': 41,
+		'idx': 40,
 		'in_filter': 1,
 		'label': 'Company',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03402',
 		'no_column': None,
@@ -1774,10 +1738,10 @@
 		'fieldtype': 'Select',
 		'hidden': None,
 		'icon': None,
-		'idx': 42,
+		'idx': 41,
 		'in_filter': 0,
 		'label': 'Fiscal Year',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
 		'name': 'FL03403',
 		'no_column': None,
@@ -1800,7 +1764,7 @@
 	{
 		'allow_on_submit': None,
 		'colour': None,
-		'creation': '2010-08-19 11:08:48',
+		'creation': '2010-08-19 11:08:49',
 		'default': None,
 		'depends_on': None,
 		'description': None,
@@ -1810,12 +1774,12 @@
 		'fieldtype': 'Link',
 		'hidden': None,
 		'icon': None,
-		'idx': 43,
+		'idx': 42,
 		'in_filter': None,
 		'label': 'Select Print Heading',
-		'modified': '2011-05-19 09:46:27',
+		'modified': '2011-06-14 12:50:12',
 		'modified_by': 'Administrator',
-		'name': 'FL03754',
+		'name': 'FL03766',
 		'no_column': None,
 		'no_copy': None,
 		'oldfieldname': 'select_print_heading',
diff --git a/material_management/doctype/valuation_control/valuation_control.py b/material_management/doctype/valuation_control/valuation_control.py
index c23753f..131c71b 100644
--- a/material_management/doctype/valuation_control/valuation_control.py
+++ b/material_management/doctype/valuation_control/valuation_control.py
@@ -69,7 +69,6 @@
 		in_rate = 0
 		val_method = self.get_valuation_method(item)
 		bin_obj = get_obj('Warehouse',warehouse).get_bin(item)
-		
 		if serial_no:
 			in_rate = self.get_serializable_inventory_rate(serial_no)
 		elif val_method == 'FIFO':
@@ -77,7 +76,7 @@
 			if qty:
 				prev_sle = bin_obj.get_prev_sle(posting_date, posting_time)
 				fcfs_stack = eval(prev_sle.get('fcfs_stack', '[]') or '[]')
-				in_rate = fcfs_stack and self.get_fifo_rate(fcfs_stack, qty) or 0				
+				in_rate = fcfs_stack and self.get_fifo_rate(fcfs_stack, qty) or 0
 		elif val_method == 'Moving Average':
 			prev_sle = bin_obj.get_prev_sle(posting_date, posting_time)
 			in_rate = prev_sle and prev_sle.get('valuation_rate', 0) or 0
diff --git a/material_management/doctype/valuation_control/valuation_control.py~ b/material_management/doctype/valuation_control/valuation_control.py~
new file mode 100644
index 0000000..82e7fb9
--- /dev/null
+++ b/material_management/doctype/valuation_control/valuation_control.py~
@@ -0,0 +1,87 @@
+# Please edit this list and import only required elements
+import webnotes
+
+from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
+from webnotes.model import db_exists
+from webnotes.model.doc import Document, addchild, removechild, getchildren, make_autoname, SuperDocType
+from webnotes.model.doclist import getlist, copy_doclist
+from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
+from webnotes import session, form, is_testing, msgprint, errprint
+
+set = webnotes.conn.set
+sql = webnotes.conn.sql
+get_value = webnotes.conn.get_value
+in_transaction = webnotes.conn.in_transaction
+convert_to_lists = webnotes.conn.convert_to_lists
+	
+# -----------------------------------------------------------------------------------------
+
+
+class DocType:
+	def __init__(self, d, dl):
+		self.doc, self.doclist = d, dl
+
+	# Get FIFO Rate from Stack
+	# -------------------------
+	def get_fifo_rate(self, fcfs_stack, qty):
+		fcfs_val = 0
+		withdraw = flt(qty)
+		while withdraw:
+			batch = fcfs_stack[0]				
+			if batch[0] <= withdraw:
+				# not enough or exactly same qty in current batch, clear batch
+				withdraw -= batch[0]
+				fcfs_val += (flt(batch[0]) * flt(batch[1]))
+				fcfs_stack.pop(0)
+			else:
+				# all from current batch
+				fcfs_val += (flt(withdraw) * flt(batch[1]))
+				batch[0] -= withdraw
+				withdraw = 0
+		fcfs_rate = flt(fcfs_val) / flt(qty)
+		return fcfs_rate
+
+	# --------------------------------
+	# get serializable inventory rate
+	# --------------------------------
+	def get_serializable_inventory_rate(self, serial_no):
+		sr_nos = get_obj("Stock Ledger").get_sr_no_list(serial_no)
+		tot = 0
+		for s in sr_nos:
+			serial_no = s.strip()
+			tot += flt(get_value('Serial No', serial_no, 'purchase_rate'))
+		return tot / len(sr_nos)
+
+
+	# ---------------------
+	# get valuation method
+	# ---------------------
+	def get_valuation_method(self, item_code):
+		val_method = webnotes.conn.get_value('Item', item_code, 'valuation_method')
+		if not val_method:
+			val_method = get_defaults().get('valuation_method', 'FIFO')
+		return val_method
+		
+
+	# Get Incoming Rate based on valuation method
+	# --------------------------------------------
+	def get_incoming_rate(self, posting_date, posting_time, item, warehouse, qty = 0, serial_no = ''):
+		msgprint(1)
+		in_rate = 0
+		val_method = self.get_valuation_method(item)
+		bin_obj = get_obj('Warehouse',warehouse).get_bin(item)
+		if serial_no:
+			in_rate = self.get_serializable_inventory_rate(serial_no)
+		elif val_method == 'FIFO':
+			in_rate = 0
+			if qty:
+				prev_sle = bin_obj.get_prev_sle(posting_date, posting_time)
+				msgprint(prev_sle)
+				fcfs_stack = eval(prev_sle.get('fcfs_stack', '[]') or '[]')
+				msgprint(fcfs_stack)
+				in_rate = fcfs_stack and self.get_fifo_rate(fcfs_stack, qty) or 0
+				msgprint(in_rate)
+		elif val_method == 'Moving Average':
+			prev_sle = bin_obj.get_prev_sle(posting_date, posting_time)
+			in_rate = prev_sle and prev_sle.get('valuation_rate', 0) or 0
+		return in_rate
diff --git a/patches/patch.py b/patches/patch.py
index 9b9255b..bb670a4 100644
--- a/patches/patch.py
+++ b/patches/patch.py
@@ -1,6 +1,6 @@
 # REMEMBER to update this
 # ========================
-last_patch = 277
+last_patch = 278
 
 #-------------------------------------------
 
@@ -1108,4 +1108,5 @@
 		delete_pages = ('Chat User Gallery', 'Badge Info', 'Home', 'Website Setup', 'Test Page', 'Setup Masters', 'Service', 'Selling', 'Sales Reports', 'Organize','My Cart', 'My Activity', 'Manage Users', 'Maintenance', 'Getting Started', 'Gantt Test', 'Custom Reports - Stock', 'Custom Reports - Selling', 'Custom Reports - Production', 'Custom Reports - Payroll', 'Custom Reports - Maintenance', 'Custom Reports - Buying', 'Custom Reports - Accounts', 'CRM Setup', 'CRM Reports')
 		for p in delete_pages:
 		  webnotes.model.delete_doc('Page',p)
-		
\ No newline at end of file
+	elif patch_no == 278:
+		sql("update tabDocTrigger set method = 'home.update_feed' where method = 'event_updates.update_feed'")