Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | |
| 3 | import random, json |
| 4 | import frappe |
| 5 | from frappe.utils import nowdate, add_days |
| 6 | from erpnext.demo.setup.setup_data import import_json |
| 7 | |
Achilles Rasquinha | 5f0c703 | 2018-02-15 11:55:45 +0530 | [diff] [blame] | 8 | from six import iteritems |
| 9 | |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 10 | def setup_data(): |
| 11 | import_json("Asset Category") |
| 12 | setup_item() |
| 13 | setup_workstation() |
| 14 | setup_asset() |
| 15 | import_json('Operation') |
| 16 | setup_item_price() |
| 17 | show_item_groups_in_website() |
| 18 | import_json('BOM', submit=True) |
| 19 | frappe.db.commit() |
| 20 | frappe.clear_cache() |
| 21 | |
| 22 | def setup_workstation(): |
| 23 | workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station'] |
| 24 | for w in workstations: |
| 25 | frappe.get_doc({ |
| 26 | "doctype": "Workstation", |
| 27 | "workstation_name": w, |
| 28 | "holiday_list": frappe.get_all("Holiday List")[0].name, |
| 29 | "hour_rate_consumable": int(random.random() * 20), |
| 30 | "hour_rate_electricity": int(random.random() * 10), |
| 31 | "hour_rate_labour": int(random.random() * 40), |
| 32 | "hour_rate_rent": int(random.random() * 10), |
| 33 | "working_hours": [ |
| 34 | { |
| 35 | "enabled": 1, |
| 36 | "start_time": "8:00:00", |
| 37 | "end_time": "15:00:00" |
| 38 | } |
| 39 | ] |
| 40 | }).insert() |
| 41 | |
| 42 | def show_item_groups_in_website(): |
| 43 | """set show_in_website=1 for Item Groups""" |
| 44 | products = frappe.get_doc("Item Group", "Products") |
| 45 | products.show_in_website = 1 |
| 46 | products.route = 'products' |
| 47 | products.save() |
| 48 | |
| 49 | def setup_asset(): |
| 50 | assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read()) |
| 51 | for d in assets: |
| 52 | asset = frappe.new_doc('Asset') |
| 53 | asset.update(d) |
| 54 | asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500)) |
| 55 | asset.next_depreciation_date = add_days(asset.purchase_date, 30) |
| 56 | asset.warehouse = "Stores - WPL" |
| 57 | asset.set_missing_values() |
| 58 | asset.make_depreciation_schedule() |
| 59 | asset.flags.ignore_validate = True |
| 60 | asset.save() |
| 61 | asset.submit() |
| 62 | |
| 63 | def setup_item(): |
| 64 | items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read()) |
| 65 | for i in items: |
| 66 | item = frappe.new_doc('Item') |
| 67 | item.update(i) |
Neil Trini Lasrado | 6da2b08 | 2016-10-31 17:13:30 +0530 | [diff] [blame] | 68 | if item.default_warehouse: |
| 69 | warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.default_warehouse}, limit=1) |
| 70 | if warehouse: |
| 71 | item.default_warehouse = warehouse[0].name |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 72 | item.insert() |
| 73 | |
| 74 | def setup_product_bundle(): |
| 75 | frappe.get_doc({ |
| 76 | 'doctype': 'Product Bundle', |
| 77 | 'new_item_code': 'Wind Mill A Series with Spare Bearing', |
| 78 | 'items': [ |
| 79 | {'item_code': 'Wind Mill A Series', 'qty': 1}, |
| 80 | {'item_code': 'Bearing Collar', 'qty': 1}, |
| 81 | {'item_code': 'Bearing Assembly', 'qty': 1}, |
| 82 | ] |
| 83 | }).insert() |
| 84 | |
| 85 | def setup_item_price(): |
| 86 | frappe.db.sql("delete from `tabItem Price`") |
| 87 | |
| 88 | standard_selling = { |
| 89 | "Base Bearing Plate": 28, |
| 90 | "Base Plate": 21, |
| 91 | "Bearing Assembly": 300, |
| 92 | "Bearing Block": 14, |
| 93 | "Bearing Collar": 103.6, |
| 94 | "Bearing Pipe": 63, |
| 95 | "Blade Rib": 46.2, |
| 96 | "Disc Collars": 42, |
| 97 | "External Disc": 56, |
| 98 | "Internal Disc": 70, |
| 99 | "Shaft": 340, |
| 100 | "Stand": 400, |
| 101 | "Upper Bearing Plate": 300, |
| 102 | "Wind Mill A Series": 320, |
| 103 | "Wind Mill A Series with Spare Bearing": 750, |
| 104 | "Wind MIll C Series": 400, |
| 105 | "Wind Turbine": 400, |
| 106 | "Wing Sheet": 30.8 |
| 107 | } |
| 108 | |
| 109 | standard_buying = { |
| 110 | "Base Bearing Plate": 20, |
| 111 | "Base Plate": 28, |
| 112 | "Base Plate Un Painted": 16, |
| 113 | "Bearing Block": 13, |
| 114 | "Bearing Collar": 96.4, |
| 115 | "Bearing Pipe": 55, |
| 116 | "Blade Rib": 38, |
| 117 | "Disc Collars": 34, |
| 118 | "External Disc": 50, |
| 119 | "Internal Disc": 60, |
| 120 | "Shaft": 250, |
| 121 | "Stand": 300, |
| 122 | "Upper Bearing Plate": 200, |
| 123 | "Wing Sheet": 25 |
| 124 | } |
| 125 | |
| 126 | for price_list in ("standard_buying", "standard_selling"): |
Achilles Rasquinha | 714c746 | 2018-02-15 11:28:55 +0530 | [diff] [blame] | 127 | for item, rate in iteritems(locals().get(price_list)): |
Neil Trini Lasrado | 0672459 | 2016-08-22 12:57:09 +0530 | [diff] [blame] | 128 | frappe.get_doc({ |
| 129 | "doctype": "Item Price", |
| 130 | "price_list": price_list.replace("_", " ").title(), |
| 131 | "item_code": item, |
| 132 | "selling": 1 if price_list=="standard_selling" else 0, |
| 133 | "buying": 1 if price_list=="standard_buying" else 0, |
| 134 | "price_list_rate": rate, |
| 135 | "currency": "USD" |
| 136 | }).insert() |