2015-07-17 09:33:18 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
|
2015-07-17 09:33:18 +00:00
|
|
|
import frappe
|
|
|
|
import frappe.utils
|
2017-03-09 12:41:11 +00:00
|
|
|
from frappe import _
|
2021-09-02 11:14:59 +00:00
|
|
|
from frappe.utils.make_random import add_random_children
|
|
|
|
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2017-12-06 07:58:06 +00:00
|
|
|
def make_sample_data(domains, make_dependent = False):
|
2015-07-17 09:33:18 +00:00
|
|
|
"""Create a few opportunities, quotes, material requests, issues, todos, projects
|
|
|
|
to help the user get started"""
|
|
|
|
|
2017-09-04 05:44:04 +00:00
|
|
|
if make_dependent:
|
|
|
|
items = frappe.get_all("Item", {'is_sales_item': 1})
|
|
|
|
customers = frappe.get_all("Customer")
|
|
|
|
warehouses = frappe.get_all("Warehouse")
|
2016-02-10 07:47:25 +00:00
|
|
|
|
2017-09-04 05:44:04 +00:00
|
|
|
if items and customers:
|
|
|
|
for i in range(3):
|
|
|
|
customer = random.choice(customers).name
|
|
|
|
make_opportunity(items, customer)
|
|
|
|
make_quote(items, customer)
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2017-09-04 05:44:04 +00:00
|
|
|
if items and warehouses:
|
|
|
|
make_material_request(frappe.get_all("Item"))
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2017-12-06 07:58:06 +00:00
|
|
|
make_projects(domains)
|
2018-06-21 03:47:52 +00:00
|
|
|
import_notification()
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2016-04-15 07:22:12 +00:00
|
|
|
def make_opportunity(items, customer):
|
2015-07-17 09:33:18 +00:00
|
|
|
b = frappe.get_doc({
|
|
|
|
"doctype": "Opportunity",
|
2019-07-03 05:04:31 +00:00
|
|
|
"opportunity_from": "Customer",
|
2015-10-03 07:52:53 +00:00
|
|
|
"customer": customer,
|
2017-11-16 11:33:52 +00:00
|
|
|
"opportunity_type": _("Sales"),
|
2015-07-17 09:33:18 +00:00
|
|
|
"with_items": 1
|
|
|
|
})
|
|
|
|
|
2016-04-15 07:22:12 +00:00
|
|
|
add_random_children(b, "items", rows=len(items), randomize = {
|
2015-07-17 09:33:18 +00:00
|
|
|
"qty": (1, 5),
|
2016-04-15 07:22:12 +00:00
|
|
|
"item_code": ["Item"]
|
2015-07-17 09:33:18 +00:00
|
|
|
}, unique="item_code")
|
|
|
|
|
|
|
|
b.insert(ignore_permissions=True)
|
|
|
|
|
2016-02-10 07:47:25 +00:00
|
|
|
b.add_comment('Comment', text="This is a dummy record")
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2016-04-15 07:22:12 +00:00
|
|
|
def make_quote(items, customer):
|
2015-07-17 09:33:18 +00:00
|
|
|
qtn = frappe.get_doc({
|
|
|
|
"doctype": "Quotation",
|
|
|
|
"quotation_to": "Customer",
|
2019-07-03 05:04:31 +00:00
|
|
|
"party_name": customer,
|
2015-07-17 09:33:18 +00:00
|
|
|
"order_type": "Sales"
|
|
|
|
})
|
|
|
|
|
2016-04-15 07:22:12 +00:00
|
|
|
add_random_children(qtn, "items", rows=len(items), randomize = {
|
2015-07-17 09:33:18 +00:00
|
|
|
"qty": (1, 5),
|
2016-04-15 07:22:12 +00:00
|
|
|
"item_code": ["Item"]
|
2015-07-17 09:33:18 +00:00
|
|
|
}, unique="item_code")
|
|
|
|
|
|
|
|
qtn.insert(ignore_permissions=True)
|
|
|
|
|
2016-02-10 07:47:25 +00:00
|
|
|
qtn.add_comment('Comment', text="This is a dummy record")
|
2015-07-17 09:33:18 +00:00
|
|
|
|
2016-04-15 07:22:12 +00:00
|
|
|
def make_material_request(items):
|
|
|
|
for i in items:
|
2015-07-17 09:33:18 +00:00
|
|
|
mr = frappe.get_doc({
|
|
|
|
"doctype": "Material Request",
|
|
|
|
"material_request_type": "Purchase",
|
2017-09-26 02:56:31 +00:00
|
|
|
"schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7),
|
2015-07-17 09:33:18 +00:00
|
|
|
"items": [{
|
|
|
|
"schedule_date": frappe.utils.add_days(frappe.utils.nowdate(), 7),
|
|
|
|
"item_code": i.name,
|
|
|
|
"qty": 10
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
mr.insert()
|
|
|
|
mr.submit()
|
|
|
|
|
2016-02-10 07:47:25 +00:00
|
|
|
mr.add_comment('Comment', text="This is a dummy record")
|
2015-07-17 09:33:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def make_issue():
|
|
|
|
pass
|
|
|
|
|
2017-12-06 07:58:06 +00:00
|
|
|
def make_projects(domains):
|
2017-03-09 12:41:11 +00:00
|
|
|
current_date = frappe.utils.nowdate()
|
2015-07-17 09:33:18 +00:00
|
|
|
project = frappe.get_doc({
|
|
|
|
"doctype": "Project",
|
|
|
|
"project_name": "ERPNext Implementation",
|
|
|
|
})
|
2017-03-09 12:41:11 +00:00
|
|
|
|
|
|
|
tasks = [
|
|
|
|
{
|
|
|
|
"title": "Explore ERPNext",
|
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": current_date,
|
|
|
|
"file": "explore.md"
|
|
|
|
}]
|
|
|
|
|
2017-12-06 07:58:06 +00:00
|
|
|
if 'Education' in domains:
|
2017-03-09 12:41:11 +00:00
|
|
|
tasks += [
|
|
|
|
{
|
2017-11-23 09:52:10 +00:00
|
|
|
"title": _("Setup your Institute in ERPNext"),
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 1),
|
2017-11-23 09:52:10 +00:00
|
|
|
"file": "education_masters.md"
|
2017-03-09 12:41:11 +00:00
|
|
|
},
|
|
|
|
{
|
2017-03-10 07:17:29 +00:00
|
|
|
"title": "Setup Master Data",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
2017-03-10 07:17:29 +00:00
|
|
|
"end_date": frappe.utils.add_days(current_date, 1),
|
2017-11-23 09:52:10 +00:00
|
|
|
"file": "education_masters.md"
|
2017-03-09 12:41:11 +00:00
|
|
|
}]
|
|
|
|
|
|
|
|
else:
|
|
|
|
tasks += [
|
|
|
|
{
|
2017-03-10 07:17:29 +00:00
|
|
|
"title": "Setup Your Company",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 1),
|
|
|
|
"file": "masters.md"
|
2015-07-17 09:33:18 +00:00
|
|
|
},
|
|
|
|
{
|
2017-03-10 07:17:29 +00:00
|
|
|
"title": "Start Tracking your Sales",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 2),
|
|
|
|
"file": "sales.md"
|
2015-07-17 09:33:18 +00:00
|
|
|
},
|
|
|
|
{
|
2017-03-10 07:17:29 +00:00
|
|
|
"title": "Start Managing Purchases",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 3),
|
|
|
|
"file": "purchase.md"
|
2015-07-17 09:33:18 +00:00
|
|
|
},
|
|
|
|
{
|
2015-07-23 12:46:25 +00:00
|
|
|
"title": "Import Data",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 4),
|
|
|
|
"file": "import_data.md"
|
2015-07-23 12:46:25 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Go Live!",
|
2017-03-09 12:41:11 +00:00
|
|
|
"start_date": current_date,
|
|
|
|
"end_date": frappe.utils.add_days(current_date, 5),
|
|
|
|
"file": "go_live.md"
|
|
|
|
}]
|
|
|
|
|
|
|
|
for t in tasks:
|
|
|
|
with open (os.path.join(os.path.dirname(__file__), "tasks", t['file'])) as f:
|
2018-08-07 06:23:36 +00:00
|
|
|
t['description'] = frappe.utils.md_to_html(f.read())
|
2017-03-09 12:41:11 +00:00
|
|
|
del t['file']
|
|
|
|
|
|
|
|
project.append('tasks', t)
|
2015-07-17 09:33:18 +00:00
|
|
|
|
|
|
|
project.insert(ignore_permissions=True)
|
2017-03-09 12:41:11 +00:00
|
|
|
|
2018-06-21 03:47:52 +00:00
|
|
|
def import_notification():
|
|
|
|
'''Import notification for task start'''
|
2017-03-09 12:41:11 +00:00
|
|
|
with open (os.path.join(os.path.dirname(__file__), "tasks/task_alert.json")) as f:
|
2018-06-21 03:47:52 +00:00
|
|
|
notification = frappe.get_doc(json.loads(f.read())[0])
|
|
|
|
notification.insert()
|
2017-03-09 12:41:11 +00:00
|
|
|
|
2017-03-10 07:17:29 +00:00
|
|
|
# trigger the first message!
|
2018-06-11 11:50:30 +00:00
|
|
|
from frappe.email.doctype.notification.notification import trigger_daily_alerts
|
2017-03-10 07:17:29 +00:00
|
|
|
trigger_daily_alerts()
|
|
|
|
|
2017-03-09 12:41:11 +00:00
|
|
|
def test_sample():
|
2018-06-11 11:50:30 +00:00
|
|
|
frappe.db.sql('delete from `tabNotification`')
|
2017-03-09 12:41:11 +00:00
|
|
|
frappe.db.sql('delete from tabProject')
|
|
|
|
frappe.db.sql('delete from tabTask')
|
|
|
|
make_projects('Education')
|
2021-08-19 08:11:10 +00:00
|
|
|
import_notification()
|