Get items from quotation in sales invoice

This commit is contained in:
Nabin Hait 2017-11-14 17:13:19 +05:30
parent 04e3518fad
commit cd13a28417
2 changed files with 44 additions and 48 deletions

View File

@ -95,8 +95,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
// Show buttons only when pos view is active // Show buttons only when pos view is active
if (cint(doc.docstatus==0) && cur_frm.page.current_view_name!=="pos" && !doc.is_return) { if (cint(doc.docstatus==0) && cur_frm.page.current_view_name!=="pos" && !doc.is_return) {
cur_frm.cscript.sales_order_btn(); this.frm.cscript.sales_order_btn();
cur_frm.cscript.delivery_note_btn(); this.frm.cscript.delivery_note_btn();
this.frm.cscript.quotation_btn();
} }
this.set_default_print_format(); this.set_default_print_format();
@ -163,7 +164,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
this.$quotation_btn = this.frm.add_custom_button(__('Quotation'), this.$quotation_btn = this.frm.add_custom_button(__('Quotation'),
function() { function() {
erpnext.utils.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.selling.doctype.quotation.quotation.make_quotation", method: "erpnext.selling.doctype.quotation.quotation.make_sales_invoice",
source_doctype: "Quotation", source_doctype: "Quotation",
target: me.frm, target: me.frm,
setters: { setters: {

View File

@ -169,51 +169,46 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
return doclist return doclist
@frappe.whitelist() @frappe.whitelist()
def make_quotation(source_name, target_doc=None): def make_sales_invoice(source_name, target_doc=None):
return _make_quotation(source_name, target_doc) return _make_sales_invoice(source_name, target_doc)
def _make_quotation(source_name, target_doc=None, ignore_permissions=False): def _make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
customer = _make_customer(source_name, ignore_permissions) customer = _make_customer(source_name, ignore_permissions)
def set_missing_values(source, target): def set_missing_values(source, target):
if customer: if customer:
target.customer = customer.name target.customer = customer.name
target.customer_name = customer.customer_name target.customer_name = customer.customer_name
target.ignore_pricing_rule = 1 target.ignore_pricing_rule = 1
target.flags.ignore_permissions = ignore_permissions target.flags.ignore_permissions = ignore_permissions
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals") target.run_method("calculate_taxes_and_totals")
def update_item(obj, target, source_parent): def update_item(obj, target, source_parent):
target.stock_qty = flt(obj.qty) * flt(obj.conversion_factor) target.stock_qty = flt(obj.qty) * flt(obj.conversion_factor)
doclist = get_mapped_doc("Quotation", source_name, { doclist = get_mapped_doc("Quotation", source_name, {
"Quotation": { "Quotation": {
"doctype": "Sales Invoice", "doctype": "Sales Invoice",
"validation": { "validation": {
"docstatus": ["=", 1] "docstatus": ["=", 1]
} }
}, },
"Quotation Item": { "Quotation Item": {
"doctype": "Sales Invoice Item", "doctype": "Sales Invoice Item",
"field_map": { "postprocess": update_item
"parent": "prevdoc_docname" },
}, "Sales Taxes and Charges": {
"postprocess": update_item "doctype": "Sales Taxes and Charges",
}, "add_if_empty": True
"Sales Taxes and Charges": { },
"doctype": "Sales Taxes and Charges", "Sales Team": {
"add_if_empty": True "doctype": "Sales Team",
}, "add_if_empty": True
"Sales Team": { }
"doctype": "Sales Team", }, target_doc, set_missing_values, ignore_permissions=ignore_permissions)
"add_if_empty": True
}
}, target_doc, set_missing_values, ignore_permissions=ignore_permissions)
# postprocess: fetch shipping address, set missing values return doclist
return doclist
def _make_customer(source_name, ignore_permissions=False): def _make_customer(source_name, ignore_permissions=False):
quotation = frappe.db.get_value("Quotation", source_name, ["lead", "order_type", "customer"]) quotation = frappe.db.get_value("Quotation", source_name, ["lead", "order_type", "customer"])