def _make_customer(source_name, ignore_permissions=False): quotation = webnotes.conn.get_value("Quotation", source_name, ["lead", "order_type"]) if quotation and quotation[0]: lead_name = quotation[0] customer_name = webnotes.conn.get_value("Customer", {"lead_name": lead_name}) if not customer_name: from selling.doctype.lead.lead import _make_customer customer_doclist = _make_customer(lead_name, ignore_permissions=ignore_permissions) customer = webnotes.bean(customer_doclist) customer.ignore_permissions = ignore_permissions if quotation[1] == "Shopping Cart": customer.doc.customer_group = webnotes.conn.get_value("Shopping Cart Settings", None, "default_customer_group") try: customer.insert() return customer except NameError, e: if webnotes.defaults.get_global_default('cust_master_name') == "Customer Name": customer.run_method("autoname") customer.doc.name += "-" + lead_name customer.insert() return customer else: raise e
def _make_customer(source_name, ignore_permissions=False): quotation = webnotes.conn.get_value("Quotation", source_name, ["lead", "order_type"]) if quotation and quotation[0]: lead_name = quotation[0] customer_name = webnotes.conn.get_value("Customer", {"lead_name": lead_name}) if not customer_name: from selling.doctype.lead.lead import _make_customer customer_doclist = _make_customer(lead_name, ignore_permissions=ignore_permissions) customer = webnotes.bean(customer_doclist) customer.ignore_permissions = ignore_permissions if quotation[1] == "Shopping Cart": customer.doc.customer_group = webnotes.conn.get_value("Shopping Cart Settings", None, "default_customer_group") try: customer.insert() return customer except NameError, e: if webnotes.defaults.get_global_default('cust_master_name') == "Customer Name": customer.run_method("autoname") customer.doc.name += "-" + lead_name customer.insert() return customer else: raise except webnotes.MandatoryError: from webnotes.utils import get_url_to_form webnotes.throw(_("Before proceeding, please create Customer from Lead") + \ (" - %s" % get_url_to_form("Lead", lead_name)))
def _make_internal_order(source_name, target_doclist=None, ignore_permissions=False): #webnotes.errprint("in make internal order 2") from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Sales Order", source_name, { "Sales Order": { "doctype": "Internal Order Form", "validation": { "docstatus": ["=", 1] } }, "Accessories Details": { "doctype": "Accessories Details", "field_map": { "parent": "prevdoc_docname" } }, "Customer Details": { "doctype": "Internal Order Customer Details", "field_map": { "parent": "prevdoc_docname" } }, "Consignee Details": { "doctype": "Internal Order Consignee Details", "field_map": { "parent": "prevdoc_docname" } }, "Sales Order Item": { "doctype": "Internal Order Item Details", "field_map": { "parent": "prevdoc_docname" } }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]
def _make_customer(source_name, ignore_permissions=False): quotation = webnotes.conn.get_value("Quotation", source_name, ["lead", "order_type"]) if quotation and quotation[0]: lead_name = quotation[0] customer_name = webnotes.conn.get_value("Customer", {"lead_name": lead_name}) if not customer_name: from selling.doctype.lead.lead import _make_customer customer_doclist = _make_customer( lead_name, ignore_permissions=ignore_permissions) customer = webnotes.bean(customer_doclist) customer.ignore_permissions = ignore_permissions if quotation[1] == "Shopping Cart": customer.doc.customer_group = webnotes.conn.get_value( "Shopping Cart Settings", None, "default_customer_group") try: customer.insert() return customer except NameError, e: if webnotes.defaults.get_global_default( 'cust_master_name') == "Customer Name": customer.run_method("autoname") customer.doc.name += "-" + lead_name customer.insert() return customer else: raise except webnotes.MandatoryError: from webnotes.utils import get_url_to_form webnotes.throw(_("Before proceeding, please create Customer from Lead") + \ (" - %s" % get_url_to_form("Lead", lead_name)))
def _make_customer(source_name, ignore_permissions=False): quotation = webnotes.conn.get_value("Quotation", source_name, ["lead", "order_type"]) if quotation and quotation[0]: lead_name = quotation[0] customer_name = webnotes.conn.get_value("Customer", {"lead_name": lead_name}) if not customer_name: from selling.doctype.lead.lead import _make_customer customer_doclist = _make_customer( lead_name, ignore_permissions=ignore_permissions) customer = webnotes.bean(customer_doclist) customer.ignore_permissions = ignore_permissions if quotation[1] == "Shopping Cart": customer.doc.customer_group = webnotes.conn.get_value( "Shopping Cart Settings", None, "default_customer_group") try: customer.insert() return customer except NameError, e: if webnotes.defaults.get_global_default( 'cust_master_name') == "Customer Name": customer.run_method("autoname") customer.doc.name += "-" + lead_name customer.insert() return customer else: raise e
def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Quotation", source_name, { "Quotation": { "doctype": "Sales Order", "validation": { "docstatus": ["=", 1] } }, "Accessories Details": { "doctype": "Accessories Details", "field_map": { "parent": "prevdoc_docname" } }, "Quotation Item": { "doctype": "Sales Order Item", "field_map": { "parent": "prevdoc_docname" } }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]
def _make_provisional_sales_order(source_name, target_doclist=None, ignore_permissions=False): from webnotes.model.mapper import get_mapped_doclist customer = _make_customer(source_name, ignore_permissions) def set_missing_values(source, target): if customer: target[0].customer = customer.doc.name target[0].customer_name = customer.doc.customer_name target[0].sales_order_type = 'Provisional' si = webnotes.bean(target) si.run_method("onload_post_render") doclist = get_mapped_doclist("Quotation", source_name, { "Quotation": { "doctype": "Sales Order", "validation": { "docstatus": ["=", 1] } }, "Quotation Item": { "doctype": "Sales Order Item", "field_map": { "parent": "prevdoc_docname" } }, # "Quotation Product": { # "doctype": "Sales Order Product", # "field_map": { # "parent": "prevdoc_docname" # } # }, "Sales Taxes and Charges": { "doctype": "Sales Taxes and Charges", "add_if_empty": True }, "Sales Team": { "doctype": "Sales Team", "add_if_empty": True } }, target_doclist, set_missing_values, ignore_permissions=ignore_permissions) # postprocess: fetch shipping address, set missing values return [d.fields for d in doclist]