[bom] [production] Cleaned up BOM, Production Planning Tool, Progress in Demo Builder
diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py
index 7d5dcb8..3780ae8 100644
--- a/manufacturing/doctype/bom/bom.py
+++ b/manufacturing/doctype/bom/bom.py
@@ -118,6 +118,11 @@
 				rate = self.get_valuation_rate(arg)
 			elif self.doc.rm_cost_as_per == 'Last Purchase Rate':
 				rate = arg['last_purchase_rate']
+			elif self.doc.rm_cost_as_per == "Price List":
+				if not self.doc.price_list:
+					webnotes.throw(_("Please select Price List"))
+				rate = webnotes.conn.get_value("Item Price", {"price_list_name": self.doc.price_list, 
+					"parent": arg["item_code"]}, "ref_rate") or 0
 			elif self.doc.rm_cost_as_per == 'Standard Rate':
 				rate = arg['standard_rate']
 
@@ -180,7 +185,7 @@
 				webnotes.conn.set(self.doc, "is_default", 0)
 			
 			sql("update `tabItem` set default_bom = null where name = %s and default_bom = %s", 
-			 	(self.doc.item, self.doc.name))
+				 (self.doc.item, self.doc.name))
 
 	def clear_operations(self):
 		if not self.doc.with_operations:
diff --git a/manufacturing/doctype/bom/bom.txt b/manufacturing/doctype/bom/bom.txt
index 92362ae..1793e6b 100644
--- a/manufacturing/doctype/bom/bom.txt
+++ b/manufacturing/doctype/bom/bom.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-22 15:11:38", 
   "docstatus": 0, 
