From ae92fc7f35575595d3b76ee532c71f9898c14135 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Sat, 3 Oct 2015 13:22:53 +0530 Subject: [PATCH] [fix] Create sample opportunity and quotation only if Customer exists --- .../setup/page/setup_wizard/sample_data.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/erpnext/setup/page/setup_wizard/sample_data.py b/erpnext/setup/page/setup_wizard/sample_data.py index 2cebc9148b..095264f44d 100644 --- a/erpnext/setup/page/setup_wizard/sample_data.py +++ b/erpnext/setup/page/setup_wizard/sample_data.py @@ -4,8 +4,9 @@ from __future__ import unicode_literals import frappe -from frappe.utils.make_random import add_random_children, get_random +from frappe.utils.make_random import add_random_children import frappe.utils +import random def make_sample_data(): """Create a few opportunities, quotes, material requests, issues, todos, projects @@ -13,11 +14,13 @@ def make_sample_data(): selling_items = frappe.get_all("Item", filters = {"is_sales_item": 1}) buying_items = frappe.get_all("Item", filters = {"is_purchase_item": 1}) - - if selling_items: + customers = frappe.get_all("Customer") + + if selling_items and customers: for i in range(3): - make_opportunity(selling_items) - make_quote(selling_items) + customer = random.choice(customers).name + make_opportunity(selling_items, customer) + make_quote(selling_items, customer) make_projects() @@ -26,11 +29,11 @@ def make_sample_data(): frappe.db.commit() -def make_opportunity(selling_items): +def make_opportunity(selling_items, customer): b = frappe.get_doc({ "doctype": "Opportunity", "enquiry_from": "Customer", - "customer": get_random("Customer"), + "customer": customer, "enquiry_type": "Sales", "with_items": 1 }) @@ -44,11 +47,11 @@ def make_opportunity(selling_items): b.add_comment("This is a dummy record") -def make_quote(selling_items): +def make_quote(selling_items, customer): qtn = frappe.get_doc({ "doctype": "Quotation", "quotation_to": "Customer", - "customer": get_random("Customer"), + "customer": customer, "order_type": "Sales" })