blob: 4f30df62be3340087d7b5241cc3065dcfb50ae9c [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
Anand Doshif879a9d2013-09-26 15:56:54 +053037 if not webnotes.conf.demo_db_name:
38 raise Exception("conf.py does not have demo_db_name")
39
Rushabh Mehta4c17f942013-08-12 14:18:09 +053040 if reset:
41 setup()
Anand Doshide8b6aa2013-09-24 17:17:39 +053042 else:
Anand Doshi8db093b2013-09-27 14:08:55 +053043 webnotes.conn.close()
Anand Doshif879a9d2013-09-26 15:56:54 +053044 webnotes.connect(db_name=webnotes.conf.demo_db_name)
Anand Doshide8b6aa2013-09-24 17:17:39 +053045
Rushabh Mehtae499a482013-09-01 11:14:32 +053046 if simulate:
Anand Doshi9283b6c2013-09-02 14:58:45 +053047 _simulate()
Anand Doshide8b6aa2013-09-24 17:17:39 +053048
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053049def setup():
Rushabh Mehtaed186b72013-07-30 16:19:40 +053050 install()
Anand Doshif879a9d2013-09-26 15:56:54 +053051 webnotes.connect(db_name=webnotes.conf.demo_db_name)
Rushabh Mehtaed186b72013-07-30 16:19:40 +053052 complete_setup()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053053 make_customers_suppliers_contacts()
Rushabh Mehta4a404e92013-08-09 18:11:35 +053054 make_items()
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +053055 make_price_lists()
Rushabh Mehta0b50b482013-08-06 17:53:41 +053056 make_users_and_employees()
Rushabh Mehta622c98d2013-08-22 15:17:58 +053057 make_bank_account()
Rushabh Mehtaed186b72013-07-30 16:19:40 +053058 # make_opening_stock()
59 # make_opening_accounts()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053060
Anand Doshi9283b6c2013-09-02 14:58:45 +053061def _simulate():
Rushabh Mehtaacd33672013-08-26 16:17:50 +053062 global runs_for
63 current_date = webnotes.utils.getdate(start_date)
64
65 # continue?
66 last_posting = webnotes.conn.sql("""select max(posting_date) from `tabStock Ledger Entry`""")
67 if last_posting[0][0]:
68 current_date = webnotes.utils.add_days(last_posting[0][0], 1)
69
70 # run till today
71 if not runs_for:
72 runs_for = webnotes.utils.date_diff(webnotes.utils.nowdate(), current_date)
73
74 for i in xrange(runs_for):
Rushabh Mehta20a10942013-08-20 15:18:42 +053075 print current_date.strftime("%Y-%m-%d")
Rushabh Mehtaacd33672013-08-26 16:17:50 +053076 webnotes.utils.current_date = current_date
Rushabh Mehta20a10942013-08-20 15:18:42 +053077
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053078 if current_date.weekday() in (5, 6):
Rushabh Mehtaacd33672013-08-26 16:17:50 +053079 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053080 continue
81
82 run_sales(current_date)
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053083 run_purchase(current_date)
84 run_manufacturing(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053085 run_stock(current_date)
Rushabh Mehta622c98d2013-08-22 15:17:58 +053086 run_accounts(current_date)
Rushabh Mehtaacd33672013-08-26 16:17:50 +053087
88 current_date = webnotes.utils.add_days(current_date, 1)
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053089
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +053090def run_sales(current_date):
Rushabh Mehta0b995402013-08-09 15:29:59 +053091 if can_make("Quotation"):
92 for i in xrange(how_many("Quotation")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053093 make_quotation(current_date)
Rushabh Mehta0b995402013-08-09 15:29:59 +053094
95 if can_make("Sales Order"):
96 for i in xrange(how_many("Sales Order")):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +053097 make_sales_order(current_date)
98
Rushabh Mehta622c98d2013-08-22 15:17:58 +053099def run_accounts(current_date):
100 if can_make("Sales Invoice"):
101 from selling.doctype.sales_order.sales_order import make_sales_invoice
102 report = "Ordered Items to be Billed"
103 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Sales Invoice")]:
104 si = webnotes.bean(make_sales_invoice(so))
105 si.doc.posting_date = current_date
106 si.insert()
107 si.submit()
108 webnotes.conn.commit()
109
110 if can_make("Purchase Invoice"):
111 from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
112 report = "Received Items to be Billed"
113 for pr in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Invoice")]:
114 pi = webnotes.bean(make_purchase_invoice(pr))
115 pi.doc.posting_date = current_date
116 pi.doc.bill_no = random_string(6)
117 pi.insert()
118 pi.submit()
119 webnotes.conn.commit()
120
121 if can_make("Payment Received"):
122 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_sales_invoice
123 report = "Accounts Receivable"
124 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")]:
125 jv = webnotes.bean(get_payment_entry_from_sales_invoice(si))
126 jv.doc.posting_date = current_date
127 jv.doc.cheque_no = random_string(6)
128 jv.doc.cheque_date = current_date
129 jv.insert()
130 jv.submit()
131 webnotes.conn.commit()
132
133 if can_make("Payment Made"):
134 from accounts.doctype.journal_voucher.journal_voucher import get_payment_entry_from_purchase_invoice
135 report = "Accounts Payable"
136 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")]:
137 jv = webnotes.bean(get_payment_entry_from_purchase_invoice(pi))
138 jv.doc.posting_date = current_date
139 jv.doc.cheque_no = random_string(6)
140 jv.doc.cheque_date = current_date
141 jv.insert()
142 jv.submit()
143 webnotes.conn.commit()
144
Rushabh Mehta0b995402013-08-09 15:29:59 +0530145def run_stock(current_date):
146 # make purchase requests
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530147 if can_make("Purchase Receipt"):
148 from buying.doctype.purchase_order.purchase_order import make_purchase_receipt
Anand Doshif879a9d2013-09-26 15:56:54 +0530149 from stock.stock_ledger import NegativeStockError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530150 report = "Purchase Order Items To Be Received"
151 for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]:
152 pr = webnotes.bean(make_purchase_receipt(po))
153 pr.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530154 pr.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530155 pr.insert()
Anand Doshif879a9d2013-09-26 15:56:54 +0530156 try:
157 pr.submit()
158 webnotes.conn.commit()
159 except NegativeStockError: pass
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530160
Rushabh Mehta0b995402013-08-09 15:29:59 +0530161 # make delivery notes (if possible)
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530162 if can_make("Delivery Note"):
163 from selling.doctype.sales_order.sales_order import make_delivery_note
Rushabh Mehta20a10942013-08-20 15:18:42 +0530164 from stock.stock_ledger import NegativeStockError
165 from stock.doctype.stock_ledger_entry.stock_ledger_entry import SerialNoRequiredError, SerialNoQtyError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530166 report = "Ordered Items To Be Delivered"
167 for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]:
168 dn = webnotes.bean(make_delivery_note(so))
169 dn.doc.posting_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530170 dn.doc.fiscal_year = "2013"
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530171 dn.insert()
Rushabh Mehta20a10942013-08-20 15:18:42 +0530172 try:
173 dn.submit()
174 webnotes.conn.commit()
175 except NegativeStockError: pass
176 except SerialNoRequiredError: pass
177 except SerialNoQtyError: pass
178
179 # try submitting existing
180 for dn in webnotes.conn.get_values("Delivery Note", {"docstatus": 0}, "name"):
181 b = webnotes.bean("Delivery Note", dn[0])
182 b.submit()
183 webnotes.conn.commit()
184
Rushabh Mehta0b995402013-08-09 15:29:59 +0530185def run_purchase(current_date):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530186 # make material requests for purchase items that have negative projected qtys
187 if can_make("Material Request"):
188 report = "Items To Be Requested"
189 for row in query_report.run(report)["result"][:how_many("Material Request")]:
190 mr = webnotes.new_bean("Material Request")
191 mr.doc.material_request_type = "Purchase"
192 mr.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530193 mr.doc.fiscal_year = "2013"
Rushabh Mehta20a10942013-08-20 15:18:42 +0530194 mr.doclist.append({
195 "doctype": "Material Request Item",
196 "parentfield": "indent_details",
197 "schedule_date": webnotes.utils.add_days(current_date, 7),
198 "item_code": row[0],
199 "qty": -row[-1]
200 })
201 mr.insert()
202 mr.submit()
203
Rushabh Mehta0b995402013-08-09 15:29:59 +0530204 # make supplier quotations
205 if can_make("Supplier Quotation"):
206 from stock.doctype.material_request.material_request import make_supplier_quotation
207 report = "Material Requests for which Supplier Quotations are not created"
208 for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530209 if row[0] != "Total":
210 sq = webnotes.bean(make_supplier_quotation(row[0]))
211 sq.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530212 sq.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530213 sq.insert()
214 sq.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530215 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530216
217 # make purchase orders
218 if can_make("Purchase Order"):
219 from stock.doctype.material_request.material_request import make_purchase_order
220 report = "Requested Items To Be Ordered"
221 for row in query_report.run(report)["result"][:how_many("Purchase Order")]:
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530222 if row[0] != "Total":
223 po = webnotes.bean(make_purchase_order(row[0]))
224 po.doc.transaction_date = current_date
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530225 po.doc.fiscal_year = "2013"
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530226 po.insert()
227 po.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530228 webnotes.conn.commit()
Rushabh Mehta0b995402013-08-09 15:29:59 +0530229
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530230def run_manufacturing(current_date):
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530231 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530232 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530233
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530234 ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
235 ppt.doc.company = company
236 ppt.doc.use_multi_level_bom = 1
237 ppt.doc.purchase_request_for_warehouse = "Stores - WP"
238 ppt.run_method("get_open_sales_orders")
239 ppt.run_method("get_items_from_so")
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530240 ppt.run_method("raise_production_order")
241 ppt.run_method("raise_purchase_request")
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530242 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530243
244 # submit production orders
Rushabh Mehta20a10942013-08-20 15:18:42 +0530245 for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}, "name"):
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530246 b = webnotes.bean("Production Order", pro[0])
247 b.doc.wip_warehouse = "Work in Progress - WP"
248 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530249 webnotes.conn.commit()
Rushabh Mehta75c31712013-08-08 16:00:40 +0530250
251 # submit material requests
Rushabh Mehta20a10942013-08-20 15:18:42 +0530252 for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}, "name"):
Rushabh Mehta75c31712013-08-08 16:00:40 +0530253 b = webnotes.bean("Material Request", pro[0])
254 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530255 webnotes.conn.commit()
Rushabh Mehta2c968ce2013-08-08 14:16:39 +0530256
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530257 # stores -> wip
258 if can_make("Stock Entry for WIP"):
259 for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]:
260 make_stock_entry_from_pro(pro[0], "Material Transfer", current_date)
261
262 # wip -> fg
263 if can_make("Stock Entry for FG"):
264 for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]:
265 make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date)
266
267 # try posting older drafts (if exists)
Rushabh Mehta20a10942013-08-20 15:18:42 +0530268 for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}, "name"):
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530269 try:
270 webnotes.bean("Stock Entry", st[0]).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
276def make_stock_entry_from_pro(pro_id, purpose, current_date):
277 from manufacturing.doctype.production_order.production_order import make_stock_entry
278 from stock.stock_ledger import NegativeStockError
Rushabh Mehta20a10942013-08-20 15:18:42 +0530279 from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError, DuplicateEntryForProductionOrderError
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530280
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530281 try:
Anand Doshic753d312013-08-26 17:33:50 +0530282 st = webnotes.bean(make_stock_entry(pro_id, purpose))
283 st.doc.posting_date = current_date
284 st.doc.fiscal_year = "2013"
Nabin Hait142007a2013-09-17 15:15:16 +0530285 for d in st.doclist.get({"parentfield": "mtn_details"}):
286 d.expense_account = "Stock Adjustment - " + company_abbr
287 d.cost_center = "Main - " + company_abbr
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530288 st.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530289 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530290 st.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530291 webnotes.conn.commit()
Rushabh Mehta4c17f942013-08-12 14:18:09 +0530292 except NegativeStockError: pass
293 except IncorrectValuationRateError: pass
Rushabh Mehta20a10942013-08-20 15:18:42 +0530294 except DuplicateEntryForProductionOrderError: pass
Anand Doshic753d312013-08-26 17:33:50 +0530295
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530296def make_quotation(current_date):
297 b = webnotes.bean([{
298 "creation": current_date,
299 "doctype": "Quotation",
300 "quotation_to": "Customer",
301 "customer": get_random("Customer"),
302 "order_type": "Sales",
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530303 "transaction_date": current_date,
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530304 "fiscal_year": "2013"
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530305 }])
306
307 add_random_children(b, {
308 "doctype": "Quotation Item",
309 "parentfield": "quotation_details",
310 }, rows=3, randomize = {
311 "qty": (1, 5),
312 "item_code": ("Item", {"is_sales_item": "Yes"})
313 }, unique="item_code")
314
315 b.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530316 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530317 b.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530318 webnotes.conn.commit()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530319
320def make_sales_order(current_date):
321 q = get_random("Quotation", {"status": "Submitted"})
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530322 if q:
323 from selling.doctype.quotation.quotation import make_sales_order
324 so = webnotes.bean(make_sales_order(q))
325 so.doc.transaction_date = current_date
326 so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
327 so.insert()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530328 webnotes.conn.commit()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530329 so.submit()
Rushabh Mehta6ca903f2013-08-13 14:31:15 +0530330 webnotes.conn.commit()
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530331
332def add_random_children(bean, template, rows, randomize, unique=None):
333 for i in xrange(random.randrange(1, rows)):
334 d = template.copy()
335 for key, val in randomize.items():
336 if isinstance(val[0], basestring):
337 d[key] = get_random(*val)
338 else:
339 d[key] = random.randrange(*val)
340
341 if unique:
342 if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
343 bean.doclist.append(d)
344 else:
345 bean.doclist.append(d)
346
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530347def get_random(doctype, filters=None):
348 condition = []
349 if filters:
350 for key, val in filters.items():
351 condition.append("%s='%s'" % (key, val))
352 if condition:
353 condition = " where " + " and ".join(condition)
354 else:
355 condition = ""
356
357 out = webnotes.conn.sql("""select name from `tab%s` %s
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530358 order by RAND() limit 0,1""" % (doctype, condition))
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530359
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530360 return out and out[0][0] or None
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530361
Rushabh Mehta0b995402013-08-09 15:29:59 +0530362def can_make(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530363 return random.random() < prob.get(doctype, prob["default"])["make"]
Rushabh Mehta0b995402013-08-09 15:29:59 +0530364
365def how_many(doctype):
Rushabh Mehta20a10942013-08-20 15:18:42 +0530366 return random.randrange(*prob.get(doctype, prob["default"])["qty"])
Rushabh Mehta0b995402013-08-09 15:29:59 +0530367
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530368def install():
369 print "Creating Fresh Database..."
370 from webnotes.install_lib.install import Installer
Pratik Vyascfed8c42013-09-21 15:16:47 +0530371 from webnotes import conf
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530372 inst = Installer('root')
Anand Doshif879a9d2013-09-26 15:56:54 +0530373 inst.install(conf.demo_db_name, verbose=1, force=1)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530374
375def complete_setup():
376 print "Complete Setup..."
377 webnotes.get_obj("Setup Control").setup_account({
378 "first_name": "Test",
379 "last_name": "User",
380 "fy_start": "1st Jan",
381 "industry": "Manufacturing",
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530382 "company_name": company,
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530383 "company_abbr": company_abbr,
Rushabh Mehta20a10942013-08-20 15:18:42 +0530384 "currency": currency,
385 "timezone": time_zone,
386 "country": country
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530387 })
Rushabh Mehta7c2a2e22013-08-07 15:08:11 +0530388
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530389 import_data("Fiscal_Year")
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530390
391def make_items():
Rushabh Mehta20a10942013-08-20 15:18:42 +0530392 import_data("Item")
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530393 import_data("BOM", submit=True)
Akhilesh Darjeec96c13a2013-09-12 19:19:46 +0530394
395def make_price_lists():
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530396 import_data("Price_List", overwrite=True)
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530397
398def make_customers_suppliers_contacts():
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530399 import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
Rushabh Mehtaed186b72013-07-30 16:19:40 +0530400
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530401def make_users_and_employees():
Rushabh Mehta0b50b482013-08-06 17:53:41 +0530402 webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
403 webnotes.conn.commit()
404
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530405 import_data(["Profile", "Employee", "Salary_Structure"])
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530406
407def make_bank_account():
408 ba = webnotes.bean({
409 "doctype": "Account",
410 "account_name": bank_name,
411 "account_type": "Bank or Cash",
412 "group_or_ledger": "Ledger",
413 "parent_account": "Bank Accounts - " + company_abbr,
414 "company": company
415 }).insert()
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530416
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530417 webnotes.set_value("Company", company, "default_bank_account", ba.doc.name)
Rushabh Mehtaacd33672013-08-26 16:17:50 +0530418 webnotes.conn.commit()
Rushabh Mehta622c98d2013-08-22 15:17:58 +0530419
Akhilesh Darjee2e1f94f2013-09-13 17:37:23 +0530420def import_data(dt, submit=False, overwrite=False):
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530421 if not isinstance(dt, (tuple, list)):
422 dt = [dt]
423
424 for doctype in dt:
425 print "Importing", doctype.replace("_", " "), "..."
Anand Doshicb4c0ea2013-08-27 15:39:31 +0530426 webnotes.form_dict = webnotes._dict()
Rushabh Mehta4a404e92013-08-09 18:11:35 +0530427 if submit:
428 webnotes.form_dict["params"] = json.dumps({"_submit": 1})
Rushabh Mehta7cfefbc2013-08-07 17:46:35 +0530429 webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
Pratik Vyascfed8c42013-09-21 15:16:47 +0530430 upload(overwrite=overwrite)