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