From dcb72c6be7cb949053c3a2b1363134df818ab07b Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 17 Feb 2016 15:05:05 +0530 Subject: [PATCH 1/3] [enhance] Displaying stock balance while creating quotation --- .../selling/doctype/quotation/quotation.js | 8 ++ .../selling/doctype/quotation/quotation.py | 3 +- .../quotation_item/quotation_item.json | 124 +++++++++++++++++- erpnext/stock/get_item_details.py | 8 ++ 4 files changed, 141 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 83cec046355..2cc7c63c9c1 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -47,6 +47,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ } this.toggle_reqd_lead_customer(); + }, quotation_to: function() { @@ -162,3 +163,10 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) { frappe.ui.form.on("Quotation Item", "items_on_form_rendered", function(frm, cdt, cdn) { // enable tax_amount field if Actual }) + +frappe.ui.form.on("Quotation Item", "stock_balance", function(frm, cdt, cdn) { + console.log("here") + var d = locals[cdt][cdn]; + frappe.route_options = {"item_code": d.item_code}; + frappe.set_route("query-report", "Stock Balance"); +}) \ No newline at end of file diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 3c8add44f79..37ac412ad09 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -106,7 +106,8 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False): "Quotation Item": { "doctype": "Sales Order Item", "field_map": { - "parent": "prevdoc_docname" + "parent": "prevdoc_docname", + "warehouse": "warehouse" } }, "Sales Taxes and Charges": { diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index 0146f38133f..cf5f2dc2ac1 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -693,6 +693,128 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 1, + "collapsible_depends_on": "eval:doc.actual_qty", + "fieldname": "item_balance", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Item Balance", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "warehouse", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Warehouse", + "length": 0, + "no_copy": 1, + "options": "Warehouse", + "permlevel": 0, + "precision": "", + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 1, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "column_break_30", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "description": "", + "fieldname": "actual_qty", + "fieldtype": "Float", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Actual Qty", + "length": 0, + "no_copy": 1, + "permlevel": 0, + "precision": "", + "print_hide": 1, + "print_hide_if_no_value": 0, + "read_only": 1, + "report_hide": 1, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "fieldname": "stock_balance", + "fieldtype": "Button", + "hidden": 0, + "ignore_user_permissions": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Stock Balance", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -910,7 +1032,7 @@ "istable": 1, "max_attachments": 0, "menu_index": 0, - "modified": "2016-02-08 08:02:06.257910", + "modified": "2016-02-17 14:48:49.320786", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 22dbe5195f7..6da2838a3df 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -165,6 +165,7 @@ def get_basic_details(args, item): "discount_percentage": 0.0, "supplier": item.default_supplier, "delivered_by_supplier": item.delivered_by_supplier, + "actual_qty": get_item_balance_qty_for_default_warehouse(item) }) # if default specified in item is for another company, fetch from company @@ -463,3 +464,10 @@ def get_default_bom(item_code=None): return bom else: frappe.throw(_("No default BOM exists for Item {0}").format(item_code)) + + +def get_item_balance_qty_for_default_warehouse(item): + item = frappe.get_doc("Item", item.name) + + return frappe.db.get_value("Bin", {"item_code": item.name, "warehouse": item.default_warehouse}, + ["actual_qty"], as_dict=True) or {"actual_qty": 0} From 3724448cd346ad81004afc2da30398a50ccd6476 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Thu, 18 Feb 2016 17:38:56 +0530 Subject: [PATCH 2/3] [fixes] typo-fixes and fix in balance qty fetching --- erpnext/selling/doctype/quotation/quotation.js | 3 +-- erpnext/stock/get_item_details.py | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 2cc7c63c9c1..3e90b97dd37 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -165,8 +165,7 @@ frappe.ui.form.on("Quotation Item", "items_on_form_rendered", function(frm, cdt, }) frappe.ui.form.on("Quotation Item", "stock_balance", function(frm, cdt, cdn) { - console.log("here") - var d = locals[cdt][cdn]; + var d = frappe.model.get_doc(cdt, cdn); frappe.route_options = {"item_code": d.item_code}; frappe.set_route("query-report", "Stock Balance"); }) \ No newline at end of file diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 6da2838a3df..8d7f23ea11d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -165,7 +165,7 @@ def get_basic_details(args, item): "discount_percentage": 0.0, "supplier": item.default_supplier, "delivered_by_supplier": item.delivered_by_supplier, - "actual_qty": get_item_balance_qty_for_default_warehouse(item) + "actual_qty": get_available_qty(item.name, user_default_warehouse or args.warehouse or item.default_warehouse) }) # if default specified in item is for another company, fetch from company @@ -464,10 +464,3 @@ def get_default_bom(item_code=None): return bom else: frappe.throw(_("No default BOM exists for Item {0}").format(item_code)) - - -def get_item_balance_qty_for_default_warehouse(item): - item = frappe.get_doc("Item", item.name) - - return frappe.db.get_value("Bin", {"item_code": item.name, "warehouse": item.default_warehouse}, - ["actual_qty"], as_dict=True) or {"actual_qty": 0} From ac3372465645e738d81762f5891d732efa763858 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 23 Feb 2016 18:16:06 +0530 Subject: [PATCH 3/3] [fixes] removed no copy for warehouse field --- erpnext/selling/doctype/quotation/quotation.py | 3 +-- erpnext/selling/doctype/quotation_item/quotation_item.json | 4 ++-- erpnext/stock/get_item_details.py | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 37ac412ad09..3c8add44f79 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -106,8 +106,7 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False): "Quotation Item": { "doctype": "Sales Order Item", "field_map": { - "parent": "prevdoc_docname", - "warehouse": "warehouse" + "parent": "prevdoc_docname" } }, "Sales Taxes and Charges": { diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index cf5f2dc2ac1..b1bb6f752ee 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -730,7 +730,7 @@ "in_list_view": 0, "label": "Warehouse", "length": 0, - "no_copy": 1, + "no_copy": 0, "options": "Warehouse", "permlevel": 0, "precision": "", @@ -1032,7 +1032,7 @@ "istable": 1, "max_attachments": 0, "menu_index": 0, - "modified": "2016-02-17 14:48:49.320786", + "modified": "2016-02-23 18:12:49.939175", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 8d7f23ea11d..686048612d8 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -164,8 +164,7 @@ def get_basic_details(args, item): "net_amount": 0.0, "discount_percentage": 0.0, "supplier": item.default_supplier, - "delivered_by_supplier": item.delivered_by_supplier, - "actual_qty": get_available_qty(item.name, user_default_warehouse or args.warehouse or item.default_warehouse) + "delivered_by_supplier": item.delivered_by_supplier }) # if default specified in item is for another company, fetch from company