-  "modified": "2013-07-22 15:28:38", 
+  "modified": "2013-08-07 17:09:46", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -67,11 +67,6 @@
   "search_index": 1
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "cb0", 
-  "fieldtype": "Column Break"
- }, 
- {
   "allow_on_submit": 1, 
   "default": "1", 
   "doctype": "DocField", 
@@ -87,6 +82,7 @@
  }, 
  {
   "allow_on_submit": 1, 
+  "default": "1", 
   "doctype": "DocField", 
   "fieldname": "is_default", 
   "fieldtype": "Check", 
@@ -97,6 +93,11 @@
   "oldfieldtype": "Check"
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "cb0", 
+  "fieldtype": "Column Break"
+ }, 
+ {
   "description": "Manage cost of operations", 
   "doctype": "DocField", 
   "fieldname": "with_operations", 
@@ -104,6 +105,22 @@
   "label": "With Operations"
  }, 
  {
+  "doctype": "DocField", 
+  "fieldname": "rm_cost_as_per", 
+  "fieldtype": "Select", 
+  "label": "Rate Of Materials Based On", 
+  "options": "Valuation Rate\nLast Purchase Rate\nPrice List"
+ }, 
+ {
+  "depends_on": "eval:doc.rm_cost_as_per===\"Price List\"", 
+  "description": "Price List for Costing", 
+  "doctype": "DocField", 
+  "fieldname": "price_list", 
+  "fieldtype": "Link", 
+  "label": "Price List", 
+  "options": "Price List"
+ }, 
+ {
   "depends_on": "with_operations", 
   "doctype": "DocField", 
   "fieldname": "operations", 
@@ -147,13 +164,6 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "rm_cost_as_per", 
-  "fieldtype": "Select", 
-  "label": "Rate Of Materials Based On", 
-  "options": "Valuation Rate\nLast Purchase Rate"
- }, 
- {
-  "doctype": "DocField", 
   "fieldname": "total_cost", 
   "fieldtype": "Float", 
   "in_list_view": 1, 
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.js b/manufacturing/doctype/production_planning_tool/production_planning_tool.js
index ebe1a1c..daa7013 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.js
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.js
@@ -2,8 +2,8 @@
 // License: GNU General Public License v3. See license.txt
 
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
-	doc.company = wn.defaults.get_default("company");
-	refresh_field("company");
+	cur_frm.set_value("company", wn.defaults.get_default("company"))
+	cur_frm.set_value("use_multi_level_bom", 1)
 }
 
 cur_frm.cscript.refresh = function(doc) {
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index 09c2705..7a92437 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -148,6 +148,7 @@
 	
 
 	def validate_data(self):
+		self.validate_company()
 		for d in getlist(self.doclist, 'pp_details'):
 			self.validate_bom_no(d)
 			if not flt(d.planned_qty):
@@ -169,7 +170,6 @@
 
 	def raise_production_order(self):
 		"""It will raise production order (Draft) for all distinct FG items"""
-		self.validate_company()
 		self.validate_data()
 
 		from utilities.transaction_base import validate_uom_is_integer
@@ -180,15 +180,15 @@
 		if pro:
 			pro = ["""<a href="#Form/Production Order/%s" target="_blank">%s</a>""" % \
 				(p, p) for p in pro]
-			msgprint("Following Production Order has been generated:\n" + '\n'.join(pro))
+			msgprint("Production Order(s) created:\n\n" + '\n'.join(pro))
 		else :
-			msgprint("No Production Order generated.")
+			msgprint("No Production Order created.")
 
 
 	def get_distinct_items_and_boms(self):
 		""" Club similar BOM and item for processing"""
 		item_dict, bom_dict = {}, {}
-		for d in self.doclist.get({"parentfield": "pp_details"}):
+		for d in self.doclist.get({"parentfield": "pp_details"}):			
 			bom_dict[d.bom_no] = bom_dict.get(d.bom_no, 0) + flt(d.planned_qty)
 			item_dict[(d.item_code, d.sales_order)] = {
 				"qty" 				: flt(item_dict.get((d.item_code, d.sales_order), \
@@ -223,6 +223,7 @@
 
 	def download_raw_materials(self):
 		""" Create csv data for required raw material to produce finished goods"""
+		self.validate_data()
 		bom_dict = self.get_distinct_items_and_boms()[0]
 		self.get_raw_materials(bom_dict)
 		return self.get_csv()
@@ -283,6 +284,7 @@
 			Raise Material Request if projected qty is less than qty required
 			Requested qty should be shortage qty considering minimum order qty
 		"""
+		self.validate_data()
 		if not self.doc.purchase_request_for_warehouse:
 			webnotes.msgprint("Please enter Warehouse for which Material Request will be raised",
 			 	raise_exception=1)
@@ -308,6 +310,7 @@
 			
 	def get_projected_qty(self):
 		items = self.item_dict.keys()
+				
 		item_projected_qty = webnotes.conn.sql("""select item_code, sum(projected_qty) 
 			from `tabBin` where item_code in (%s) group by item_code""" % 
 			(", ".join(["%s"]*len(items)),), tuple(items))
@@ -355,7 +358,7 @@
 			if purchase_request_list:
 				pur_req = ["""<a href="#Form/Material Request/%s" target="_blank">%s</a>""" % \
 					(p, p) for p in purchase_request_list]
-				webnotes.msgprint("Following Material Request created successfully: \n%s" % 
+				webnotes.msgprint("Material Request(s) created: \n%s" % 
 					"\n".join(pur_req))
 		else:
 			webnotes.msgprint("Nothing to request")
diff --git a/manufacturing/doctype/production_planning_tool/production_planning_tool.txt b/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
index 85d8dab..482946b 100644
--- a/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
+++ b/manufacturing/doctype/production_planning_tool/production_planning_tool.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-01-21 12:03:47", 
   "docstatus": 0, 
-  "modified": "2013-07-22 15:26:45", 
+  "modified": "2013-08-07 17:21:19", 
   "modified_by": "Administrator", 
   "owner": "jai@webnotestech.com"
  }, 
@@ -118,47 +118,18 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "clear_so_table", 
-  "fieldtype": "Button", 
-  "label": "Clear Table", 
-  "options": "clear_so_table"
- }, 
- {
-  "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.", 
-  "doctype": "DocField", 
-  "fieldname": "create_production_orders", 
+  "fieldname": "items_for_production", 
   "fieldtype": "Section Break", 
-  "label": "Create Production Orders"
+  "label": "Select Items"
  }, 
  {
-  "description": "Pull items from Sales Order mentioned in the above table.", 
   "doctype": "DocField", 
   "fieldname": "get_items_from_so", 
   "fieldtype": "Button", 
-  "label": "Get Items", 
+  "label": "Get Items From Sales Orders", 
   "options": "get_items_from_so"
  }, 
  {
-  "doctype": "DocField", 
-  "fieldname": "pp_details", 
-  "fieldtype": "Table", 
-  "label": "Production Plan Items", 
-  "options": "Production Plan Item"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "clear_item_table", 
-  "fieldtype": "Button", 
-  "label": "Clear Table", 
-  "options": "clear_item_table"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "section_break3", 
-  "fieldtype": "Section Break", 
-  "options": "Simple"
- }, 
- {
   "default": "1", 
   "description": "If checked, BOM for sub-assembly items will be considered for getting raw materials. Otherwise, all sub-assembly items will be treated as a raw material.", 
   "doctype": "DocField", 
@@ -169,36 +140,31 @@
  }, 
  {
   "doctype": "DocField", 
-  "fieldname": "cb5", 
-  "fieldtype": "Column Break", 
-  "width": "50%"
+  "fieldname": "pp_details", 
+  "fieldtype": "Table", 
+  "label": "Production Plan Items", 
+  "options": "Production Plan Item"
+ }, 
+ {
+  "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.", 
+  "doctype": "DocField", 
+  "fieldname": "create_production_orders", 
+  "fieldtype": "Section Break", 
+  "label": "Production Orders"
  }, 
  {
   "description": "Separate production order will be created for each finished good item.", 
   "doctype": "DocField", 
   "fieldname": "raise_production_order", 
   "fieldtype": "Button", 
-  "label": "Raise Production Order", 
+  "label": "Create Production Orders", 
   "options": "raise_production_order"
  }, 
  {
   "doctype": "DocField", 
   "fieldname": "sb5", 
   "fieldtype": "Section Break", 
-  "label": "Materials Requirement Planning (MRP)"
- }, 
- {
-  "description": "Download a report containing all raw materials with their latest inventory status", 
-  "doctype": "DocField", 
-  "fieldname": "download_materials_required", 
-  "fieldtype": "Button", 
-  "label": "Download Materials Required"
- }, 
- {
-  "doctype": "DocField", 
-  "fieldname": "column_break6", 
-  "fieldtype": "Column Break", 
-  "width": "50%"
+  "label": "Material Requirement"
  }, 
  {
   "doctype": "DocField", 
@@ -212,10 +178,17 @@
   "doctype": "DocField", 
   "fieldname": "raise_purchase_request", 
   "fieldtype": "Button", 
-  "label": "Raise Material Request", 
+  "label": "Create Material Requests", 
   "options": "raise_purchase_request"
  }, 
  {
+  "description": "Download a report containing all raw materials with their latest inventory status", 
+  "doctype": "DocField", 
+  "fieldname": "download_materials_required", 
+  "fieldtype": "Button", 
+  "label": "Download Materials Required"
+ }, 
+ {
   "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/selling/doctype/quotation/quotation.txt b/selling/doctype/quotation/quotation.txt
index 7949c03..82c0650 100644
--- a/selling/doctype/quotation/quotation.txt
+++ b/selling/doctype/quotation/quotation.txt
@@ -2,7 +2,7 @@
  {
   "creation": "2013-05-24 19:29:08", 
   "docstatus": 0, 
-  "modified": "2013-07-26 11:16:53", 
+  "modified": "2013-08-07 16:20:21", 
   "modified_by": "Administrator", 
   "owner": "Administrator"
  }, 
@@ -728,6 +728,7 @@
   "fieldname": "status", 
   "fieldtype": "Select", 
   "in_filter": 1, 
+  "in_list_view": 1, 
   "label": "Status", 
   "no_copy": 1, 
   "oldfieldname": "status", 
diff --git a/startup/install.py b/startup/install.py
index 0824c6c..7e9273c 100644
--- a/startup/install.py
+++ b/startup/install.py
@@ -107,6 +107,7 @@
 		{'doctype': 'Item Group', 'item_group_name': 'Products', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
 		{'doctype': 'Item Group', 'item_group_name': 'Raw Material', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
 		{'doctype': 'Item Group', 'item_group_name': 'Services', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
+		{'doctype': 'Item Group', 'item_group_name': 'Sub Assemblies', 'is_group': 'No', 'parent_item_group': 'All Item Groups'},
 		
 		# deduction type
 		{'doctype': 'Deduction Type', 'name': 'Income Tax', 'description': 'Income Tax', 'deduction_name': 'Income Tax'},
diff --git a/utilities/demo_docs/BOM.csv b/utilities/demo_docs/BOM.csv
new file mode 100644
index 0000000..8e31275
--- /dev/null
+++ b/utilities/demo_docs/BOM.csv
@@ -0,0 +1,48 @@
+"Data Import Template"

+"Table:","BOM"

+""

+""

+"Notes:"

+"Please do not change the template headings."

+"First data column must be blank."

+"If you are uploading new records, leave the ""name"" (ID) column blank."

+"If you are uploading new records, ""Naming Series"" becomes mandatory, if present."

+"Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish."

+"For updating, you can update only selective columns."

+"You can only upload upto 5000 records in one go. (may be less in some cases)"

+""

+"DocType:","BOM","","","","","","","","","","","","","","","","-","BOM Operation","bom_operations","","","","","","-","BOM Item","bom_materials","","","","","","","","","-","BOM Explosion Item","flat_bom_details","","","","","",""

+"Column Labels:","ID","Last Updated On","Item","Quantity","Is Active","Is Default","With Operations","Rate Of Materials Based On","Price List","Total Cost","Total Raw Material Cost","Total Operating Cost","Item UOM","Project Name","Item Desription","Amended From","-","ID","Operation No","Operation Description","Workstation","Hour Rate","Operation Time (mins)","Operating Cost","-","ID","Item Code","Qty","Stock UOM","Operation No","BOM No","Rate","Amount","Scrap %","Item Description","-","ID","Item Code","Description","Qty","Rate","Amount","Stock UOM","Qty Consumed Per Unit"

+"Column Name:","name","modified","item","quantity","is_active","is_default","with_operations","rm_cost_as_per","price_list","total_cost","raw_material_cost","operating_cost","uom","project_name","description","amended_from","-","name","operation_no","opn_description","workstation","hour_rate","time_in_mins","operating_cost","-","name","item_code","qty","stock_uom","operation_no","bom_no","rate","amount","scrap","description","-","name","item_code","description","qty","rate","amount","stock_uom","qty_consumed_per_unit"

+"Mandatory:","Yes","Yes","Yes","Yes","No","No","No","No","No","No","No","No","No","No","No","No","-","Yes","Yes","Yes","No","No","No","No","-","Yes","Yes","Yes","Yes","No","No","No","No","No","No","-","Yes","No","No","No","No","No","No","No"

+"Type:","Data (text)","Data","Link","Float","Check","Check","Check","Select","Link","Float","Float","Float","Select","Link","Small Text","Link","-","Data","Data","Text","Link","Float","Float","Float","-","Data","Link","Float","Link","Select","Link","Float","Float","Float","Text","-","Data","Link","Text","Float","Float","Float","Link","Float"

+"Info:","","Don't change!","Valid Item","","0 or 1","0 or 1","0 or 1","One of: Valuation Rate, Last Purchase Rate, Price List","Valid Price List","","","","Valid UOM","Valid Project","","Valid BOM","-","Leave blank for new records","","","Valid Workstation","","","","-","Leave blank for new records","Valid Item","","Valid UOM","","Valid BOM","","","","","-","Leave blank for new records","Valid Item","","","","","Valid UOM",""

+"Start entering data below this line"

+"","BOM/Bearing Assembly/001","""2013-08-07 16:58:00""","Bearing Assembly",1.0,1,"","","Price List","Standard Buying",130.0,130.0,0.0,"Nos","","Bearing Assembly","","","","","","","","","","","000000183","Base Bearing Plate",1.0,"Nos","","",15.0,15.0,"","1/4 in. x 6 in. x 6 in. Mild Steel Plate","","FBD/000039","Bearing Pipe","1.5 in. Diameter x 36 in. Mild Steel Tubing",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000184","Bearing Block",1.0,"Nos","","",10.0,10.0,"","CAST IRON, MCMASTER PART NO. 3710T13","","FBD/000040","Bearing Collar","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar",2.0,20.0,40.0,"Nos",2.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000185","Bearing Collar",2.0,"Nos","","",20.0,40.0,"","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar","","FBD/000041","Bearing Block","CAST IRON, MCMASTER PART NO. 3710T13",1.0,10.0,10.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000186","Bearing Pipe",1.0,"Nos","","",15.0,15.0,"","1.5 in. Diameter x 36 in. Mild Steel Tubing","","FBD/000042","Upper Bearing Plate","3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate",1.0,50.0,50.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000187","Upper Bearing Plate",1.0,"Nos","","",50.0,50.0,"","3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate","","FBD/000043","Base Bearing Plate","1/4 in. x 6 in. x 6 in. Mild Steel Plate",1.0,15.0,15.0,"Nos",1.0

+"","BOM/Wind Mill A Series/001","""2013-08-07 16:47:02""","Wind Mill A Series",1.0,1,"","","Price List","Standard Buying",223.0,223.0,0.0,"Nos","","Wind Mill A Series for Home Use 9ft","","","","","","","","","","","000000163","Base Bearing Plate",1.0,"Nos","","",15.0,15.0,"","1/4 in. x 6 in. x 6 in. Mild Steel Plate","","FBD/000008","Shaft","1.25 in. Diameter x 6 ft. Mild Steel Tubing",1.0,30.0,30.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000164","Base Plate",1.0,"Nos","","",20.0,20.0,"","3/4 in. x 2 ft. x 4 ft. Pine Plywood","","FBD/000009","Base Bearing Plate","1/4 in. x 6 in. x 6 in. Mild Steel Plate",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000165","Bearing Block",1.0,"Nos","","",10.0,10.0,"","CAST IRON, MCMASTER PART NO. 3710T13","","FBD/000010","External Disc","15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing",1.0,45.0,45.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000166","Bearing Pipe",1.0,"Nos","","",15.0,15.0,"","1.5 in. Diameter x 36 in. Mild Steel Tubing","","FBD/000011","Bearing Pipe","1.5 in. Diameter x 36 in. Mild Steel Tubing",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000167","External Disc",1.0,"Nos","","",45.0,45.0,"","15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing","","FBD/000012","Wing Sheet","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet",4.0,22.0,88.0,"Nos",4.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000168","Shaft",1.0,"Nos","","",30.0,30.0,"","1.25 in. Diameter x 6 ft. Mild Steel Tubing","","FBD/000013","Base Plate","3/4 in. x 2 ft. x 4 ft. Pine Plywood",1.0,20.0,20.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000169","Wing Sheet",4.0,"Nos","","",22.0,88.0,"","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet","","FBD/000014","Bearing Block","CAST IRON, MCMASTER PART NO. 3710T13",1.0,10.0,10.0,"Nos",1.0

+"","BOM/Wind MIll C Series/001","""2013-08-07 16:58:51""","Wind MIll C Series",1.0,1,"","","Price List","Standard Buying",314.0,314.0,0.0,"Nos","","Wind Mill C Series for Commercial Use 18ft","","","","","","","","","","","000000176","Base Plate",2.0,"Nos","","",20.0,40.0,"","3/4 in. x 2 ft. x 4 ft. Pine Plywood","","FBD/000061","Base Bearing Plate","1/4 in. x 6 in. x 6 in. Mild Steel Plate",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000178","Internal Disc",1.0,"Nos","","",33.0,33.0,"","For Bearing Collar","","FBD/000062","Bearing Collar","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar",2.0,20.0,40.0,"Nos",2.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000179","External Disc",1.0,"Nos","","",45.0,45.0,"","15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing","","FBD/000063","Base Plate","3/4 in. x 2 ft. x 4 ft. Pine Plywood",2.0,20.0,40.0,"Nos",2.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000188","Bearing Assembly",1.0,"Nos","","BOM/Bearing Assembly/001",130.0,130.0,"","Bearing Assembly","","FBD/000064","Bearing Pipe","1.5 in. Diameter x 36 in. Mild Steel Tubing",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000189","Wing Sheet",3.0,"Nos","","",22.0,66.0,"","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet","","FBD/000065","Internal Disc","For Bearing Collar",1.0,33.0,33.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","FBD/000066","Upper Bearing Plate","3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate",1.0,50.0,50.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","FBD/000067","Wing Sheet","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet",3.0,22.0,66.0,"Nos",3.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","FBD/000068","External Disc","15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing",1.0,45.0,45.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","FBD/000069","Bearing Block","CAST IRON, MCMASTER PART NO. 3710T13",1.0,10.0,10.0,"Nos",1.0

+"","BOM/Wind Turbine/001","""2013-08-07 16:51:56""","Wind Turbine",1.0,1,"","","Price List","Standard Buying",139.0,139.0,0.0,"Nos","","Small Wind Turbine for Home Use","","","","","","","","","","","000000170","Base Bearing Plate",1.0,"Nos","","",15.0,15.0,"","1/4 in. x 6 in. x 6 in. Mild Steel Plate","","FBD/000021","Shaft","1.25 in. Diameter x 6 ft. Mild Steel Tubing",1.0,30.0,30.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000171","Base Plate",1.0,"Nos","","",20.0,20.0,"","3/4 in. x 2 ft. x 4 ft. Pine Plywood","","FBD/000022","Bearing Collar","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar",1.0,20.0,20.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000172","Bearing Collar",1.0,"Nos","","",20.0,20.0,"","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar","","FBD/000023","Base Plate","3/4 in. x 2 ft. x 4 ft. Pine Plywood",1.0,20.0,20.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000173","Blade Rib",1.0,"Nos","","",10.0,10.0,"","1/2 in. x 2 ft. x 4 ft. Pine Plywood","","FBD/000024","Base Bearing Plate","1/4 in. x 6 in. x 6 in. Mild Steel Plate",1.0,15.0,15.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000174","Shaft",1.0,"Nos","","",30.0,30.0,"","1.25 in. Diameter x 6 ft. Mild Steel Tubing","","FBD/000025","Blade Rib","1/2 in. x 2 ft. x 4 ft. Pine Plywood",1.0,10.0,10.0,"Nos",1.0

+"","","","","","","","","","","","","","","","","","","","","","","","","","","000000175","Wing Sheet",2.0,"Nos","","",22.0,44.0,"","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet","","FBD/000026","Wing Sheet","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet",2.0,22.0,44.0,"Nos",2.0

+
diff --git a/utilities/demo_docs/Item.csv b/utilities/demo_docs/Item.csv
index 57d438d..b9ab6eb 100644
--- a/utilities/demo_docs/Item.csv
+++ b/utilities/demo_docs/Item.csv
@@ -1,36 +1,38 @@
-Data Import Template,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-Table:,Item,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-Notes:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-Please do not change the template headings.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-First data column must be blank.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-"For updating, you can update only selective columns.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-"If you are uploading new records, leave the ""name"" (ID) column blank.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-"If you are uploading new records, ""Naming Series"" becomes mandatory, if present.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-You can only upload upto 5000 records in one go. (may be less in some cases),,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-Column Labels,ID,Is Service Item,Is Asset Item,Is Sub Contracted Item,Item Name,Is Sales Item,Default Unit of Measure,Allow Production Order,Allow Bill of Materials,Description,Is Stock Item,Inspection Required,Is Purchase Item,Item Group,Has Batch No,Has Serial No,Allow Samples,Item Code,Default Reserved Warehouse,Cost Center,Last Purchase Rate,Default BOM,Naming Series,Image,Valuation Method,Image,Weightage,Net Weight,Max Discount (%),Warranty Period (in days),Default Cost Center,Re-Order Level,Default Income Account,Default Expense Account,Description HTML,Show in Website,End of Life,Website Warehouse,Manufacturer Part Number,Page Name,Manufacturer,Allowance Percent,Brand,Barcode,Slideshow,Re-Order Qty,Weight UOM,Minimum Order Qty,Lead Time Days,Website Description,Standard Rate

-Column Name:,name,is_service_item,is_asset_item,is_sub_contracted_item,item_name,is_sales_item,stock_uom,is_pro_applicable,is_manufactured_item,description,is_stock_item,inspection_required,is_purchase_item,item_group,has_batch_no,has_serial_no,is_sample_item,item_code,default_warehouse,default_sales_cost_center,last_purchase_rate,default_bom,naming_series,image,valuation_method,website_image,weightage,net_weight,max_discount,warranty_period,cost_center,re_order_level,default_income_account,purchase_account,description_html,show_in_website,end_of_life,website_warehouse,manufacturer_part_no,page_name,manufacturer,tolerance,brand,barcode,slideshow,re_order_qty,weight_uom,min_order_qty,lead_time_days,web_long_description,standard_rate

-Mandatory:,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No

-Type:,Data (text),Select,Select,Select,Data,Select,Link,Select,Select,Small Text,Select,Select,Select,Link,Select,Select,Select,Data,Link,Link,Float,Link,Select,Select,Select,Select,Int,Float,Float,Data,Link,Float,Link,Link,Small Text,Check,Date,Link,Data,Data,Data,Float,Link,Data,Link,Float,Link,Float,Int,Text Editor,Float

-Info:,,"One of: Yes, No","One of: Yes, No","One of: Yes, No",,"One of: Yes, No",Valid UOM,"One of: Yes, No","One of: Yes, No",,"One of: Yes, No","One of: Yes, No","One of: Yes, No",Valid Item Group,"One of: Yes, No","One of: Yes, No","One of: Yes, No",,Valid Warehouse,Valid Cost Center,,Valid BOM,One of: ITEM,One of: attach_files:,"One of: FIFO, Moving Average",One of: attach_files:,Integer,,,,Valid Cost Center,,Valid Account,Valid Account,,0 or 1,,Valid Warehouse,,,,,Valid Brand,,Valid Website Slideshow,,Valid UOM,,Integer,,

-Start entering data below this line,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Wind Turbine,Yes,No,No,Wind Turbine,Yes,Nos,Yes,Yes,Small Wind Turbine for Home Use,Yes,No,Yes,Products,No,No,No,Wind Turbine,Finished Goods - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Wind Mill A Series,Yes,No,No,Wind Mill A Series,Yes,Nos,Yes,Yes,Wind Mill A Series for Home Use 9ft,Yes,No,Yes,Products,No,Yes,No,Wind Mill A Series,Finished Goods - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Wind Mill A Series,Yes,No,No,Wind Mill A Series,Yes,Nos,Yes,Yes,Wind Mill A Series for Home Use 12ft,Yes,No,Yes,Products,No,Yes,No,Wind Mill A Series,Finished Goods - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Wind MIll C Series,Yes,No,No,Wind MIll C Series,Yes,Nos,Yes,Yes,Wind Mill C Series for Commercial Use 18ft,Yes,No,Yes,Products,No,Yes,No,Wind MIll C Series,Finished Goods - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Base Plate,Yes,No,No,Base Plate,Yes,Nos,Yes,No,3/4 in. x 2 ft. x 4 ft. Pine Plywood,Yes,No,Yes,Raw Material,No,No,No,Base Plate,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Base Bearing Plate,Yes,No,No,Base Bearing Plate,Yes,Nos,Yes,No,1/4 in. x 6 in. x 6 in. Mild Steel Plate,Yes,No,Yes,Raw Material,No,No,No,Base Bearing Plate,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Bearing Pipe,Yes,No,No,Bearing Pipe,Yes,Nos,Yes,No,1.5 in. Diameter x 36 in. Mild Steel Tubing,Yes,No,Yes,Raw Material,No,No,No,Bearing Pipe,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Upper Bearing Plate,Yes,No,No,Upper Bearing Plate,Yes,Nos,Yes,No,3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate,Yes,No,Yes,Raw Material,No,No,No,Upper Bearing Plate,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Bearing Collar,Yes,No,No,Bearing Collar,Yes,Nos,Yes,No,1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar ,Yes,No,Yes,Raw Material,No,No,No,Bearing Collar,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,External Disc,Yes,No,No,External Disc,Yes,Nos,Yes,No,15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing ,Yes,No,Yes,Raw Material,No,No,No,External Disc,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Shaft,Yes,No,No,Shaft,Yes,Nos,Yes,No,1.25 in. Diameter x 6 ft. Mild Steel Tubing,Yes,No,Yes,Raw Material,No,No,No,Shaft,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Internal Disc,Yes,No,No,Internal Disc,Yes,Nos,Yes,No,For Bearing Collar,Yes,No,Yes,Raw Material,No,No,No,Internal Disc,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Blade Rib,Yes,No,No,Blade Rib,Yes,Nos,Yes,No,1/2 in. x 2 ft. x 4 ft. Pine Plywood,Yes,No,Yes,Raw Material,No,No,No,Blade Rib,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Wing Sheet,Yes,No,No,Wing Sheet,Yes,Nos,Yes,No,1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet,Yes,No,Yes,Raw Material,No,No,No,Wing Sheet,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Disc Collars,Yes,No,No,Disc Collars,Yes,Nos,Yes,No,For Upper Bearing,Yes,No,Yes,Raw Material,No,No,No,Disc Collars,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Bearing Block,Yes,No,No,Bearing Block,Yes,Nos,Yes,No,"CAST IRON, MCMASTER PART NO. 3710T13",Yes,No,Yes,Raw Material,No,No,No,Bearing Block,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

-,Stand,Yes,No,No,Stand,Yes,Nos,Yes,No,N/A,Yes,No,Yes,Raw Material,No,No,No,Stand,Stores - WP,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
\ No newline at end of file
+"Data Import Template"

+"Table:","Item"

+""

+""

+"Notes:"

+"Please do not change the template headings."

+"First data column must be blank."

+"If you are uploading new records, leave the ""name"" (ID) column blank."

+"If you are uploading new records, ""Naming Series"" becomes mandatory, if present."

+"Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish."

+"For updating, you can update only selective columns."

+"You can only upload upto 5000 records in one go. (may be less in some cases)"

+""

+"DocType:","Item","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"Column Labels:","ID","Item Name","Item Group","Default Unit of Measure","Description","Is Stock Item","Is Asset Item","Has Batch No","Has Serial No","Is Purchase Item","Is Sales Item","Is Service Item","Allow Samples","Inspection Required","Allow Bill of Materials","Allow Production Order","Is Sub Contracted Item","Naming Series","Item Code","Brand","Barcode","Image","Description HTML","Default Warehouse","Allowance Percent","Valuation Method","Minimum Order Qty","Warranty Period (in days)","End of Life","Net Weight","Weight UOM","Re-Order Level","Re-Order Qty","Default Supplier","Lead Time Days","Default Expense Account","Default Cost Center","Last Purchase Rate","Standard Rate","Manufacturer","Manufacturer Part Number","Max Discount (%)","Default Income Account","Cost Center","Default BOM","Show in Website","Page Name","Weightage","Slideshow","Image","Website Warehouse","Website Description"

+"Column Name:","name","item_name","item_group","stock_uom","description","is_stock_item","is_asset_item","has_batch_no","has_serial_no","is_purchase_item","is_sales_item","is_service_item","is_sample_item","inspection_required","is_manufactured_item","is_pro_applicable","is_sub_contracted_item","naming_series","item_code","brand","barcode","image","description_html","default_warehouse","tolerance","valuation_method","min_order_qty","warranty_period","end_of_life","net_weight","weight_uom","re_order_level","re_order_qty","default_supplier","lead_time_days","purchase_account","cost_center","last_purchase_rate","standard_rate","manufacturer","manufacturer_part_no","max_discount","default_income_account","default_sales_cost_center","default_bom","show_in_website","page_name","weightage","slideshow","website_image","website_warehouse","web_long_description"

+"Mandatory:","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","Yes","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No","No"

+"Type:","Data (text)","Data","Link","Link","Small Text","Select","Select","Select","Select","Select","Select","Select","Select","Select","Select","Select","Select","Select","Data","Link","Data","Select","Small Text","Link","Float","Select","Float","Data","Date","Float","Link","Float","Float","Link","Int","Link","Link","Float","Float","Data","Data","Float","Link","Link","Link","Check","Data","Int","Link","Select","Link","Text Editor"

+"Info:","","","Valid Item Group","Valid UOM","","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: Yes, No","One of: ITEM","","Valid Brand","","One of: attach_files:","","Valid Warehouse","","One of: FIFO, Moving Average","","","","","Valid UOM","","","Valid Supplier","Integer","Valid Account","Valid Cost Center","","","","","","Valid Account","Valid Cost Center","Valid BOM","0 or 1","","Integer","Valid Website Slideshow","One of: attach_files:","Valid Warehouse",""

+"Start entering data below this line"

+"","Base Bearing Plate","Base Bearing Plate","Raw Material","Nos","1/4 in. x 6 in. x 6 in. Mild Steel Plate","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Base Bearing Plate","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Base Plate","Base Plate","Raw Material","Nos","3/4 in. x 2 ft. x 4 ft. Pine Plywood","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Base Plate","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Bearing Assembly","Bearing Assembly","Sub Assemblies","Nos","Bearing Assembly","Yes","No","No","No","No","Yes","No","No","No","Yes","Yes","No","","Bearing Assembly","","","","","Stores - WP","","",0.0,"","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Bearing Block","Bearing Block","Raw Material","Nos","CAST IRON, MCMASTER PART NO. 3710T13","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Bearing Block","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Bearing Collar","Bearing Collar","Raw Material","Nos","1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Bearing Collar","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Bearing Pipe","Bearing Pipe","Raw Material","Nos","1.5 in. Diameter x 36 in. Mild Steel Tubing","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Bearing Pipe","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Blade Rib","Blade Rib","Raw Material","Nos","1/2 in. x 2 ft. x 4 ft. Pine Plywood","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Blade Rib","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Disc Collars","Disc Collars","Raw Material","Nos","For Upper Bearing","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Disc Collars","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","External Disc","External Disc","Raw Material","Nos","15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","External Disc","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Internal Disc","Internal Disc","Raw Material","Nos","For Bearing Collar","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Internal Disc","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Shaft","Shaft","Raw Material","Nos","1.25 in. Diameter x 6 ft. Mild Steel Tubing","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Shaft","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Stand","Stand","Raw Material","Nos","N/A","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Stand","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Upper Bearing Plate","Upper Bearing Plate","Raw Material","Nos","3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Upper Bearing Plate","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Wind Mill A Series","Wind Mill A Series","Products","Nos","Wind Mill A Series for Home Use 9ft","Yes","No","No","Yes","Yes","Yes","Yes","No","No","Yes","Yes","No","","Wind Mill A Series","","","","","Finished Goods - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Wind MIll C Series","Wind MIll C Series","Products","Nos","Wind Mill C Series for Commercial Use 18ft","Yes","No","No","Yes","Yes","Yes","Yes","No","No","Yes","Yes","No","","Wind MIll C Series","","","","","Finished Goods - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Wind Turbine","Wind Turbine","Products","Nos","Small Wind Turbine for Home Use","Yes","No","No","No","Yes","Yes","Yes","No","No","Yes","Yes","No","","Wind Turbine","","","","","Finished Goods - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+"","Wing Sheet","Wing Sheet","Raw Material","Nos","1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet","Yes","No","No","No","Yes","Yes","Yes","No","No","No","No","No","","Wing Sheet","","","","","Stores - WP","","","","","","","","","","","","","","","","","","","","","","","","","","","",""

+
diff --git a/utilities/make_demo.py b/utilities/make_demo.py
index 61a971b..025c83a 100644
--- a/utilities/make_demo.py
+++ b/utilities/make_demo.py
@@ -8,10 +8,12 @@
 webnotes.session = webnotes._dict({"user":"Administrator"})
 from core.page.data_import_tool.data_import_tool import upload
 
+company = "Wind Power LLC"
 start_date = '2010-01-01'
 runs_for = 100
 prob = {
-	"Quotation": 0.5
+	"Quotation": { "make": 0.5, "qty": (1,3) },
+	"Sales Order": { "make": 0.5, "qty": (1,2) }
 }
 
 def make():
@@ -20,9 +22,7 @@
 	webnotes.mute_emails = True
 
 	# setup()
-	# simulate()
-	make_quotation("2010-01-01")
-	webnotes.conn.commit()
+	simulate()
 	
 def setup():
 	install()
@@ -30,13 +30,13 @@
 	make_items()
 	make_customers_suppliers_contacts()
 	make_users_and_employees()
-	# make_bom()
 	# make_opening_stock()
 	# make_opening_accounts()
 
 def simulate():
 	current_date = None
 	for i in xrange(runs_for):
+		print i
 		if not current_date:
 			current_date = webnotes.utils.getdate(start_date)
 		else:
@@ -46,14 +46,34 @@
 			continue
 
 		run_sales(current_date)
-
-	webnotes.conn.commit()
+		run_purchase(current_date)
+		run_manufacturing(current_date)
 		
+	webnotes.conn.commit()
 
 def run_sales(current_date):
-	if random.random() < prob["Quotation"]:
-		make_quotation(current_date)
-		
+	if random.random() < prob["Quotation"]["make"]:
+		for i in xrange(random.randrange(*prob["Quotation"]["qty"])):
+			make_quotation(current_date)
+			
+	if random.random() < prob["Sales Order"]["make"]:
+		for i in xrange(random.randrange(*prob["Sales Order"]["qty"])):
+			make_sales_order(current_date)
+
+def run_purchase(current_date):
+	pass
+	
+def run_manufacturing(current_date):
+	ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
+	ppt.doc.company = company
+	ppt.doc.use_multi_level_bom = 1
+	ppt.doc.purchase_request_for_warehouse = "Stores - WP"
+	ppt.run_method("get_open_sales_orders")
+	ppt.run_method("get_items_from_so")
+	ppt.run_method("get_items_from_so")
+	ppt.run_method("raise_production_order")
+	ppt.run_method("raise_purchase_request")
+
 def make_quotation(current_date):
 	b = webnotes.bean([{
 		"creation": current_date,
@@ -75,7 +95,16 @@
 	}, unique="item_code")
 	
 	b.insert()
-	print b.doc.name
+	b.submit()
+	
+def make_sales_order(current_date):
+	q = get_random("Quotation", {"status": "Submitted"})
+	from selling.doctype.quotation.quotation import make_sales_order
+	so = webnotes.bean(make_sales_order(q))
+	so.doc.transaction_date = current_date
+	so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
+	so.insert()
+	so.submit()
 	
 def add_random_children(bean, template, rows, randomize, unique=None):
 	for i in xrange(random.randrange(1, rows)):
@@ -92,8 +121,6 @@
 		else:
 			bean.doclist.append(d)
 
-	
-
 def get_random(doctype, filters=None):
 	condition = []
 	if filters:
@@ -108,7 +135,7 @@
 		order by RAND() limit 0,1""" % (doctype, condition))[0][0]
 
 	return out
-	
+
 def install():
 	print "Creating Fresh Database..."
 	from webnotes.install_lib.install import Installer
@@ -122,57 +149,35 @@
 		"last_name": "User",
 		"fy_start": "1st Jan",
 		"industry": "Manufacturing",
-		"company_name": "Wind Power LLC",
+		"company_name": company,
 		"company_abbr": "WP",
 		"currency": "USD",
 		"timezone": "America/New York",
 		"country": "United States"
 	})
 
-	print "Importing Fiscal Years..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Fiscal_Year.csv")
-	upload()
-
+	import_data("Fiscal_Year")
 	
 def make_items():
