blob: 0469264da1ea2e7e0179f5e325d9e3de5cc0993f [file] [log] [blame]
Chillar Anand915b3432021-09-02 16:44:59 +05301import json
2
Zlash6562592d32018-10-10 14:27:40 +05303import frappe
Chillar Anand915b3432021-09-02 16:44:59 +05304
Zlash6562592d32018-10-10 14:27:40 +05305from erpnext.demo.domains import data
6
Zlash6562592d32018-10-10 14:27:40 +05307
8def setup_data():
9 setup_item()
10 setup_item_price()
11 frappe.db.commit()
12 frappe.clear_cache()
13
14def setup_item():
15 items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read())
16 for i in items:
17 if not i.get("domain") == "Retail": continue
18 item = frappe.new_doc('Item')
19 item.update(i)
20 if hasattr(item, 'item_defaults') and item.item_defaults[0].default_warehouse:
21 item.item_defaults[0].company = data.get("Retail").get('company_name')
22 warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1)
23 if warehouse:
24 item.item_defaults[0].default_warehouse = warehouse[0].name
25 item.insert()
26
27def setup_item_price():
28 frappe.db.sql("delete from `tabItem Price`")
29
30 standard_selling = {
31 "OnePlus 6": 579,
32 "OnePlus 6T": 600,
33 "Xiaomi Poco F1": 300,
34 "Iphone XS": 999,
35 "Samsung Galaxy S9": 720,
36 "Sony Bluetooth Headphone": 99,
37 "Xiaomi Phone Repair": 10,
38 "Samsung Phone Repair": 20,
39 "OnePlus Phone Repair": 15,
40 "Apple Phone Repair": 30,
41 }
42
43 standard_buying = {
44 "OnePlus 6": 300,
45 "OnePlus 6T": 350,
46 "Xiaomi Poco F1": 200,
47 "Iphone XS": 600,
48 "Samsung Galaxy S9": 500,
49 "Sony Bluetooth Headphone": 69
50 }
51
52 for price_list in ("standard_buying", "standard_selling"):
Ankush Menat8fe5feb2021-11-04 19:48:32 +053053 for item, rate in locals().get(price_list).items():
Zlash6562592d32018-10-10 14:27:40 +053054 frappe.get_doc({
55 "doctype": "Item Price",
56 "price_list": price_list.replace("_", " ").title(),
57 "item_code": item,
58 "selling": 1 if price_list=="standard_selling" else 0,
59 "buying": 1 if price_list=="standard_buying" else 0,
60 "price_list_rate": rate,
61 "currency": "USD"
62 }).insert()