[fix] Create sample opportunity and quotation only if Customer exists

This commit is contained in:
Nabin Hait 2015-10-03 13:22:53 +05:30
parent 0bc3ca02f3
commit ae92fc7f35

View File

@ -4,8 +4,9 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe 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 frappe.utils
import random
def make_sample_data(): def make_sample_data():
"""Create a few opportunities, quotes, material requests, issues, todos, projects """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}) selling_items = frappe.get_all("Item", filters = {"is_sales_item": 1})
buying_items = frappe.get_all("Item", filters = {"is_purchase_item": 1}) buying_items = frappe.get_all("Item", filters = {"is_purchase_item": 1})
customers = frappe.get_all("Customer")
if selling_items: if selling_items and customers:
for i in range(3): for i in range(3):
make_opportunity(selling_items) customer = random.choice(customers).name
make_quote(selling_items) make_opportunity(selling_items, customer)
make_quote(selling_items, customer)
make_projects() make_projects()
@ -26,11 +29,11 @@ def make_sample_data():
frappe.db.commit() frappe.db.commit()
def make_opportunity(selling_items): def make_opportunity(selling_items, customer):
b = frappe.get_doc({ b = frappe.get_doc({
"doctype": "Opportunity", "doctype": "Opportunity",
"enquiry_from": "Customer", "enquiry_from": "Customer",
"customer": get_random("Customer"), "customer": customer,
"enquiry_type": "Sales", "enquiry_type": "Sales",
"with_items": 1 "with_items": 1
}) })
@ -44,11 +47,11 @@ def make_opportunity(selling_items):
b.add_comment("This is a dummy record") b.add_comment("This is a dummy record")
def make_quote(selling_items): def make_quote(selling_items, customer):
qtn = frappe.get_doc({ qtn = frappe.get_doc({
"doctype": "Quotation", "doctype": "Quotation",
"quotation_to": "Customer", "quotation_to": "Customer",
"customer": get_random("Customer"), "customer": customer,
"order_type": "Sales" "order_type": "Sales"
}) })