blob: 9527b48b37ef50c7e8e4aaff9c1606ad43dfe1f5 [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()
Rushabh Mehta0b50b482013-08-06 17:53:41 +053047 make_users_and_employees()
Rushabh Mehta622c98d2013-08-22 15:17:58 +053048 make_bank_account()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053049 # make_opening_stock()
50 # make_opening_accounts()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053051
Anand Doshi9283b6c2013-09-02 14:58:45 +053052def _simulate():
Rushabh Mehtaacd33672013-08-26 16:17:50 +053053 global runs_for
54 current_date = webnotes.utils.getdate(start_date)
55
56 # continue?
57 last_posting = webnotes.conn.sql("""select max(posting_date) from `tabStock Ledger Entry`""")
58 if last_posting[0][0]:
59 current_date = webnotes.utils.add_days(last_posting[0][0], 1)
60
61 # run till today
62 if not runs_for:
63 runs_for = webnotes.utils.date_diff(webnotes.utils.nowdate(), current_date)
64
65 for i in xrange(runs_for):
Rushabh Mehta20a10942013-08-20 15:18:42 +053066 print current_date.strftime("%Y-%m-%d")
Rushabh Mehtaacd33672013-08-26 16:17:50 +053067 webnotes.utils.current_date = current_date
Rushabh Mehta20a10942013-08-20 15:18:42 +053068
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053069 if current_date.weekday() in (5, 6):
Rushabh Mehtaacd33672013-08-26 16:17:50 +053070 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053071 continue
72
73 run_sales(current_date)
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053074 run_purchase(current_date)
75 run_manufacturing(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053076 run_stock(current_date)
Rushabh Mehta622c98d2013-08-22 15:17:58 +053077 run_accounts(current_date)
Rushabh Mehtaacd33672013-08-26 16:17:50 +053078
79 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053080
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053081def run_sales(current_date):
Rushabh Mehta0b995402013-08-09 15:29:59 +053082 if can_make("Quotation"):
83 for i in xrange(how_many("Quotation")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053084 make_quotation(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053085
86 if can_make("Sales Order"):
87 for i in xrange(how_many("Sales Order")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053088 make_sales_order(current_date)
89
Rushabh Mehta622c98d2013-08-22 15:17:58 +053090def run_accounts(current_date):
91 if can_make("Sales Invoice"):
92 from selling.doctype.sales_order.sales_order import make_sales_invoice
93 report = "Ordered Items to be Billed"
94 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
95 si = webnotes.bean(make_sales_invoice(so))
96 si.doc.posting_date = current_date
97 si.insert()
98 si.submit()
99 webnotes.conn.commit()
100
101 if can_make("Purchase Invoice"):
102 from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
103 report = "Received Items to be Billed"
104 for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
105 pi = webnotes.bean(make_purchase_invoice(pr))
106 pi.doc.posting_date = current_date
107 pi.doc.bill_no = random_string(6)
108 pi.insert()
109 pi.submit()
110 webnotes.conn.commit()
111
112 if can_make("Payment Received"):
113 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
114 report = "Accounts Receivable"
115 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")]:
116 jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
117 jv.doc.posting_date = current_date
118 jv.doc.cheque_no = random_string(6)
119 jv.doc.cheque_date = current_date
120 jv.insert()
121 jv.submit()
122 webnotes.conn.commit()
123
124 if can_make("Payment Made"):
125 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
126 report = "Accounts Payable"
127 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")]:
128 jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
129 jv.doc.posting_date = current_date
130 jv.doc.cheque_no = random_string(6)
131 jv.doc.cheque_date = current_date
132 jv.insert()
133 jv.submit()
134 webnotes.conn.commit()
135
Rushabh Mehta0b995402013-08-09 15:29:59 +0530136def run_stock(current_date):
137 # make purchase requests
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530138 if can_make("Purchase Receipt"):
139 from buying.doctype.purchase_order.purchase_order import make_purchase_receipt
140 report = "Purchase Order Items To Be Received"
141 for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
142 pr = webnotes.bean(make_purchase_receipt(po))
143 pr.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530144 pr.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530145 pr.insert()
146 pr.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530147 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530148
Rushabh Mehta0b995402013-08-09 15:29:59 +0530149 # make delivery notes (if possible)
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530150 if can_make("Delivery Note"):
151 from selling.doctype.sales_order.sales_order import make_delivery_note
Rushabh Mehta20a10942013-08-20 15:18:42 +0530152 from stock.stock_ledger import NegativeStockError
153 from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoRequiredError, SerialNoQtyError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530154 report = "Ordered Items To Be Delivered"
155 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]:
156 dn = webnotes.bean(make_delivery_note(so))
157 dn.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530158 dn.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530159 dn.insert()
Rushabh Mehta20a10942013-08-20 15:18:42 +0530160 try:
161 dn.submit()
162 webnotes.conn.commit()
163 except NegativeStockError: pass
164 except SerialNoRequiredError: pass
165 except SerialNoQtyError: pass
166
167 # try submitting existing
168 for dn in webnotes.conn.get_values("Delivery Note", {"docstatus": 0}, "name"):
169 b = webnotes.bean("Delivery Note", dn[0])
170 b.submit()
171 webnotes.conn.commit()
172
Rushabh Mehta0b995402013-08-09 15:29:59 +0530173def run_purchase(current_date):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530174 # make material requests for purchase items that have negative projected qtys
175 if can_make("Material Request"):
176 report = "Items To Be Requested"
177 for row in query_report.run(report)["result"][:how_many("Material Request")]:
178 mr = webnotes.new_bean("Material Request")
179 mr.doc.material_request_type = "Purchase"
180 mr.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530181 mr.doc.fiscal_year = "2013"
Rushabh Mehta20a10942013-08-20 15:18:42 +0530182 mr.doclist.append({
183 "doctype": "Material Request Item",
184 "parentfield": "indent_details",
185 "schedule_date": webnotes.utils.add_days(current_date, 7),
186 "item_code": row[0],
187 "qty": -row[-1]
188 })
189 mr.insert()
190 mr.submit()
191
Rushabh Mehta0b995402013-08-09 15:29:59 +0530192 # make supplier quotations
193 if can_make("Supplier Quotation"):
194 from stock.doctype.material_request.material_request import make_supplier_quotation
195 report = "Material Requests for which Supplier Quotations are not created"
196 for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530197 if row[0] != "Total":
198 sq = webnotes.bean(make_supplier_quotation(row[0]))
199 sq.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530200 sq.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530201 sq.insert()
202 sq.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530203 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530204
205 # make purchase orders
206 if can_make("Purchase Order"):
207 from stock.doctype.material_request.material_request import make_purchase_order
208 report = "Requested Items To Be Ordered"
209 for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530210 if row[0] != "Total":
211 po = webnotes.bean(make_purchase_order(row[0]))
212 po.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530213 po.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530214 po.insert()
215 po.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530216 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530217
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530218def run_manufacturing(current_date):
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530219 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530220 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530221
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530222 ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
223 ppt.doc.company = company
224 ppt.doc.use_multi_level_bom = 1
225 ppt.doc.purchase_request_for_warehouse = "Stores - WP"
226 ppt.run_method("get_open_sales_orders")
227 ppt.run_method("get_items_from_so")
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530228 ppt.run_method("raise_production_order")
229 ppt.run_method("raise_purchase_request")
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530230 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530231
232 # submit production orders
Rushabh Mehta20a10942013-08-20 15:18:42 +0530233 for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}, "name"):
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530234 b = webnotes.bean("Production Order", pro[0])
235 b.doc.wip_warehouse = "Work in Progress - WP"
236 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530237 webnotes.conn.commit()
Rushabh Mehta75c31712013-08-08 16:00:40 +0530238
239 # submit material requests
Rushabh Mehta20a10942013-08-20 15:18:42 +0530240 for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}, "name"):
Rushabh Mehta75c31712013-08-08 16:00:40 +0530241 b = webnotes.bean("Material Request", pro[0])
242 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530243 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530244
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530245 # stores -> wip
246 if can_make("Stock Entry for WIP"):
247 for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
248 make_stock_entry_from_pro(pro[0], "Material Transfer", current_date)
249
250 # wip -> fg
251 if can_make("Stock Entry for FG"):
252 for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
253 make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date)
254
255 # try posting older drafts (if exists)
Rushabh Mehta20a10942013-08-20 15:18:42 +0530256 for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}, "name"):
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530257 try:
258 webnotes.bean("Stock Entry", st[0]).submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530259 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530260 except NegativeStockError: pass
261 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530262 except DuplicateEntryForProductionOrderError: pass
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530263
264def make_stock_entry_from_pro(pro_id, purpose, current_date):
265 from manufacturing.doctype.production_order.production_order import make_stock_entry
266 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530267 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530268
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530269 try:
Anand Doshic753d312013-08-26 17:33:50 +0530270 st = webnotes.bean(make_stock_entry(pro_id, purpose))
271 st.doc.posting_date = current_date
272 st.doc.fiscal_year = "2013"
Nabin Hait142007a2013-09-17 15:15:16 +0530273 for d in st.doclist.get({"parentfield": "mtn_details"}):
274 d.expense_account = "Stock Adjustment - " + company_abbr
275 d.cost_center = "Main - " + company_abbr
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530276 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530277 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530278 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530279 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530280 except NegativeStockError: pass
281 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530282 except DuplicateEntryForProductionOrderError: pass
Anand Doshic753d312013-08-26 17:33:50 +0530283
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530284def make_quotation(current_date):
285 b = webnotes.bean([{
286 "creation": current_date,
287 "doctype": "Quotation",
288 "quotation_to": "Customer",
289 "customer": get_random("Customer"),
290 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530291 "transaction_date": current_date,
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530292 "fiscal_year": "2013"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530293 }])
294
295 add_random_children(b, {
296 "doctype": "Quotation Item",
297 "parentfield": "quotation_details",
298 }, rows=3, randomize = {
299 "qty": (1, 5),
300 "item_code": ("Item", {"is_sales_item": "Yes"})
301 }, unique="item_code")
302
303 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530304 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530305 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530306 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530307
308def make_sales_order(current_date):
309 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530310 if q:
311 from selling.doctype.quotation.quotation import make_sales_order
312 so = webnotes.bean(make_sales_order(q))
313 so.doc.transaction_date = current_date
314 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
315 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530316 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530317 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530318 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530319
320def add_random_children(bean, template, rows, randomize, unique=None):
321 for i in xrange(random.randrange(1, rows)):
322 d = template.copy()
323 for key, val in randomize.items():
324 if isinstance(val[0], basestring):
325 d[key] = get_random(*val)
326 else:
327 d[key] = random.randrange(*val)
328
329 if unique:
330 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
331 bean.doclist.append(d)
332 else:
333 bean.doclist.append(d)
334
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530335def get_random(doctype, filters=None):
336 condition = []
337 if filters:
338 for key, val in filters.items():
339 condition.append("%s='%s'" % (key, val))
340 if condition:
341 condition = " where " + " and ".join(condition)
342 else:
343 condition = ""
344
345 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530346 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530347
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530348 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530349
Rushabh Mehta0b995402013-08-09 15:29:59 +0530350def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530351 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530352
353def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530354 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530355
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530356def install():
357 print "Creating Fresh Database..."
358 from webnotes.install_lib.install import Installer
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530359 import conf
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530360 inst = Installer('root')
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530361 inst.import_from_db(conf.demo_db_name, verbose = 1)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530362
363def complete_setup():
364 print "Complete Setup..."
365 webnotes.get_obj("Setup Control").setup_account({
366 "first_name": "Test",
367 "last_name": "User",
368 "fy_start": "1st Jan",
369 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530370 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530371 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530372 "currency": currency,
373 "timezone": time_zone,
374 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530375 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530376
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530377 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530378
379def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530380 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530381 import_data("BOM", submit=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530382
383def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530384 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530385
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530386def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530387 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
388 webnotes.conn.commit()
389
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530390 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530391
392def make_bank_account():
393 ba = webnotes.bean({
394 "doctype": "Account",
395 "account_name": bank_name,
396 "account_type": "Bank or Cash",
397 "group_or_ledger": "Ledger",
398 "parent_account": "Bank Accounts - " + company_abbr,
399 "company": company
400 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530401
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530402 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530403 webnotes.conn.commit()
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530404
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530405def import_data(dt, submit=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530406 if not isinstance(dt, (tuple, list)):
407 dt = [dt]
408
409 for doctype in dt:
410 print "Importing", doctype.replace("_", " "), "..."
Anand Doshicb4c0ea2013-08-27 15:39:31 +0530411 webnotes.form_dict = webnotes._dict()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530412 if submit:
413 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530414 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
Anand Doshi9283b6c2013-09-02 14:58:45 +0530415 upload()