blob: 2d2d07e0eaac8c7206171710f031876e9af85c57 [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()
Anand Doshide8b6aa2013-09-24 17:17:39 +053039 else:
40 webnotes.connect()
41
Rushabh Mehtae499a482013-09-01 11:14:32 +053042 if simulate:
Anand Doshi9283b6c2013-09-02 14:58:45 +053043 _simulate()
Anand Doshide8b6aa2013-09-24 17:17:39 +053044
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053045def setup():
Rushabh Mehtaed186b72013-07-30 16:19:40 +053046 install()
Anand Doshide8b6aa2013-09-24 17:17:39 +053047 webnotes.connect()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053048 complete_setup()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053049 make_customers_suppliers_contacts()
Rushabh Mehta4a404e92013-08-09 18:11:35 +053050 make_items()
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +053051 make_price_lists()
Rushabh Mehta0b50b482013-08-06 17:53:41 +053052 make_users_and_employees()
Rushabh Mehta622c98d2013-08-22 15:17:58 +053053 make_bank_account()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053054 # make_opening_stock()
55 # make_opening_accounts()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053056
Anand Doshi9283b6c2013-09-02 14:58:45 +053057def _simulate():
Rushabh Mehtaacd33672013-08-26 16:17:50 +053058 global runs_for
59 current_date = webnotes.utils.getdate(start_date)
60
61 # continue?
62 last_posting = webnotes.conn.sql("""select max(posting_date) from `tabStock Ledger Entry`""")
63 if last_posting[0][0]:
64 current_date = webnotes.utils.add_days(last_posting[0][0], 1)
65
66 # run till today
67 if not runs_for:
68 runs_for = webnotes.utils.date_diff(webnotes.utils.nowdate(), current_date)
69
70 for i in xrange(runs_for):
Rushabh Mehta20a10942013-08-20 15:18:42 +053071 print current_date.strftime("%Y-%m-%d")
Rushabh Mehtaacd33672013-08-26 16:17:50 +053072 webnotes.utils.current_date = current_date
Rushabh Mehta20a10942013-08-20 15:18:42 +053073
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053074 if current_date.weekday() in (5, 6):
Rushabh Mehtaacd33672013-08-26 16:17:50 +053075 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053076 continue
77
78 run_sales(current_date)
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053079 run_purchase(current_date)
80 run_manufacturing(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053081 run_stock(current_date)
Rushabh Mehta622c98d2013-08-22 15:17:58 +053082 run_accounts(current_date)
Rushabh Mehtaacd33672013-08-26 16:17:50 +053083
84 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053085
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053086def run_sales(current_date):
Rushabh Mehta0b995402013-08-09 15:29:59 +053087 if can_make("Quotation"):
88 for i in xrange(how_many("Quotation")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053089 make_quotation(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053090
91 if can_make("Sales Order"):
92 for i in xrange(how_many("Sales Order")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053093 make_sales_order(current_date)
94
Rushabh Mehta622c98d2013-08-22 15:17:58 +053095def run_accounts(current_date):
96 if can_make("Sales Invoice"):
97 from selling.doctype.sales_order.sales_order import make_sales_invoice
98 report = "Ordered Items to be Billed"
99 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
100 si = webnotes.bean(make_sales_invoice(so))
101 si.doc.posting_date = current_date
102 si.insert()
103 si.submit()
104 webnotes.conn.commit()
105
106 if can_make("Purchase Invoice"):
107 from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
108 report = "Received Items to be Billed"
109 for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
110 pi = webnotes.bean(make_purchase_invoice(pr))
111 pi.doc.posting_date = current_date
112 pi.doc.bill_no = random_string(6)
113 pi.insert()
114 pi.submit()
115 webnotes.conn.commit()
116
117 if can_make("Payment Received"):
118 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
119 report = "Accounts Receivable"
120 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")]:
121 jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
122 jv.doc.posting_date = current_date
123 jv.doc.cheque_no = random_string(6)
124 jv.doc.cheque_date = current_date
125 jv.insert()
126 jv.submit()
127 webnotes.conn.commit()
128
129 if can_make("Payment Made"):
130 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
131 report = "Accounts Payable"
132 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")]:
133 jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
134 jv.doc.posting_date = current_date
135 jv.doc.cheque_no = random_string(6)
136 jv.doc.cheque_date = current_date
137 jv.insert()
138 jv.submit()
139 webnotes.conn.commit()
140
Rushabh Mehta0b995402013-08-09 15:29:59 +0530141def run_stock(current_date):
142 # make purchase requests
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530143 if can_make("Purchase Receipt"):
144 from buying.doctype.purchase_order.purchase_order import make_purchase_receipt
145 report = "Purchase Order Items To Be Received"
146 for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
147 pr = webnotes.bean(make_purchase_receipt(po))
148 pr.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530149 pr.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530150 pr.insert()
151 pr.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530152 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530153
Rushabh Mehta0b995402013-08-09 15:29:59 +0530154 # make delivery notes (if possible)
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530155 if can_make("Delivery Note"):
156 from selling.doctype.sales_order.sales_order import make_delivery_note
Rushabh Mehta20a10942013-08-20 15:18:42 +0530157 from stock.stock_ledger import NegativeStockError
158 from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoRequiredError, SerialNoQtyError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530159 report = "Ordered Items To Be Delivered"
160 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]:
161 dn = webnotes.bean(make_delivery_note(so))
162 dn.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530163 dn.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530164 dn.insert()
Rushabh Mehta20a10942013-08-20 15:18:42 +0530165 try:
166 dn.submit()
167 webnotes.conn.commit()
168 except NegativeStockError: pass
169 except SerialNoRequiredError: pass
170 except SerialNoQtyError: pass
171
172 # try submitting existing
173 for dn in webnotes.conn.get_values("Delivery Note", {"docstatus": 0}, "name"):
174 b = webnotes.bean("Delivery Note", dn[0])
175 b.submit()
176 webnotes.conn.commit()
177
Rushabh Mehta0b995402013-08-09 15:29:59 +0530178def run_purchase(current_date):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530179 # make material requests for purchase items that have negative projected qtys
180 if can_make("Material Request"):
181 report = "Items To Be Requested"
182 for row in query_report.run(report)["result"][:how_many("Material Request")]:
183 mr = webnotes.new_bean("Material Request")
184 mr.doc.material_request_type = "Purchase"
185 mr.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530186 mr.doc.fiscal_year = "2013"
Rushabh Mehta20a10942013-08-20 15:18:42 +0530187 mr.doclist.append({
188 "doctype": "Material Request Item",
189 "parentfield": "indent_details",
190 "schedule_date": webnotes.utils.add_days(current_date, 7),
191 "item_code": row[0],
192 "qty": -row[-1]
193 })
194 mr.insert()
195 mr.submit()
196
Rushabh Mehta0b995402013-08-09 15:29:59 +0530197 # make supplier quotations
198 if can_make("Supplier Quotation"):
199 from stock.doctype.material_request.material_request import make_supplier_quotation
200 report = "Material Requests for which Supplier Quotations are not created"
201 for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530202 if row[0] != "Total":
203 sq = webnotes.bean(make_supplier_quotation(row[0]))
204 sq.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530205 sq.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530206 sq.insert()
207 sq.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530208 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530209
210 # make purchase orders
211 if can_make("Purchase Order"):
212 from stock.doctype.material_request.material_request import make_purchase_order
213 report = "Requested Items To Be Ordered"
214 for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530215 if row[0] != "Total":
216 po = webnotes.bean(make_purchase_order(row[0]))
217 po.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530218 po.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530219 po.insert()
220 po.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530221 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530222
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530223def run_manufacturing(current_date):
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530224 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530225 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530226
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530227 ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
228 ppt.doc.company = company
229 ppt.doc.use_multi_level_bom = 1
230 ppt.doc.purchase_request_for_warehouse = "Stores - WP"
231 ppt.run_method("get_open_sales_orders")
232 ppt.run_method("get_items_from_so")
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530233 ppt.run_method("raise_production_order")
234 ppt.run_method("raise_purchase_request")
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530235 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530236
237 # submit production orders
Rushabh Mehta20a10942013-08-20 15:18:42 +0530238 for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}, "name"):
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530239 b = webnotes.bean("Production Order", pro[0])
240 b.doc.wip_warehouse = "Work in Progress - WP"
241 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530242 webnotes.conn.commit()
Rushabh Mehta75c31712013-08-08 16:00:40 +0530243
244 # submit material requests
Rushabh Mehta20a10942013-08-20 15:18:42 +0530245 for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}, "name"):
Rushabh Mehta75c31712013-08-08 16:00:40 +0530246 b = webnotes.bean("Material Request", pro[0])
247 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530248 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530249
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530250 # stores -> wip
251 if can_make("Stock Entry for WIP"):
252 for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
253 make_stock_entry_from_pro(pro[0], "Material Transfer", current_date)
254
255 # wip -> fg
256 if can_make("Stock Entry for FG"):
257 for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
258 make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date)
259
260 # try posting older drafts (if exists)
Rushabh Mehta20a10942013-08-20 15:18:42 +0530261 for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}, "name"):
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530262 try:
263 webnotes.bean("Stock Entry", st[0]).submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530264 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530265 except NegativeStockError: pass
266 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530267 except DuplicateEntryForProductionOrderError: pass
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530268
269def make_stock_entry_from_pro(pro_id, purpose, current_date):
270 from manufacturing.doctype.production_order.production_order import make_stock_entry
271 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530272 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530273
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530274 try:
Anand Doshic753d312013-08-26 17:33:50 +0530275 st = webnotes.bean(make_stock_entry(pro_id, purpose))
276 st.doc.posting_date = current_date
277 st.doc.fiscal_year = "2013"
Nabin Hait142007a2013-09-17 15:15:16 +0530278 for d in st.doclist.get({"parentfield": "mtn_details"}):
279 d.expense_account = "Stock Adjustment - " + company_abbr
280 d.cost_center = "Main - " + company_abbr
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530281 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530282 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530283 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530284 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530285 except NegativeStockError: pass
286 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530287 except DuplicateEntryForProductionOrderError: pass
Anand Doshic753d312013-08-26 17:33:50 +0530288
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530289def make_quotation(current_date):
290 b = webnotes.bean([{
291 "creation": current_date,
292 "doctype": "Quotation",
293 "quotation_to": "Customer",
294 "customer": get_random("Customer"),
295 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530296 "transaction_date": current_date,
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530297 "fiscal_year": "2013"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530298 }])
299
300 add_random_children(b, {
301 "doctype": "Quotation Item",
302 "parentfield": "quotation_details",
303 }, rows=3, randomize = {
304 "qty": (1, 5),
305 "item_code": ("Item", {"is_sales_item": "Yes"})
306 }, unique="item_code")
307
308 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530309 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530310 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530311 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530312
313def make_sales_order(current_date):
314 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530315 if q:
316 from selling.doctype.quotation.quotation import make_sales_order
317 so = webnotes.bean(make_sales_order(q))
318 so.doc.transaction_date = current_date
319 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
320 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530321 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530322 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530323 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530324
325def add_random_children(bean, template, rows, randomize, unique=None):
326 for i in xrange(random.randrange(1, rows)):
327 d = template.copy()
328 for key, val in randomize.items():
329 if isinstance(val[0], basestring):
330 d[key] = get_random(*val)
331 else:
332 d[key] = random.randrange(*val)
333
334 if unique:
335 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
336 bean.doclist.append(d)
337 else:
338 bean.doclist.append(d)
339
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530340def get_random(doctype, filters=None):
341 condition = []
342 if filters:
343 for key, val in filters.items():
344 condition.append("%s='%s'" % (key, val))
345 if condition:
346 condition = " where " + " and ".join(condition)
347 else:
348 condition = ""
349
350 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530351 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530352
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530353 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530354
Rushabh Mehta0b995402013-08-09 15:29:59 +0530355def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530356 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530357
358def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530359 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530360
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530361def install():
362 print "Creating Fresh Database..."
363 from webnotes.install_lib.install import Installer
Pratik Vyascfed8c42013-09-21 15:16:47 +0530364 from webnotes import conf
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530365 inst = Installer('root')
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530366 inst.import_from_db(conf.demo_db_name, verbose = 1)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530367
368def complete_setup():
369 print "Complete Setup..."
370 webnotes.get_obj("Setup Control").setup_account({
371 "first_name": "Test",
372 "last_name": "User",
373 "fy_start": "1st Jan",
374 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530375 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530376 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530377 "currency": currency,
378 "timezone": time_zone,
379 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530380 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530381
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530382 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530383
384def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530385 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530386 import_data("BOM", submit=True)
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +0530387
388def make_price_lists():
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530389 import_data("Price_List", overwrite=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530390
391def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530392 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530393
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530394def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530395 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
396 webnotes.conn.commit()
397
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530398 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530399
400def make_bank_account():
401 ba = webnotes.bean({
402 "doctype": "Account",
403 "account_name": bank_name,
404 "account_type": "Bank or Cash",
405 "group_or_ledger": "Ledger",
406 "parent_account": "Bank Accounts - " + company_abbr,
407 "company": company
408 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530409
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530410 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530411 webnotes.conn.commit()
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530412
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530413def import_data(dt, submit=False, overwrite=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530414 if not isinstance(dt, (tuple, list)):
415 dt = [dt]
416
417 for doctype in dt:
418 print "Importing", doctype.replace("_", " "), "..."
Anand Doshicb4c0ea2013-08-27 15:39:31 +0530419 webnotes.form_dict = webnotes._dict()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530420 if submit:
421 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530422 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
Pratik Vyascfed8c42013-09-21 15:16:47 +0530423 upload(overwrite=overwrite)