blob: 809a12b6c5c3963a327554f12ef02b7894dbd457 [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2# License: GNU General Public License v3. See license.txt
3
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +05304import webnotes, os, datetime
5import webnotes.utils
Rushabh Mehta622c98d2013-08-22 15:17:58 +05306from webnotes.utils import random_string
Rushabh Mehta0b995402013-08-09 15:29:59 +05307from webnotes.widgets import query_report
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +05308import random
Rushabh Mehta4a404e92013-08-09 18:11:35 +05309import json
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053010
Rushabh Mehtaed186b72013-07-30 16:19:40 +053011webnotes.session = webnotes._dict({"user":"Administrator"})
12from core.page.data_import_tool.data_import_tool import upload
13
Rushabh Mehta0b995402013-08-09 15:29:59 +053014# fix price list
15# fix fiscal year
16
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053017company = "Wind Power LLC"
Rushabh Mehta622c98d2013-08-22 15:17:58 +053018company_abbr = "WP"
Rushabh Mehta20a10942013-08-20 15:18:42 +053019country = "United States"
20currency = "USD"
21time_zone = "America/New York"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053022start_date = '2010-01-01'
Rushabh Mehta622c98d2013-08-22 15:17:58 +053023bank_name = "Citibank"
Rushabh Mehta4a404e92013-08-09 18:11:35 +053024runs_for = 20
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053025prob = {
Rushabh Mehta20a10942013-08-20 15:18:42 +053026 "default": { "make": 0.6, "qty": (1,5) },
27 "Purchase Order": { "make": 0.7, "qty": (1,15) },
28 "Purchase Receipt": { "make": 0.7, "qty": (1,15) },
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053029}
30
Rushabh Mehta4c17f942013-08-12 14:18:09 +053031def make(reset=False):
Rushabh Mehtaed186b72013-07-30 16:19:40 +053032 webnotes.connect()
Rushabh Mehta2b76a5e2013-08-02 15:16:59 +053033 webnotes.print_messages = True
Rushabh Mehtaed186b72013-07-30 16:19:40 +053034 webnotes.mute_emails = True
Rushabh Mehta62030e02013-08-14 18:37:28 +053035 webnotes.rollback_on_exception = True
Rushabh Mehta4a404e92013-08-09 18:11:35 +053036
Rushabh Mehta4c17f942013-08-12 14:18:09 +053037 if reset:
38 setup()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053039 simulate()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053040
41def setup():
Rushabh Mehtaed186b72013-07-30 16:19:40 +053042 install()
43 complete_setup()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053044 make_customers_suppliers_contacts()
Rushabh Mehta4a404e92013-08-09 18:11:35 +053045 make_items()
Rushabh Mehta0b50b482013-08-06 17:53:41 +053046 make_users_and_employees()
Rushabh Mehta622c98d2013-08-22 15:17:58 +053047 make_bank_account()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053048 # make_opening_stock()
49 # make_opening_accounts()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053050
51def simulate():
52 current_date = None
53 for i in xrange(runs_for):
54 if not current_date:
Rushabh Mehta20a10942013-08-20 15:18:42 +053055 # get last stock ledger posting date or use default
56 last_posting = webnotes.conn.sql("""select max(posting_date) from `tabStock Ledger Entry`""")
57 if last_posting[0][0]:
58 current_date = webnotes.utils.add_days(last_posting[0][0], 1)
59 else:
60 current_date = webnotes.utils.getdate(start_date)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053061 else:
62 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta20a10942013-08-20 15:18:42 +053063
64 print current_date.strftime("%Y-%m-%d")
65
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053066 if current_date.weekday() in (5, 6):
67 continue
68
69 run_sales(current_date)
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053070 run_purchase(current_date)
71 run_manufacturing(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053072 run_stock(current_date)
Rushabh Mehta622c98d2013-08-22 15:17:58 +053073 run_accounts(current_date)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053074
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053075def run_sales(current_date):
Rushabh Mehta0b995402013-08-09 15:29:59 +053076 if can_make("Quotation"):
77 for i in xrange(how_many("Quotation")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053078 make_quotation(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053079
80 if can_make("Sales Order"):
81 for i in xrange(how_many("Sales Order")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053082 make_sales_order(current_date)
83
Rushabh Mehta622c98d2013-08-22 15:17:58 +053084def run_accounts(current_date):
85 if can_make("Sales Invoice"):
86 from selling.doctype.sales_order.sales_order import make_sales_invoice
87 report = "Ordered Items to be Billed"
88 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
89 si = webnotes.bean(make_sales_invoice(so))
90 si.doc.posting_date = current_date
91 si.insert()
92 si.submit()
93 webnotes.conn.commit()
94
95 if can_make("Purchase Invoice"):
96 from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
97 report = "Received Items to be Billed"
98 for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
99 pi = webnotes.bean(make_purchase_invoice(pr))
100 pi.doc.posting_date = current_date
101 pi.doc.bill_no = random_string(6)
102 pi.insert()
103 pi.submit()
104 webnotes.conn.commit()
105
106 if can_make("Payment Received"):
107 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
108 report = "Accounts Receivable"
109 for si in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="Sales Invoice"]))[:how_many("Payment Received")]:
110 jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
111 jv.doc.posting_date = current_date
112 jv.doc.cheque_no = random_string(6)
113 jv.doc.cheque_date = current_date
114 jv.insert()
115 jv.submit()
116 webnotes.conn.commit()
117
118 if can_make("Payment Made"):
119 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
120 report = "Accounts Payable"
121 for pi in list(set([r[4] for r in query_report.run(report, {"report_date": current_date })["result"] if r[3]=="Purchase Invoice"]))[:how_many("Payment Made")]:
122 jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
123 jv.doc.posting_date = current_date
124 jv.doc.cheque_no = random_string(6)
125 jv.doc.cheque_date = current_date
126 jv.insert()
127 jv.submit()
128 webnotes.conn.commit()
129
Rushabh Mehta0b995402013-08-09 15:29:59 +0530130def run_stock(current_date):
131 # make purchase requests
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530132 if can_make("Purchase Receipt"):
133 from buying.doctype.purchase_order.purchase_order import make_purchase_receipt
134 report = "Purchase Order Items To Be Received"
135 for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
136 pr = webnotes.bean(make_purchase_receipt(po))
137 pr.doc.posting_date = current_date
138 pr.doc.fiscal_year = "2010"
139 pr.insert()
140 pr.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530141 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530142
Rushabh Mehta0b995402013-08-09 15:29:59 +0530143 # make delivery notes (if possible)
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530144 if can_make("Delivery Note"):
145 from selling.doctype.sales_order.sales_order import make_delivery_note
Rushabh Mehta20a10942013-08-20 15:18:42 +0530146 from stock.stock_ledger import NegativeStockError
147 from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoRequiredError, SerialNoQtyError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530148 report = "Ordered Items To Be Delivered"
149 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]:
150 dn = webnotes.bean(make_delivery_note(so))
151 dn.doc.posting_date = current_date
152 dn.doc.fiscal_year = "2010"
153 dn.insert()
Rushabh Mehta20a10942013-08-20 15:18:42 +0530154 try:
155 dn.submit()
156 webnotes.conn.commit()
157 except NegativeStockError: pass
158 except SerialNoRequiredError: pass
159 except SerialNoQtyError: pass
160
161 # try submitting existing
162 for dn in webnotes.conn.get_values("Delivery Note", {"docstatus": 0}, "name"):
163 b = webnotes.bean("Delivery Note", dn[0])
164 b.submit()
165 webnotes.conn.commit()
166
Rushabh Mehta0b995402013-08-09 15:29:59 +0530167def run_purchase(current_date):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530168 # make material requests for purchase items that have negative projected qtys
169 if can_make("Material Request"):
170 report = "Items To Be Requested"
171 for row in query_report.run(report)["result"][:how_many("Material Request")]:
172 mr = webnotes.new_bean("Material Request")
173 mr.doc.material_request_type = "Purchase"
174 mr.doc.transaction_date = current_date
175 mr.doc.fiscal_year = "2010"
176 mr.doclist.append({
177 "doctype": "Material Request Item",
178 "parentfield": "indent_details",
179 "schedule_date": webnotes.utils.add_days(current_date, 7),
180 "item_code": row[0],
181 "qty": -row[-1]
182 })
183 mr.insert()
184 mr.submit()
185
Rushabh Mehta0b995402013-08-09 15:29:59 +0530186 # make supplier quotations
187 if can_make("Supplier Quotation"):
188 from stock.doctype.material_request.material_request import make_supplier_quotation
189 report = "Material Requests for which Supplier Quotations are not created"
190 for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530191 if row[0] != "Total":
192 sq = webnotes.bean(make_supplier_quotation(row[0]))
193 sq.doc.transaction_date = current_date
194 sq.doc.fiscal_year = "2010"
195 sq.insert()
196 sq.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530197 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530198
199 # make purchase orders
200 if can_make("Purchase Order"):
201 from stock.doctype.material_request.material_request import make_purchase_order
202 report = "Requested Items To Be Ordered"
203 for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530204 if row[0] != "Total":
205 po = webnotes.bean(make_purchase_order(row[0]))
206 po.doc.transaction_date = current_date
207 po.doc.fiscal_year = "2010"
208 po.insert()
209 po.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530210 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530211
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530212def run_manufacturing(current_date):
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530213 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530214 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530215
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530216 ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
217 ppt.doc.company = company
218 ppt.doc.use_multi_level_bom = 1
219 ppt.doc.purchase_request_for_warehouse = "Stores - WP"
220 ppt.run_method("get_open_sales_orders")
221 ppt.run_method("get_items_from_so")
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530222 ppt.run_method("raise_production_order")
223 ppt.run_method("raise_purchase_request")
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530224 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530225
226 # submit production orders
Rushabh Mehta20a10942013-08-20 15:18:42 +0530227 for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}, "name"):
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530228 b = webnotes.bean("Production Order", pro[0])
229 b.doc.wip_warehouse = "Work in Progress - WP"
230 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530231 webnotes.conn.commit()
Rushabh Mehta75c31712013-08-08 16:00:40 +0530232
233 # submit material requests
Rushabh Mehta20a10942013-08-20 15:18:42 +0530234 for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}, "name"):
Rushabh Mehta75c31712013-08-08 16:00:40 +0530235 b = webnotes.bean("Material Request", pro[0])
236 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530237 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530238
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530239 # stores -> wip
240 if can_make("Stock Entry for WIP"):
241 for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
242 make_stock_entry_from_pro(pro[0], "Material Transfer", current_date)
243
244 # wip -> fg
245 if can_make("Stock Entry for FG"):
246 for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
247 make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date)
248
249 # try posting older drafts (if exists)
Rushabh Mehta20a10942013-08-20 15:18:42 +0530250 for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}, "name"):
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530251 try:
252 webnotes.bean("Stock Entry", st[0]).submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530253 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530254 except NegativeStockError: pass
255 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530256 except DuplicateEntryForProductionOrderError: pass
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530257
258def make_stock_entry_from_pro(pro_id, purpose, current_date):
259 from manufacturing.doctype.production_order.production_order import make_stock_entry
260 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530261 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530262
263 st = webnotes.bean(make_stock_entry(pro_id, purpose))
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530264 st.doc.posting_date = current_date
265 st.doc.fiscal_year = "2010"
266 st.doc.expense_adjustment_account = "Stock in Hand - WP"
267 try:
268 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530269 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530270 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530271 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530272 except NegativeStockError: pass
273 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530274 except DuplicateEntryForProductionOrderError: pass
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530275
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530276def make_quotation(current_date):
277 b = webnotes.bean([{
278 "creation": current_date,
279 "doctype": "Quotation",
280 "quotation_to": "Customer",
281 "customer": get_random("Customer"),
282 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530283 "transaction_date": current_date,
284 "fiscal_year": "2010"
285 }])
286
287 add_random_children(b, {
288 "doctype": "Quotation Item",
289 "parentfield": "quotation_details",
290 }, rows=3, randomize = {
291 "qty": (1, 5),
292 "item_code": ("Item", {"is_sales_item": "Yes"})
293 }, unique="item_code")
294
295 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530296 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530297 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530298 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530299
300def make_sales_order(current_date):
301 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530302 if q:
303 from selling.doctype.quotation.quotation import make_sales_order
304 so = webnotes.bean(make_sales_order(q))
305 so.doc.transaction_date = current_date
306 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
307 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530308 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530309 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530310 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530311
312def add_random_children(bean, template, rows, randomize, unique=None):
313 for i in xrange(random.randrange(1, rows)):
314 d = template.copy()
315 for key, val in randomize.items():
316 if isinstance(val[0], basestring):
317 d[key] = get_random(*val)
318 else:
319 d[key] = random.randrange(*val)
320
321 if unique:
322 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
323 bean.doclist.append(d)
324 else:
325 bean.doclist.append(d)
326
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530327def get_random(doctype, filters=None):
328 condition = []
329 if filters:
330 for key, val in filters.items():
331 condition.append("%s='%s'" % (key, val))
332 if condition:
333 condition = " where " + " and ".join(condition)
334 else:
335 condition = ""
336
337 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530338 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530339
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530340 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530341
Rushabh Mehta0b995402013-08-09 15:29:59 +0530342def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530343 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530344
345def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530346 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530347
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530348def install():
349 print "Creating Fresh Database..."
350 from webnotes.install_lib.install import Installer
351 inst = Installer('root')
352 inst.import_from_db("demo", verbose = 1)
353
354def complete_setup():
355 print "Complete Setup..."
356 webnotes.get_obj("Setup Control").setup_account({
357 "first_name": "Test",
358 "last_name": "User",
359 "fy_start": "1st Jan",
360 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530361 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530362 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530363 "currency": currency,
364 "timezone": time_zone,
365 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530366 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530367
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530368 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530369
370def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530371 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530372 import_data("BOM", submit=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530373
374def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530375 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530376
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530377def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530378 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
379 webnotes.conn.commit()
380
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530381 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530382
383def make_bank_account():
384 ba = webnotes.bean({
385 "doctype": "Account",
386 "account_name": bank_name,
387 "account_type": "Bank or Cash",
388 "group_or_ledger": "Ledger",
389 "parent_account": "Bank Accounts - " + company_abbr,
390 "company": company
391 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530392
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530393 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
394
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530395def import_data(dt, submit=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530396 if not isinstance(dt, (tuple, list)):
397 dt = [dt]
398
399 for doctype in dt:
400 print "Importing", doctype.replace("_", " "), "..."
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530401 webnotes.form_dict = {}
402 if submit:
403 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530404 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
405 upload()
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530406
407if __name__=="__main__":
408 make()