Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 4 | import webnotes, os, datetime |
| 5 | import webnotes.utils |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 6 | from webnotes.widgets import query_report |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 7 | import random |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 8 | import json |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 9 | |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 10 | webnotes.session = webnotes._dict({"user":"Administrator"}) |
| 11 | from core.page.data_import_tool.data_import_tool import upload |
| 12 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 13 | # fix price list |
| 14 | # fix fiscal year |
| 15 | |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 16 | company = "Wind Power LLC" |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 17 | start_date = '2010-01-01' |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 18 | runs_for = 20 |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 19 | prob = { |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 20 | "Quotation": { "make": 0.5, "qty": (1,5) }, |
| 21 | "Sales Order": { "make": 0.5, "qty": (1,4) }, |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 22 | "Purchase Order": { "make": 0.7, "qty": (1,4) }, |
| 23 | "Purchase Receipt": { "make": 0.7, "qty": (1,4) }, |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 24 | "Supplier Quotation": { "make": 0.5, "qty": (1, 3) } |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 25 | } |
| 26 | |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 27 | def make(reset=False): |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 28 | webnotes.connect() |
Rushabh Mehta | 2b76a5e | 2013-08-02 15:16:59 +0530 | [diff] [blame] | 29 | webnotes.print_messages = True |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 30 | webnotes.mute_emails = True |
Rushabh Mehta | 62030e0 | 2013-08-14 18:37:28 +0530 | [diff] [blame] | 31 | webnotes.rollback_on_exception = True |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 32 | |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 33 | if reset: |
| 34 | setup() |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 35 | simulate() |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 36 | |
| 37 | def setup(): |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 38 | install() |
| 39 | complete_setup() |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 40 | make_customers_suppliers_contacts() |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 41 | make_items() |
Rushabh Mehta | 0b50b48 | 2013-08-06 17:53:41 +0530 | [diff] [blame] | 42 | make_users_and_employees() |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 43 | # make_opening_stock() |
| 44 | # make_opening_accounts() |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 45 | |
| 46 | def simulate(): |
| 47 | current_date = None |
| 48 | for i in xrange(runs_for): |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 49 | print i |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 50 | if not current_date: |
| 51 | current_date = webnotes.utils.getdate(start_date) |
| 52 | else: |
| 53 | current_date = webnotes.utils.add_days(current_date, 1) |
| 54 | |
| 55 | if current_date.weekday() in (5, 6): |
| 56 | continue |
| 57 | |
| 58 | run_sales(current_date) |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 59 | run_purchase(current_date) |
| 60 | run_manufacturing(current_date) |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 61 | run_stock(current_date) |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 62 | |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 63 | def run_sales(current_date): |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 64 | if can_make("Quotation"): |
| 65 | for i in xrange(how_many("Quotation")): |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 66 | make_quotation(current_date) |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 67 | |
| 68 | if can_make("Sales Order"): |
| 69 | for i in xrange(how_many("Sales Order")): |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 70 | make_sales_order(current_date) |
| 71 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 72 | def run_stock(current_date): |
| 73 | # make purchase requests |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 74 | if can_make("Purchase Receipt"): |
| 75 | from buying.doctype.purchase_order.purchase_order import make_purchase_receipt |
| 76 | report = "Purchase Order Items To Be Received" |
| 77 | for po in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Purchase Receipt")]: |
| 78 | pr = webnotes.bean(make_purchase_receipt(po)) |
| 79 | pr.doc.posting_date = current_date |
| 80 | pr.doc.fiscal_year = "2010" |
| 81 | pr.insert() |
| 82 | pr.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 83 | webnotes.conn.commit() |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 84 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 85 | # make delivery notes (if possible) |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 86 | if can_make("Delivery Note"): |
| 87 | from selling.doctype.sales_order.sales_order import make_delivery_note |
| 88 | report = "Ordered Items To Be Delivered" |
| 89 | for so in list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:how_many("Delivery Note")]: |
| 90 | dn = webnotes.bean(make_delivery_note(so)) |
| 91 | dn.doc.posting_date = current_date |
| 92 | dn.doc.fiscal_year = "2010" |
| 93 | dn.insert() |
| 94 | dn.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 95 | webnotes.conn.commit() |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 96 | |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 97 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 98 | def run_purchase(current_date): |
| 99 | # make supplier quotations |
| 100 | if can_make("Supplier Quotation"): |
| 101 | from stock.doctype.material_request.material_request import make_supplier_quotation |
| 102 | report = "Material Requests for which Supplier Quotations are not created" |
| 103 | for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]: |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 104 | if row[0] != "Total": |
| 105 | sq = webnotes.bean(make_supplier_quotation(row[0])) |
| 106 | sq.doc.transaction_date = current_date |
| 107 | sq.doc.fiscal_year = "2010" |
| 108 | sq.insert() |
| 109 | sq.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 110 | webnotes.conn.commit() |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 111 | |
| 112 | # make purchase orders |
| 113 | if can_make("Purchase Order"): |
| 114 | from stock.doctype.material_request.material_request import make_purchase_order |
| 115 | report = "Requested Items To Be Ordered" |
| 116 | for row in query_report.run(report)["result"][:how_many("Purchase Order")]: |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 117 | if row[0] != "Total": |
| 118 | po = webnotes.bean(make_purchase_order(row[0])) |
| 119 | po.doc.transaction_date = current_date |
| 120 | po.doc.fiscal_year = "2010" |
| 121 | po.insert() |
| 122 | po.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 123 | webnotes.conn.commit() |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 124 | |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 125 | def run_manufacturing(current_date): |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 126 | from stock.stock_ledger import NegativeStockError |
| 127 | from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError |
| 128 | |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 129 | ppt = webnotes.bean("Production Planning Tool", "Production Planning Tool") |
| 130 | ppt.doc.company = company |
| 131 | ppt.doc.use_multi_level_bom = 1 |
| 132 | ppt.doc.purchase_request_for_warehouse = "Stores - WP" |
| 133 | ppt.run_method("get_open_sales_orders") |
| 134 | ppt.run_method("get_items_from_so") |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 135 | ppt.run_method("raise_production_order") |
| 136 | ppt.run_method("raise_purchase_request") |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 137 | webnotes.conn.commit() |
Rushabh Mehta | 2c968ce | 2013-08-08 14:16:39 +0530 | [diff] [blame] | 138 | |
| 139 | # submit production orders |
| 140 | for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}): |
| 141 | b = webnotes.bean("Production Order", pro[0]) |
| 142 | b.doc.wip_warehouse = "Work in Progress - WP" |
| 143 | b.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 144 | webnotes.conn.commit() |
Rushabh Mehta | 75c3171 | 2013-08-08 16:00:40 +0530 | [diff] [blame] | 145 | |
| 146 | # submit material requests |
| 147 | for pro in webnotes.conn.get_values("Material Request", {"docstatus": 0}): |
| 148 | b = webnotes.bean("Material Request", pro[0]) |
| 149 | b.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 150 | webnotes.conn.commit() |
Rushabh Mehta | 2c968ce | 2013-08-08 14:16:39 +0530 | [diff] [blame] | 151 | |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 152 | # stores -> wip |
| 153 | if can_make("Stock Entry for WIP"): |
| 154 | for pro in query_report.run("Open Production Orders")["result"][:how_many("Stock Entry for WIP")]: |
| 155 | make_stock_entry_from_pro(pro[0], "Material Transfer", current_date) |
| 156 | |
| 157 | # wip -> fg |
| 158 | if can_make("Stock Entry for FG"): |
| 159 | for pro in query_report.run("Production Orders in Progress")["result"][:how_many("Stock Entry for FG")]: |
| 160 | make_stock_entry_from_pro(pro[0], "Manufacture/Repack", current_date) |
| 161 | |
| 162 | # try posting older drafts (if exists) |
| 163 | for st in webnotes.conn.get_values("Stock Entry", {"docstatus":0}): |
| 164 | try: |
| 165 | webnotes.bean("Stock Entry", st[0]).submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 166 | webnotes.conn.commit() |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 167 | except NegativeStockError: pass |
| 168 | except IncorrectValuationRateError: pass |
| 169 | |
| 170 | |
| 171 | def make_stock_entry_from_pro(pro_id, purpose, current_date): |
| 172 | from manufacturing.doctype.production_order.production_order import make_stock_entry |
| 173 | from stock.stock_ledger import NegativeStockError |
| 174 | from stock.doctype.stock_entry.stock_entry import IncorrectValuationRateError |
| 175 | |
| 176 | st = webnotes.bean(make_stock_entry(pro_id, purpose)) |
| 177 | st.run_method("get_items") |
| 178 | st.doc.posting_date = current_date |
| 179 | st.doc.fiscal_year = "2010" |
| 180 | st.doc.expense_adjustment_account = "Stock in Hand - WP" |
| 181 | try: |
| 182 | st.insert() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 183 | webnotes.conn.commit() |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 184 | st.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 185 | webnotes.conn.commit() |
Rushabh Mehta | 4c17f94 | 2013-08-12 14:18:09 +0530 | [diff] [blame] | 186 | except NegativeStockError: pass |
| 187 | except IncorrectValuationRateError: pass |
| 188 | |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 189 | def make_quotation(current_date): |
| 190 | b = webnotes.bean([{ |
| 191 | "creation": current_date, |
| 192 | "doctype": "Quotation", |
| 193 | "quotation_to": "Customer", |
| 194 | "customer": get_random("Customer"), |
| 195 | "order_type": "Sales", |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 196 | "transaction_date": current_date, |
| 197 | "fiscal_year": "2010" |
| 198 | }]) |
| 199 | |
| 200 | add_random_children(b, { |
| 201 | "doctype": "Quotation Item", |
| 202 | "parentfield": "quotation_details", |
| 203 | }, rows=3, randomize = { |
| 204 | "qty": (1, 5), |
| 205 | "item_code": ("Item", {"is_sales_item": "Yes"}) |
| 206 | }, unique="item_code") |
| 207 | |
| 208 | b.insert() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 209 | webnotes.conn.commit() |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 210 | b.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 211 | webnotes.conn.commit() |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 212 | |
| 213 | def make_sales_order(current_date): |
| 214 | q = get_random("Quotation", {"status": "Submitted"}) |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 215 | if q: |
| 216 | from selling.doctype.quotation.quotation import make_sales_order |
| 217 | so = webnotes.bean(make_sales_order(q)) |
| 218 | so.doc.transaction_date = current_date |
| 219 | so.doc.delivery_date = webnotes.utils.add_days(current_date, 10) |
| 220 | so.insert() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 221 | webnotes.conn.commit() |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 222 | so.submit() |
Rushabh Mehta | 6ca903f | 2013-08-13 14:31:15 +0530 | [diff] [blame] | 223 | webnotes.conn.commit() |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 224 | |
| 225 | def add_random_children(bean, template, rows, randomize, unique=None): |
| 226 | for i in xrange(random.randrange(1, rows)): |
| 227 | d = template.copy() |
| 228 | for key, val in randomize.items(): |
| 229 | if isinstance(val[0], basestring): |
| 230 | d[key] = get_random(*val) |
| 231 | else: |
| 232 | d[key] = random.randrange(*val) |
| 233 | |
| 234 | if unique: |
| 235 | if not bean.doclist.get({"doctype": d["doctype"], unique:d[unique]}): |
| 236 | bean.doclist.append(d) |
| 237 | else: |
| 238 | bean.doclist.append(d) |
| 239 | |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 240 | def get_random(doctype, filters=None): |
| 241 | condition = [] |
| 242 | if filters: |
| 243 | for key, val in filters.items(): |
| 244 | condition.append("%s='%s'" % (key, val)) |
| 245 | if condition: |
| 246 | condition = " where " + " and ".join(condition) |
| 247 | else: |
| 248 | condition = "" |
| 249 | |
| 250 | out = webnotes.conn.sql("""select name from `tab%s` %s |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 251 | order by RAND() limit 0,1""" % (doctype, condition)) |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 252 | |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 253 | return out and out[0][0] or None |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 254 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 255 | def can_make(doctype): |
| 256 | return random.random() < prob.get(doctype, {"make": 0.5})["make"] |
| 257 | |
| 258 | def how_many(doctype): |
| 259 | return random.randrange(*prob.get(doctype, {"qty": (1, 3)})["qty"]) |
| 260 | |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 261 | def install(): |
| 262 | print "Creating Fresh Database..." |
| 263 | from webnotes.install_lib.install import Installer |
| 264 | inst = Installer('root') |
| 265 | inst.import_from_db("demo", verbose = 1) |
| 266 | |
| 267 | def complete_setup(): |
| 268 | print "Complete Setup..." |
| 269 | webnotes.get_obj("Setup Control").setup_account({ |
| 270 | "first_name": "Test", |
| 271 | "last_name": "User", |
| 272 | "fy_start": "1st Jan", |
| 273 | "industry": "Manufacturing", |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 274 | "company_name": company, |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 275 | "company_abbr": "WP", |
Rushabh Mehta | 0b50b48 | 2013-08-06 17:53:41 +0530 | [diff] [blame] | 276 | "currency": "USD", |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 277 | "timezone": "America/New York", |
| 278 | "country": "United States" |
| 279 | }) |
Rushabh Mehta | 7c2a2e2 | 2013-08-07 15:08:11 +0530 | [diff] [blame] | 280 | |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 281 | import_data("Fiscal_Year") |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 282 | |
| 283 | def make_items(): |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 284 | import_data(["Item", "Item_Price"]) |
| 285 | import_data("BOM", submit=True) |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 286 | |
| 287 | def make_customers_suppliers_contacts(): |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 288 | import_data(["Customer", "Supplier", "Contact", "Address", "Lead"]) |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 289 | |
Rushabh Mehta | 0b50b48 | 2013-08-06 17:53:41 +0530 | [diff] [blame] | 290 | def make_users_and_employees(): |
Rushabh Mehta | 0b50b48 | 2013-08-06 17:53:41 +0530 | [diff] [blame] | 291 | webnotes.conn.set_value("HR Settings", None, "emp_created_by", "Naming Series") |
| 292 | webnotes.conn.commit() |
| 293 | |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 294 | import_data(["Profile", "Employee", "Salary_Structure"]) |
| 295 | |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 296 | def import_data(dt, submit=False): |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 297 | if not isinstance(dt, (tuple, list)): |
| 298 | dt = [dt] |
| 299 | |
| 300 | for doctype in dt: |
| 301 | print "Importing", doctype.replace("_", " "), "..." |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 302 | webnotes.form_dict = {} |
| 303 | if submit: |
| 304 | webnotes.form_dict["params"] = json.dumps({"_submit": 1}) |
Rushabh Mehta | 7cfefbc | 2013-08-07 17:46:35 +0530 | [diff] [blame] | 305 | webnotes.uploaded_file = os.path.join(os.path.dirname(__file__), "demo_docs", doctype+".csv") |
| 306 | upload() |
Rushabh Mehta | ed186b7 | 2013-07-30 16:19:40 +0530 | [diff] [blame] | 307 | |
| 308 | if __name__=="__main__": |
| 309 | make() |