-	print "Importing Items..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Item.csv")
-	upload()
-	print "Importing Item Prices..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Item_Price.csv")
-	upload()
+	import_data(["Item", "Item_Price", "BOM"])
 	
 def make_customers_suppliers_contacts():
-	print "Importing Customers..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Customer.csv")
-	upload()
-	print "Importing Suppliers..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Supplier.csv")
-	upload()
-	print "Importing Contacts..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Contact.csv")
-	upload()
-	print "Importing Address..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Address.csv")
-	upload()
-	print "Importing Lead..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Lead.csv")
-	upload()
+	import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
 
 def make_users_and_employees():
-	print "Importing Profile..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Profile.csv")
-	upload()
 	webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
 	webnotes.conn.commit()
 	
-	print "Importing Employee..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Employee.csv")
-	upload()
-
-	print "Importing Salary Structure..."
-	webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", "Salary_Structure.csv")
-	upload()
+	import_data(["Profile", "Employee", "Salary_Structure"])
+	
+def import_data(dt):
+	if not isinstance(dt, (tuple, list)):
+		dt = [dt]
+	
+	for doctype in dt:
+		print "Importing", doctype.replace("_", " "), "..."
+		webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
+		upload()
 
 if __name__=="__main__":
 	make()
\ No newline at end of file