From 86e726158b663782582949a841515cb06ffcadc7 Mon Sep 17 00:00:00 2001 From: AravindPranera Date: Tue, 31 Oct 2017 10:29:43 +0530 Subject: [PATCH] Getting Quotation Document in Sales Invoice --- .../selling/doctype/quotation/quotation.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index f0cce5ffb7..c240c653ea 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -168,6 +168,53 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False): return doclist +@frappe.whitelist() + def make_quotation(source_name, target_doc=None): + return _make_quotation(source_name, target_doc) + + def _make_quotation(source_name, target_doc=None, ignore_permissions=False): + customer = _make_customer(source_name, ignore_permissions) + + def set_missing_values(source, target): + if customer: + target.customer = customer.name + target.customer_name = customer.customer_name + target.ignore_pricing_rule = 1 + target.flags.ignore_permissions = ignore_permissions + target.run_method("set_missing_values") + target.run_method("calculate_taxes_and_totals") + + def update_item(obj, target, source_parent): + target.stock_qty = flt(obj.qty) * flt(obj.conversion_factor) + + doclist = get_mapped_doc("Quotation", source_name, { + "Quotation": { + "doctype": "Sales Invoice", + "validation": { + "docstatus": ["=", 1] + } + }, + "Quotation Item": { + "doctype": "Sales Invoice Item", + "field_map": { + "parent": "prevdoc_docname" + }, + "postprocess": update_item + }, + "Sales Taxes and Charges": { + "doctype": "Sales Taxes and Charges", + "add_if_empty": True + }, + "Sales Team": { + "doctype": "Sales Team", + "add_if_empty": True + } + }, target_doc, set_missing_values, ignore_permissions=ignore_permissions) + + # postprocess: fetch shipping address, set missing values + + return doclist + def _make_customer(source_name, ignore_permissions=False): quotation = frappe.db.get_value("Quotation", source_name, ["lead", "order_type", "customer"]) if quotation and quotation[0] and not quotation[2]: