Merge branch 'master' of github.com:webnotes/erpnext
diff --git a/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py b/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py
index 3b21ca6..be4d450 100644
--- a/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py
+++ b/erpnext/patches/july_2012/repost_stock_due_to_wrong_packing_list.py
@@ -40,7 +40,8 @@
 				and parenttype="Sales Order"
 				and exists (select * from `tabSales Order` so
 				where name = dnpi_in.parent and docstatus = 1 and status != 'Stopped')
-			) dnpi) tab""", (d[0], d[1]))
+			) dnpi) tab
+			where so_item_qty >= so_item_delivered_qty""", (d[0], d[1]))
 
 		if flt(d[3]) != flt(reserved_qty[0][0]):
 			print d[3], reserved_qty[0][0]
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 9e00dc1..c21b552 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -66,7 +66,7 @@
 
 			if cstr(d.uom) == cstr(self.doc.stock_uom):
 				if flt(d.conversion_factor) != 1:
-					msgprint("Conversion Fator of UOM : %s should be equal to 1. As UOM : %s is Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
+					msgprint("Conversion Factor of UOM : %s should be equal to 1. As UOM : %s is Stock UOM of Item: %s." % ( cstr(d.uom), cstr(d.uom), cstr(self.doc.name)))
 					raise Exception
 				# else set uom_exist as true
 				uom_exist='true'
diff --git a/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py b/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
index 8414f8a..f7ff36b 100644
--- a/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
+++ b/erpnext/stock/doctype/stock_uom_replace_utility/stock_uom_replace_utility.py
@@ -8,11 +8,11 @@
 # 
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
 # GNU General Public License for more details.
 # 
 # You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+# along with this program.	If not, see <http://www.gnu.org/licenses/>.
 
 # Please edit this list and import only required elements
 import webnotes
@@ -34,88 +34,86 @@
 
 
 class DocType:
-  def __init__(self, d, dl=[]):
-    self.doc, self.doclist = d,dl
+	def __init__(self, d, dl=[]):
+		self.doc, self.doclist = d,dl
 
-  def get_stock_uom(self, item_code):
-    return {'current_stock_uom': cstr(get_value('Item', item_code, 'stock_uom'))}
-  
-  def validate_mandatory(self):
-    if not cstr(self.doc.item_code):
-      msgprint("Please Enter an Item.")
-      raise Exception
+	def get_stock_uom(self, item_code):
+		return {'current_stock_uom': cstr(get_value('Item', item_code, 'stock_uom'))}
+	
+	def validate_mandatory(self):
+		if not cstr(self.doc.item_code):
+			msgprint("Please Enter an Item.")
+			raise Exception
+		
+		if not cstr(self.doc.new_stock_uom):
+			msgprint("Please Enter New Stock UOM.")
+			raise Exception
 
-    if not cstr(self.doc.current_stock_uom):
-      msgprint("There is no Current Stock UOM for Item Code" + cstr(self.doc.item_code))
-      raise Exception
-    
-    if not cstr(self.doc.new_stock_uom):
-      msgprint("Please Enter New Stock UOM.")
-      raise Exception
+		if cstr(self.doc.current_stock_uom) == cstr(self.doc.new_stock_uom):
+			msgprint("Current Stock UOM and Stock UOM are same.")
+			raise Exception 
+	
+		# check conversion factor
+		if not flt(self.doc.conversion_factor):
+			msgprint("Please Enter Conversion Factor.")
+			raise Exception
+		
+		stock_uom = sql("select stock_uom from `tabItem` where name = '%s'" % self.doc.item_code)
+		stock_uom = stock_uom and stock_uom[0][0]
+		if cstr(self.doc.new_stock_uom) == cstr(stock_uom):
+			msgprint("Item Master is already updated with New Stock UOM " + cstr(self.doc.new_stock_uom))
+			raise Exception
+			
+	def update_item_master(self):
+		# update stock uom in item master
+		sql("update `tabItem` set stock_uom = '%s' where name = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
+		
+		# acknowledge user
+		msgprint("New Stock UOM : " + cstr(self.doc.new_stock_uom) + " updated in Item : " + cstr(self.doc.item_code))
+		
+	def update_bin(self):
+		# update bin
+		if flt(self.doc.conversion_factor) != flt(1):
+			sql("update `tabBin` set stock_uom = '%s' , indented_qty = ifnull(indented_qty,0) * %s, ordered_qty = ifnull(ordered_qty,0) * %s, reserved_qty = ifnull(reserved_qty,0) * %s, planned_qty = ifnull(planned_qty,0) * %s, projected_qty = actual_qty + ordered_qty + indented_qty + planned_qty - reserved_qty	where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.item_code) )
+		else:
+			sql("update `tabBin` set stock_uom = '%s' where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.item_code) )
 
-    if cstr(self.doc.current_stock_uom) == cstr(self.doc.new_stock_uom):
-      msgprint("Current Stock UOM and Stock UOM are same.")
-      raise Exception 
-  
-    # check conversion factor
-    if not flt(self.doc.conversion_factor):
-      msgprint("Please Enter Conversion Factor.")
-      raise Exception
-    
-    stock_uom = sql("select stock_uom from `tabItem` where name = '%s'" % self.doc.item_code)
-    stock_uom = stock_uom and stock_uom[0][0]
-    if cstr(self.doc.new_stock_uom) == cstr(stock_uom):
-      msgprint("Item Master is already updated with New Stock UOM " + cstr(self.doc.new_stock_uom))
-      raise Exception
-      
-  def update_item_master(self):
-    # update stock uom in item master
-    sql("update `tabItem` set stock_uom = '%s' where name = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
-    
-    # acknowledge user
-    msgprint("New Stock UOM : " + cstr(self.doc.new_stock_uom) + " updated in Item : " + cstr(self.doc.item_code))
-    
-  def update_bin(self):
-    # update bin
-    if flt(self.doc.conversion_factor) != flt(1):
-      sql("update `tabBin` set stock_uom = '%s' , indented_qty = ifnull(indented_qty,0) * %s, ordered_qty = ifnull(ordered_qty,0) * %s, reserved_qty = ifnull(reserved_qty,0) * %s, planned_qty = ifnull(planned_qty,0) * %s, projected_qty = actual_qty + ordered_qty + indented_qty + planned_qty - reserved_qty  where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.conversion_factor, self.doc.item_code) )
-    else:
-      sql("update `tabBin` set stock_uom = '%s' where item_code = '%s'" % (self.doc.new_stock_uom, self.doc.item_code) )
+		# acknowledge user
+		msgprint(" All Bin's Updated Successfully.")
+			
+	def update_stock_ledger_entry(self):
+		# update stock ledger entry
+		if flt(self.doc.conversion_factor) != flt(1):
+			sql("update `tabStock Ledger Entry` set stock_uom = '%s', actual_qty = ifnull(actual_qty,0) * '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.item_code))
+		else:
+			sql("update `tabStock Ledger Entry` set stock_uom = '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
+		
+		# acknowledge user
+		msgprint("Stock Ledger Entries Updated Successfully.")
+		
+		# update item valuation
+		if flt(self.doc.conversion_factor) != flt(1):
+			wh = sql("select name from `tabWarehouse`")
+			for w in wh:
+				bin = sql("select name from `tabBin` where item_code = '%s' and warehouse = '%s'" % (self.doc.item_code, w[0])) 
+				if bin and bin[0][0]:
+					get_obj("Bin", bin[0][0]).update_entries_after(posting_date = '', posting_time = '')
 
-    # acknowledge user
-    msgprint(" All Bin's Updated Successfully.")
-      
-  def update_stock_ledger_entry(self):
-    # update stock ledger entry
-    if flt(self.doc.conversion_factor) != flt(1):
-      sql("update `tabStock Ledger Entry` set stock_uom = '%s', actual_qty = ifnull(actual_qty,0) * '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.conversion_factor, self.doc.item_code))
-    else:
-      sql("update `tabStock Ledger Entry` set stock_uom = '%s' where item_code = '%s' " % (self.doc.new_stock_uom, self.doc.item_code))
-    
-    # acknowledge user
-    msgprint("Stock Ledger Entries Updated Successfully.")
-    
-    # update item valuation
-    if flt(self.doc.conversion_factor) != flt(1):
-      wh = sql("select name from `tabWarehouse`")
-      for w in wh:
-        bin = sql("select name from `tabBin` where item_code = '%s' and warehouse = '%s'" % (self.doc.item_code, w[0])) 
-        if bin and bin[0][0]:
-          get_obj("Bin", bin[0][0]).update_entries_after(posting_date = '', posting_time = '')
+		# acknowledge user
+		msgprint("Item Valuation Updated Successfully.")
 
-    # acknowledge user
-    msgprint("Item Valuation Updated Successfully.")
+	# Update Stock UOM							
+	def update_stock_uom(self):
+		# validate mandatory
+		self.validate_mandatory()
+		
+		# update item master
+		self.update_item_master()
+		
+		# update stock ledger entry
+		self.update_stock_ledger_entry()
+		
+		# update bin
+		self.update_bin()
 
-  # Update Stock UOM              
-  def update_stock_uom(self):
-    # validate mandatory
-    self.validate_mandatory()
-    
-    # update item master
-    self.update_item_master()
-    
-    # update stock ledger entry
-    self.update_stock_ledger_entry()
-    
-    # update bin
-    self.update_bin()
\ No newline at end of file
+		get_obj("Item", self.doc.item_code).on_update()
\ No newline at end of file
diff --git a/public/js/all-app.js b/public/js/all-app.js
index df69de6..3c50ed2 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -478,7 +478,7 @@
 new_dt=new Date(dt.getFullYear(),dt.getMonth()+months,dt.getDate())
 if(new_dt.getDate()!=dt.getDate()){return dateutil.month_end(new Date(dt.getFullYear(),dt.getMonth()+months,1))}
 return dateutil.obj_to_str(new_dt);},month_start:function(){var d=new Date();return d.getFullYear()+'-'+int_to_str(d.getMonth()+1,2)+'-01';},month_end:function(d){if(!d)var d=new Date();var m=d.getMonth()+1;var y=d.getFullYear();last_date=month_last[m];if(m==2&&(y%4)==0&&((y%100)!=0||(y%400)==0))
-last_date=29;return y+'-'+int_to_str(m,2)+'-'+last_date;},get_user_fmt:function(){var t=wn.control_panel.date_format;if(!t)t='dd-mm-yyyy';return t;},str_to_user:function(val,no_time_str){var user_fmt=dateutil.get_user_fmt();var time_str='';if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');if(tmp[1])
+last_date=29;return y+'-'+int_to_str(m,2)+'-'+last_date;},get_user_fmt:function(){var t=sys_defaults.date_format;if(!t)t='dd-mm-yyyy';return t;},str_to_user:function(val,no_time_str){var user_fmt=dateutil.get_user_fmt();var time_str='';if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');if(tmp[1])
 time_str=' '+tmp[1];var d=tmp[0];}else{var d=val;}
 if(no_time_str)time_str='';d=d.split('-');if(d.length==3){if(user_fmt=='dd-mm-yyyy')
 val=d[2]+'-'+d[1]+'-'+d[0]+time_str;else if(user_fmt=='dd/mm/yyyy')
@@ -719,7 +719,7 @@
 HTMLField.prototype=new Field();HTMLField.prototype.with_label=0;HTMLField.prototype.set_disp=function(val){this.disp_area.innerHTML=val;}
 HTMLField.prototype.set_input=function(val){if(val)this.set_disp(val);}
 HTMLField.prototype.onrefresh=function(){this.set_disp(this.df.options?this.df.options:'');}
-var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=wn.control_panel.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
+var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=sys_defaults.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
 _f.cur_grid_cell.grid.cell_deselect();}});var me=this;me.input.onchange=function(){if(this.value==null)this.value='';if(!this.not_in_form)
 me.set(dateutil.user_to_str(me.input.value));me.run_trigger();}
 me.input.set_input=function(val){if(val==null)val='';else val=dateutil.str_to_user(val);me.input.value=val;}
@@ -1546,7 +1546,7 @@
 HTMLField.prototype=new Field();HTMLField.prototype.with_label=0;HTMLField.prototype.set_disp=function(val){this.disp_area.innerHTML=val;}
 HTMLField.prototype.set_input=function(val){if(val)this.set_disp(val);}
 HTMLField.prototype.onrefresh=function(){this.set_disp(this.df.options?this.df.options:'');}
-var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=wn.control_panel.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
+var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=sys_defaults.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
 _f.cur_grid_cell.grid.cell_deselect();}});var me=this;me.input.onchange=function(){if(this.value==null)this.value='';if(!this.not_in_form)
 me.set(dateutil.user_to_str(me.input.value));me.run_trigger();}
 me.input.set_input=function(val){if(val==null)val='';else val=dateutil.str_to_user(val);me.input.value=val;}
diff --git a/public/js/all-web.js b/public/js/all-web.js
index 5a4a4a1..c52a51a 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -365,7 +365,7 @@
 new_dt=new Date(dt.getFullYear(),dt.getMonth()+months,dt.getDate())
 if(new_dt.getDate()!=dt.getDate()){return dateutil.month_end(new Date(dt.getFullYear(),dt.getMonth()+months,1))}
 return dateutil.obj_to_str(new_dt);},month_start:function(){var d=new Date();return d.getFullYear()+'-'+int_to_str(d.getMonth()+1,2)+'-01';},month_end:function(d){if(!d)var d=new Date();var m=d.getMonth()+1;var y=d.getFullYear();last_date=month_last[m];if(m==2&&(y%4)==0&&((y%100)!=0||(y%400)==0))
-last_date=29;return y+'-'+int_to_str(m,2)+'-'+last_date;},get_user_fmt:function(){var t=wn.control_panel.date_format;if(!t)t='dd-mm-yyyy';return t;},str_to_user:function(val,no_time_str){var user_fmt=dateutil.get_user_fmt();var time_str='';if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');if(tmp[1])
+last_date=29;return y+'-'+int_to_str(m,2)+'-'+last_date;},get_user_fmt:function(){var t=sys_defaults.date_format;if(!t)t='dd-mm-yyyy';return t;},str_to_user:function(val,no_time_str){var user_fmt=dateutil.get_user_fmt();var time_str='';if(val==null||val=='')return null;if(val.search(':')!=-1){var tmp=val.split(' ');if(tmp[1])
 time_str=' '+tmp[1];var d=tmp[0];}else{var d=val;}
 if(no_time_str)time_str='';d=d.split('-');if(d.length==3){if(user_fmt=='dd-mm-yyyy')
 val=d[2]+'-'+d[1]+'-'+d[0]+time_str;else if(user_fmt=='dd/mm/yyyy')
diff --git a/public/js/fields.js b/public/js/fields.js
index 32aa00c..c85c8c2 100644
--- a/public/js/fields.js
+++ b/public/js/fields.js
@@ -83,7 +83,7 @@
 HTMLField.prototype=new Field();HTMLField.prototype.with_label=0;HTMLField.prototype.set_disp=function(val){this.disp_area.innerHTML=val;}
 HTMLField.prototype.set_input=function(val){if(val)this.set_disp(val);}
 HTMLField.prototype.onrefresh=function(){this.set_disp(this.df.options?this.df.options:'');}
-var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=wn.control_panel.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
+var datepicker_active=0;function DateField(){}DateField.prototype=new Field();DateField.prototype.make_input=function(){var me=this;this.user_fmt=sys_defaults.date_format;if(!this.user_fmt)this.user_fmt='dd-mm-yy';this.input=$a(this.input_area,'input');$(this.input).datepicker({dateFormat:me.user_fmt.replace('yyyy','yy'),altFormat:'yy-mm-dd',changeYear:true,beforeShow:function(input,inst){datepicker_active=1},onClose:function(dateText,inst){datepicker_active=0;if(_f.cur_grid_cell)
 _f.cur_grid_cell.grid.cell_deselect();}});var me=this;me.input.onchange=function(){if(this.value==null)this.value='';if(!this.not_in_form)
 me.set(dateutil.user_to_str(me.input.value));me.run_trigger();}
 me.input.set_input=function(val){if(val==null)val='';else val=dateutil.str_to_user(val);me.input.value=val;}