blob: 3d7d6487d4ee097bcf0896bf762ce9748d6b305a [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 Mehta4c17f942013-08-12 14:18:09 +053032def make(reset=False):
Rushabh Mehtaed186b72013-07-30 16:19:40 +053033 webnotes.connect()
Rushabh Mehta16a62fa2013-08-23 13:16:22 +053034 #webnotes.print_messages = True
Rushabh Mehtaed186b72013-07-30 16:19:40 +053035 webnotes.mute_emails = True
Rushabh Mehta62030e02013-08-14 18:37:28 +053036 webnotes.rollback_on_exception = True
Rushabh Mehta4a404e92013-08-09 18:11:35 +053037
Rushabh Mehta4c17f942013-08-12 14:18:09 +053038 if reset:
39 setup()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +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
52def 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"
273 st.doc.expense_adjustment_account = "Stock in Hand - WP"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530274 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530275 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530276 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530277 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530278 except NegativeStockError: pass
279 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530280 except DuplicateEntryForProductionOrderError: pass
Anand Doshic753d312013-08-26 17:33:50 +0530281
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530282def make_quotation(current_date):
283 b = webnotes.bean([{
284 "creation": current_date,
285 "doctype": "Quotation",
286 "quotation_to": "Customer",
287 "customer": get_random("Customer"),
288 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530289 "transaction_date": current_date,
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530290 "fiscal_year": "2013"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530291 }])
292
293 add_random_children(b, {
294 "doctype": "Quotation Item",
295 "parentfield": "quotation_details",
296 }, rows=3, randomize = {
297 "qty": (1, 5),
298 "item_code": ("Item", {"is_sales_item": "Yes"})
299 }, unique="item_code")
300
301 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530302 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530303 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530304 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530305
306def make_sales_order(current_date):
307 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530308 if q:
309 from selling.doctype.quotation.quotation import make_sales_order
310 so = webnotes.bean(make_sales_order(q))
311 so.doc.transaction_date = current_date
312 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
313 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530314 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530315 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530316 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530317
318def add_random_children(bean, template, rows, randomize, unique=None):
319 for i in xrange(random.randrange(1, rows)):
320 d = template.copy()
321 for key, val in randomize.items():
322 if isinstance(val[0], basestring):
323 d[key] = get_random(*val)
324 else:
325 d[key] = random.randrange(*val)
326
327 if unique:
328 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
329 bean.doclist.append(d)
330 else:
331 bean.doclist.append(d)
332
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530333def get_random(doctype, filters=None):
334 condition = []
335 if filters:
336 for key, val in filters.items():
337 condition.append("%s='%s'" % (key, val))
338 if condition:
339 condition = " where " + " and ".join(condition)
340 else:
341 condition = ""
342
343 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530344 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530345
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530346 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530347
Rushabh Mehta0b995402013-08-09 15:29:59 +0530348def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530349 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530350
351def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530352 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530353
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530354def install():
355 print "Creating Fresh Database..."
356 from webnotes.install_lib.install import Installer
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530357 import conf
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530358 inst = Installer('root')
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530359 inst.import_from_db(conf.demo_db_name, verbose = 1)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530360
361def complete_setup():
362 print "Complete Setup..."
363 webnotes.get_obj("Setup Control").setup_account({
364 "first_name": "Test",
365 "last_name": "User",
366 "fy_start": "1st Jan",
367 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530368 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530369 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530370 "currency": currency,
371 "timezone": time_zone,
372 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530373 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530374
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530375 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530376
377def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530378 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530379 import_data("BOM", submit=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530380
381def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530382 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530383
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530384def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530385 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
386 webnotes.conn.commit()
387
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530388 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530389
390def make_bank_account():
391 ba = webnotes.bean({
392 "doctype": "Account",
393 "account_name": bank_name,
394 "account_type": "Bank or Cash",
395 "group_or_ledger": "Ledger",
396 "parent_account": "Bank Accounts - " + company_abbr,
397 "company": company
398 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530399
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530400 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530401 webnotes.conn.commit()
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530402
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530403def import_data(dt, submit=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530404 if not isinstance(dt, (tuple, list)):
405 dt = [dt]
406
407 for doctype in dt:
408 print "Importing", doctype.replace("_", " "), "..."
Anand Doshicb4c0ea2013-08-27 15:39:31 +0530409 webnotes.form_dict = webnotes._dict()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530410 if submit:
411 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530412 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
413 upload()
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530414
415if __name__=="__main__":
416 make()