2013-08-05 09:29:54 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2013-08-07 09:38:11 +00:00
|
|
|
import webnotes, os, datetime
|
|
|
|
import webnotes.utils
|
|
|
|
import random
|
|
|
|
|
2013-07-30 10:49:40 +00:00
|
|
|
webnotes.session = webnotes._dict({"user":"Administrator"})
|
|
|
|
from core.page.data_import_tool.data_import_tool import upload
|
|
|
|
|
2013-08-07 12:16:35 +00:00
|
|
|
company = "Wind Power LLC"
|
2013-08-07 09:38:11 +00:00
|
|
|
start_date = '2010-01-01'
|
|
|
|
runs_for = 100
|
|
|
|
prob = {
|
2013-08-07 12:16:35 +00:00
|
|
|
"Quotation": { "make": 0.5, "qty": (1,3) },
|
|
|
|
"Sales Order": { "make": 0.5, "qty": (1,2) }
|
2013-08-07 09:38:11 +00:00
|
|
|
}
|
|
|
|
|
2013-07-30 10:49:40 +00:00
|
|
|
def make():
|
|
|
|
webnotes.connect()
|
2013-08-02 09:46:59 +00:00
|
|
|
webnotes.print_messages = True
|
2013-07-30 10:49:40 +00:00
|
|
|
webnotes.mute_emails = True
|
2013-08-07 09:38:11 +00:00
|
|
|
|
|
|
|
# setup()
|
2013-08-07 12:16:35 +00:00
|
|
|
simulate()
|
2013-08-07 09:38:11 +00:00
|
|
|
|
|
|
|
def setup():
|
2013-07-30 10:49:40 +00:00
|
|
|
install()
|
|
|
|
complete_setup()
|
|
|
|
make_items()
|
|
|
|
make_customers_suppliers_contacts()
|
2013-08-06 12:23:41 +00:00
|
|
|
make_users_and_employees()
|
2013-07-30 10:49:40 +00:00
|
|
|
# make_opening_stock()
|
|
|
|
# make_opening_accounts()
|
2013-08-07 09:38:11 +00:00
|
|
|
|
|
|
|
def simulate():
|
|
|
|
current_date = None
|
|
|
|
for i in xrange(runs_for):
|
2013-08-07 12:16:35 +00:00
|
|
|
print i
|
2013-08-07 09:38:11 +00:00
|
|
|
if not current_date:
|
|
|
|
current_date = webnotes.utils.getdate(start_date)
|
|
|
|
else:
|
|
|
|
current_date = webnotes.utils.add_days(current_date, 1)
|
|
|
|
|
|
|
|
if current_date.weekday() in (5, 6):
|
|
|
|
continue
|
|
|
|
|
|
|
|
run_sales(current_date)
|
2013-08-07 12:16:35 +00:00
|
|
|
run_purchase(current_date)
|
|
|
|
run_manufacturing(current_date)
|
2013-08-07 09:38:11 +00:00
|
|
|
|
2013-08-07 12:16:35 +00:00
|
|
|
webnotes.conn.commit()
|
2013-08-07 09:38:11 +00:00
|
|
|
|
|
|
|
def run_sales(current_date):
|
2013-08-07 12:16:35 +00:00
|
|
|
if random.random() < prob["Quotation"]["make"]:
|
|
|
|
for i in xrange(random.randrange(*prob["Quotation"]["qty"])):
|
|
|
|
make_quotation(current_date)
|
|
|
|
|
|
|
|
if random.random() < prob["Sales Order"]["make"]:
|
|
|
|
for i in xrange(random.randrange(*prob["Sales Order"]["qty"])):
|
|
|
|
make_sales_order(current_date)
|
|
|
|
|
|
|
|
def run_purchase(current_date):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def run_manufacturing(current_date):
|
|
|
|
ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool")
|
|
|
|
ppt.doc.company = company
|
|
|
|
ppt.doc.use_multi_level_bom = 1
|
|
|
|
ppt.doc.purchase_request_for_warehouse = "Stores - WP"
|
|
|
|
ppt.run_method("get_open_sales_orders")
|
|
|
|
ppt.run_method("get_items_from_so")
|
|
|
|
ppt.run_method("get_items_from_so")
|
|
|
|
ppt.run_method("raise_production_order")
|
|
|
|
ppt.run_method("raise_purchase_request")
|
|
|
|
|
2013-08-07 09:38:11 +00:00
|
|
|
def make_quotation(current_date):
|
|
|
|
b = webnotes.bean([{
|
|
|
|
"creation": current_date,
|
|
|
|
"doctype": "Quotation",
|
|
|
|
"quotation_to": "Customer",
|
|
|
|
"customer": get_random("Customer"),
|
|
|
|
"order_type": "Sales",
|
|
|
|
"price_list_name": "Standard Selling",
|
|
|
|
"transaction_date": current_date,
|
|
|
|
"fiscal_year": "2010"
|
|
|
|
}])
|
|
|
|
|
|
|
|
add_random_children(b, {
|
|
|
|
"doctype": "Quotation Item",
|
|
|
|
"parentfield": "quotation_details",
|
|
|
|
}, rows=3, randomize = {
|
|
|
|
"qty": (1, 5),
|
|
|
|
"item_code": ("Item", {"is_sales_item": "Yes"})
|
|
|
|
}, unique="item_code")
|
|
|
|
|
|
|
|
b.insert()
|
2013-08-07 12:16:35 +00:00
|
|
|
b.submit()
|
|
|
|
|
|
|
|
def make_sales_order(current_date):
|
|
|
|
q = get_random("Quotation", {"status": "Submitted"})
|
|
|
|
from selling.doctype.quotation.quotation import make_sales_order
|
|
|
|
so = webnotes.bean(make_sales_order(q))
|
|
|
|
so.doc.transaction_date = current_date
|
|
|
|
so.doc.delivery_date = webnotes.utils.add_days(current_date, 10)
|
|
|
|
so.insert()
|
|
|
|
so.submit()
|
2013-08-07 09:38:11 +00:00
|
|
|
|
|
|
|
def add_random_children(bean, template, rows, randomize, unique=None):
|
|
|
|
for i in xrange(random.randrange(1, rows)):
|
|
|
|
d = template.copy()
|
|
|
|
for key, val in randomize.items():
|
|
|
|
if isinstance(val[0], basestring):
|
|
|
|
d[key] = get_random(*val)
|
|
|
|
else:
|
|
|
|
d[key] = random.randrange(*val)
|
|
|
|
|
|
|
|
if unique:
|
|
|
|
if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}):
|
|
|
|
bean.doclist.append(d)
|
|
|
|
else:
|
|
|
|
bean.doclist.append(d)
|
|
|
|
|
|
|
|
def get_random(doctype, filters=None):
|
|
|
|
condition = []
|
|
|
|
if filters:
|
|
|
|
for key, val in filters.items():
|
|
|
|
condition.append("%s='%s'" % (key, val))
|
|
|
|
if condition:
|
|
|
|
condition = " where " + " and ".join(condition)
|
|
|
|
else:
|
|
|
|
condition = ""
|
|
|
|
|
|
|
|
out = webnotes.conn.sql("""select name from `tab%s` %s
|
|
|
|
order by RAND() limit 0,1""" % (doctype, condition))[0][0]
|
|
|
|
|
|
|
|
return out
|
2013-08-07 12:16:35 +00:00
|
|
|
|
2013-07-30 10:49:40 +00:00
|
|
|
def install():
|
|
|
|
print "Creating Fresh Database..."
|
|
|
|
from webnotes.install_lib.install import Installer
|
|
|
|
inst = Installer('root')
|
|
|
|
inst.import_from_db("demo", verbose = 1)
|
|
|
|
|
|
|
|
def complete_setup():
|
|
|
|
print "Complete Setup..."
|
|
|
|
webnotes.get_obj("Setup Control").setup_account({
|
|
|
|
"first_name": "Test",
|
|
|
|
"last_name": "User",
|
|
|
|
"fy_start": "1st Jan",
|
|
|
|
"industry": "Manufacturing",
|
2013-08-07 12:16:35 +00:00
|
|
|
"company_name": company,
|
2013-07-30 10:49:40 +00:00
|
|
|
"company_abbr": "WP",
|
2013-08-06 12:23:41 +00:00
|
|
|
"currency": "USD",
|
2013-07-30 10:49:40 +00:00
|
|
|
"timezone": "America/New York",
|
|
|
|
"country": "United States"
|
|
|
|
})
|
2013-08-07 09:38:11 +00:00
|
|
|
|
2013-08-07 12:16:35 +00:00
|
|
|
import_data("Fiscal_Year")
|
2013-07-30 10:49:40 +00:00
|
|
|
|
|
|
|
def make_items():
|
2013-08-07 12:16:35 +00:00
|
|
|
import_data(["Item", "Item_Price", "BOM"])
|
2013-07-30 10:49:40 +00:00
|
|
|
|
|
|
|
def make_customers_suppliers_contacts():
|
2013-08-07 12:16:35 +00:00
|
|
|
import_data(["Customer", "Supplier", "Contact", "Address", "Lead"])
|
2013-07-30 10:49:40 +00:00
|
|
|
|
2013-08-06 12:23:41 +00:00
|
|
|
def make_users_and_employees():
|
|
|
|
webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series")
|
|
|
|
webnotes.conn.commit()
|
|
|
|
|
2013-08-07 12:16:35 +00:00
|
|
|
import_data(["Profile", "Employee", "Salary_Structure"])
|
|
|
|
|
|
|
|
def import_data(dt):
|
|
|
|
if not isinstance(dt, (tuple, list)):
|
|
|
|
dt = [dt]
|
|
|
|
|
|
|
|
for doctype in dt:
|
|
|
|
print "Importing", doctype.replace("_", " "), "..."
|
|
|
|
webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv")
|
|
|
|
upload()
|
2013-07-30 10:49:40 +00:00
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
|
|
make()
|