blob: 883186791a9541d9f500e63d25f14abc55256017 [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 Mehtaacd33672013-08-26 16:17:50 +053022start_date = '2013-01-01'
Rushabh Mehta622c98d2013-08-22 15:17:58 +053023bank_name = "Citibank"
Rushabh Mehtaacd33672013-08-26 16:17:50 +053024runs_for = None
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053025prob = {
Rushabh Mehta20a10942013-08-20 15:18:42 +053026 "default": { "make": 0.6, "qty": (1,5) },
Rushabh Mehta16a62fa2013-08-23 13:16:22 +053027 "Sales Order": { "make": 0.4, "qty": (1,3) },
Rushabh Mehta20a10942013-08-20 15:18:42 +053028 "Purchase Order": { "make": 0.7, "qty": (1,15) },
29 "Purchase Receipt": { "make": 0.7, "qty": (1,15) },
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053030}
31
Rushabh Mehtae499a482013-09-01 11:14:32 +053032def make(reset=False, simulate=True):
Rushabh Mehta16a62fa2013-08-23 13:16:22 +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 Mehtae499a482013-09-01 11:14:32 +053039 if simulate:
Anand Doshi9283b6c2013-09-02 14:58:45 +053040 _simulate()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053041
42def setup():
Rushabh Mehtaed186b72013-07-30 16:19:40 +053043 install()
44 complete_setup()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053045 make_customers_suppliers_contacts()
Rushabh Mehta4a404e92013-08-09 18:11:35 +053046 make_items()
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +053047 make_price_lists()
Rushabh Mehta0b50b482013-08-06 17:53:41 +053048 make_users_and_employees()
Rushabh Mehta622c98d2013-08-22 15:17:58 +053049 make_bank_account()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053050 # make_opening_stock()
51 # make_opening_accounts()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053052
Anand Doshi9283b6c2013-09-02 14:58:45 +053053def _simulate():
Rushabh Mehtaacd33672013-08-26 16:17:50 +053054 global runs_for
55 current_date = webnotes.utils.getdate(start_date)
56
57 # continue?
58 last_posting = webnotes.conn.sql("""select max(posting_date) from `tabStock Ledger Entry`""")
59 if last_posting[0][0]:
60 current_date = webnotes.utils.add_days(last_posting[0][0], 1)
61
62 # run till today
63 if not runs_for:
64 runs_for = webnotes.utils.date_diff(webnotes.utils.nowdate(), current_date)
65
66 for i in xrange(runs_for):
Rushabh Mehta20a10942013-08-20 15:18:42 +053067 print current_date.strftime("%Y-%m-%d")
Rushabh Mehtaacd33672013-08-26 16:17:50 +053068 webnotes.utils.current_date = current_date
Rushabh Mehta20a10942013-08-20 15:18:42 +053069
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053070 if current_date.weekday() in (5, 6):
Rushabh Mehtaacd33672013-08-26 16:17:50 +053071 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053072 continue
73
74 run_sales(current_date)
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053075 run_purchase(current_date)
76 run_manufacturing(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053077 run_stock(current_date)
Rushabh Mehta622c98d2013-08-22 15:17:58 +053078 run_accounts(current_date)
Rushabh Mehtaacd33672013-08-26 16:17:50 +053079
80 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053081
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053082def run_sales(current_date):
Rushabh Mehta0b995402013-08-09 15:29:59 +053083 if can_make("Quotation"):
84 for i in xrange(how_many("Quotation")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053085 make_quotation(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053086
87 if can_make("Sales Order"):
88 for i in xrange(how_many("Sales Order")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053089 make_sales_order(current_date)
90
Rushabh Mehta622c98d2013-08-22 15:17:58 +053091def run_accounts(current_date):
92 if can_make("Sales Invoice"):
93 from selling.doctype.sales_order.sales_order import make_sales_invoice
94 report = "Ordered Items to be Billed"
95 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
96 si = webnotes.bean(make_sales_invoice(so))
97 si.doc.posting_date = current_date
98 si.insert()
99 si.submit()
100 webnotes.conn.commit()
101
102 if can_make("Purchase Invoice"):
103 from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
104 report = "Received Items to be Billed"
105 for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
106 pi = webnotes.bean(make_purchase_invoice(pr))
107 pi.doc.posting_date = current_date
108 pi.doc.bill_no = random_string(6)
109 pi.insert()
110 pi.submit()
111 webnotes.conn.commit()
112
113 if can_make("Payment Received"):
114 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
115 report = "Accounts Receivable"
116 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")]:
117 jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
118 jv.doc.posting_date = current_date
119 jv.doc.cheque_no = random_string(6)
120 jv.doc.cheque_date = current_date
121 jv.insert()
122 jv.submit()
123 webnotes.conn.commit()
124
125 if can_make("Payment Made"):
126 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
127 report = "Accounts Payable"
128 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")]:
129 jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
130 jv.doc.posting_date = current_date
131 jv.doc.cheque_no = random_string(6)
132 jv.doc.cheque_date = current_date
133 jv.insert()
134 jv.submit()
135 webnotes.conn.commit()
136
Rushabh Mehta0b995402013-08-09 15:29:59 +0530137def run_stock(current_date):
138 # make purchase requests
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530139 if can_make("Purchase Receipt"):
140 from buying.doctype.purchase_order.purchase_order import make_purchase_receipt
141 report = "Purchase Order Items To Be Received"
142 for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
143 pr = webnotes.bean(make_purchase_receipt(po))
144 pr.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530145 pr.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530146 pr.insert()
147 pr.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530148 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530149
Rushabh Mehta0b995402013-08-09 15:29:59 +0530150 # make delivery notes (if possible)
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530151 if can_make("Delivery Note"):
152 from selling.doctype.sales_order.sales_order import make_delivery_note
Rushabh Mehta20a10942013-08-20 15:18:42 +0530153 from stock.stock_ledger import NegativeStockError
154 from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoRequiredError, SerialNoQtyError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530155 report = "Ordered Items To Be Delivered"
156 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]:
157 dn = webnotes.bean(make_delivery_note(so))
158 dn.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530159 dn.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530160 dn.insert()
Rushabh Mehta20a10942013-08-20 15:18:42 +0530161 try:
162 dn.submit()
163 webnotes.conn.commit()
164 except NegativeStockError: pass
165 except SerialNoRequiredError: pass
166 except SerialNoQtyError: pass
167
168 # try submitting existing
169 for dn in webnotes.conn.get_values("Delivery Note", {"docstatus": 0}, "name"):
170 b = webnotes.bean("Delivery Note", dn[0])
171 b.submit()
172 webnotes.conn.commit()
173
Rushabh Mehta0b995402013-08-09 15:29:59 +0530174def run_purchase(current_date):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530175 # make material requests for purchase items that have negative projected qtys
176 if can_make("Material Request"):
177 report = "Items To Be Requested"
178 for row in query_report.run(report)["result"][:how_many("Material Request")]:
179 mr = webnotes.new_bean("Material Request")
180 mr.doc.material_request_type = "Purchase"
181 mr.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530182 mr.doc.fiscal_year = "2013"
Rushabh Mehta20a10942013-08-20 15:18:42 +0530183 mr.doclist.append({
184 "doctype": "Material Request Item",
185 "parentfield": "indent_details",
186 "schedule_date": webnotes.utils.add_days(current_date, 7),
187 "item_code": row[0],
188 "qty": -row[-1]
189 })
190 mr.insert()
191 mr.submit()
192
Rushabh Mehta0b995402013-08-09 15:29:59 +0530193 # make supplier quotations
194 if can_make("Supplier Quotation"):
195 from stock.doctype.material_request.material_request import make_supplier_quotation
196 report = "Material Requests for which Supplier Quotations are not created"
197 for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530198 if row[0] != "Total":
199 sq = webnotes.bean(make_supplier_quotation(row[0]))
200 sq.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530201 sq.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530202 sq.insert()
203 sq.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530204 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530205
206 # make purchase orders
207 if can_make("Purchase Order"):
208 from stock.doctype.material_request.material_request import make_purchase_order
209 report = "Requested Items To Be Ordered"
210 for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530211 if row[0] != "Total":
212 po = webnotes.bean(make_purchase_order(row[0]))
213 po.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530214 po.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530215 po.insert()
216 po.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530217 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530218
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530219def run_manufacturing(current_date):
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530220 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530221 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530222
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530223 ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
224 ppt.doc.company = company
225 ppt.doc.use_multi_level_bom = 1
226 ppt.doc.purchase_request_for_warehouse = "Stores - WP"
227 ppt.run_method("get_open_sales_orders")
228 ppt.run_method("get_items_from_so")
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530229 ppt.run_method("raise_production_order")
230 ppt.run_method("raise_purchase_request")
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530231 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530232
233 # submit production orders
Rushabh Mehta20a10942013-08-20 15:18:42 +0530234 for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}, "name"):
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530235 b = webnotes.bean("Production Order", pro[0])
236 b.doc.wip_warehouse = "Work in Progress - WP"
237 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530238 webnotes.conn.commit()
Rushabh Mehta75c31712013-08-08 16:00:40 +0530239
240 # submit material requests
Rushabh Mehta20a10942013-08-20 15:18:42 +0530241 for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}, "name"):
Rushabh Mehta75c31712013-08-08 16:00:40 +0530242 b = webnotes.bean("Material Request", pro[0])
243 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530244 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530245
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530246 # stores -> wip
247 if can_make("Stock Entry for WIP"):
248 for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
249 make_stock_entry_from_pro(pro[0], "Material Transfer", current_date)
250
251 # wip -> fg
252 if can_make("Stock Entry for FG"):
253 for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
254 make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date)
255
256 # try posting older drafts (if exists)
Rushabh Mehta20a10942013-08-20 15:18:42 +0530257 for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}, "name"):
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530258 try:
259 webnotes.bean("Stock Entry", st[0]).submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530260 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530261 except NegativeStockError: pass
262 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530263 except DuplicateEntryForProductionOrderError: pass
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530264
265def make_stock_entry_from_pro(pro_id, purpose, current_date):
266 from manufacturing.doctype.production_order.production_order import make_stock_entry
267 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530268 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530269
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530270 try:
Anand Doshic753d312013-08-26 17:33:50 +0530271 st = webnotes.bean(make_stock_entry(pro_id, purpose))
272 st.doc.posting_date = current_date
273 st.doc.fiscal_year = "2013"
274 st.doc.expense_adjustment_account = "Stock in Hand - WP"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530275 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530276 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530277 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530278 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530279 except NegativeStockError: pass
280 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530281 except DuplicateEntryForProductionOrderError: pass
Anand Doshic753d312013-08-26 17:33:50 +0530282
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530283def make_quotation(current_date):
284 b = webnotes.bean([{
285 "creation": current_date,
286 "doctype": "Quotation",
287 "quotation_to": "Customer",
288 "customer": get_random("Customer"),
289 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530290 "transaction_date": current_date,
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530291 "fiscal_year": "2013"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530292 }])
293
294 add_random_children(b, {
295 "doctype": "Quotation Item",
296 "parentfield": "quotation_details",
297 }, rows=3, randomize = {
298 "qty": (1, 5),
299 "item_code": ("Item", {"is_sales_item": "Yes"})
300 }, unique="item_code")
301
302 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530303 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530304 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530305 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530306
307def make_sales_order(current_date):
308 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530309 if q:
310 from selling.doctype.quotation.quotation import make_sales_order
311 so = webnotes.bean(make_sales_order(q))
312 so.doc.transaction_date = current_date
313 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
314 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530315 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530316 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530317 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530318
319def add_random_children(bean, template, rows, randomize, unique=None):
320 for i in xrange(random.randrange(1, rows)):
321 d = template.copy()
322 for key, val in randomize.items():
323 if isinstance(val[0], basestring):
324 d[key] = get_random(*val)
325 else:
326 d[key] = random.randrange(*val)
327
328 if unique:
329 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
330 bean.doclist.append(d)
331 else:
332 bean.doclist.append(d)
333
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530334def get_random(doctype, filters=None):
335 condition = []
336 if filters:
337 for key, val in filters.items():
338 condition.append("%s='%s'" % (key, val))
339 if condition:
340 condition = " where " + " and ".join(condition)
341 else:
342 condition = ""
343
344 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530345 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530346
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530347 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530348
Rushabh Mehta0b995402013-08-09 15:29:59 +0530349def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530350 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530351
352def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530353 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530354
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530355def install():
356 print "Creating Fresh Database..."
357 from webnotes.install_lib.install import Installer
Pratik Vyascfed8c42013-09-21 15:16:47 +0530358 from webnotes import conf
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530359 inst = Installer('root')
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530360 inst.import_from_db(conf.demo_db_name, verbose = 1)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530361
362def complete_setup():
363 print "Complete Setup..."
364 webnotes.get_obj("Setup Control").setup_account({
365 "first_name": "Test",
366 "last_name": "User",
367 "fy_start": "1st Jan",
368 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530369 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530370 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530371 "currency": currency,
372 "timezone": time_zone,
373 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530374 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530375
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530376 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530377
378def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530379 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530380 import_data("BOM", submit=True)
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +0530381
382def make_price_lists():
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530383 import_data("Price_List", overwrite=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530384
385def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530386 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530387
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530388def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530389 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
390 webnotes.conn.commit()
391
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530392 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530393
394def make_bank_account():
395 ba = webnotes.bean({
396 "doctype": "Account",
397 "account_name": bank_name,
398 "account_type": "Bank or Cash",
399 "group_or_ledger": "Ledger",
400 "parent_account": "Bank Accounts - " + company_abbr,
401 "company": company
402 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530403
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530404 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530405 webnotes.conn.commit()
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530406
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530407def import_data(dt, submit=False, overwrite=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530408 if not isinstance(dt, (tuple, list)):
409 dt = [dt]
410
411 for doctype in dt:
412 print "Importing", doctype.replace("_", " "), "..."
Anand Doshicb4c0ea2013-08-27 15:39:31 +0530413 webnotes.form_dict = webnotes._dict()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530414 if submit:
415 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530416 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
Pratik Vyascfed8c42013-09-21 15:16:47 +0530417 upload(overwrite=overwrite)