Merge pull request #4854 from patilsangram/develop

Removed Stop Button from SO and PO
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index 2de9993..b91df4b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -24,11 +24,13 @@
 
 		if(!doc.is_return) {
 			if(doc.docstatus==1) {
-				if(doc.outstanding_amount != 0) {
+				if(doc.outstanding_amount < 0) {
 					this.frm.add_custom_button(__('Payment'), this.make_bank_entry, __("Make"));
 					cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
 				}
-				cur_frm.add_custom_button(__('Debit Note'), this.make_debit_note, __("Make"));
+				if(Math.abs(flt(doc.outstanding_amount)) < flt(doc.grand_total)) {
+					cur_frm.add_custom_button(__('Debit Note'), this.make_debit_note, __("Make"));
+				}
 			}
 
 			if(doc.docstatus===0) {
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index e717089..200fca6 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -57,10 +57,12 @@
 				return item.is_delivered_by_supplier ? true : false;
 			})
 
-			cur_frm.add_custom_button(doc.update_stock ? __('Sales Return') : __('Credit Note'),
-				this.make_sales_return, __("Make"));
-			cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
-
+			if(Math.abs(flt(doc.outstanding_amount)) < flt(doc.grand_total)) {
+				cur_frm.add_custom_button(doc.update_stock ? __('Sales Return') : __('Credit Note'),
+					this.make_sales_return, __("Make"));
+				cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
+			}
+			
 			if(cint(doc.update_stock)!=1) {
 				// show Make Delivery Note button only if Sales Invoice is not created from Delivery Note
 				var from_delivery_note = false;
@@ -75,7 +77,7 @@
 				}
 			}
 
-			if(doc.outstanding_amount!=0 && !cint(doc.is_return)) {
+			if(doc.outstanding_amount>0 && !cint(doc.is_return)) {
 				cur_frm.add_custom_button(__('Payment Request'), this.make_payment_request, __("Make"));
 				cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry, __("Make"));
 			}
diff --git a/erpnext/buying/report/item_wise_purchase_history/item_wise_purchase_history.json b/erpnext/buying/report/item_wise_purchase_history/item_wise_purchase_history.json
index 4cfda96..4659b36 100644
--- a/erpnext/buying/report/item_wise_purchase_history/item_wise_purchase_history.json
+++ b/erpnext/buying/report/item_wise_purchase_history/item_wise_purchase_history.json
@@ -2,17 +2,18 @@
  "add_total_row": 1, 
  "apply_user_permissions": 1, 
  "creation": "2013-05-03 14:55:53", 
+ "disabled": 0, 
  "docstatus": 0, 
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2016-01-28 15:36:46.837095", 
+ "modified": "2016-02-22 11:27:39.445257", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Item-wise Purchase History", 
  "owner": "Administrator", 
- "query": "select\n    po_item.item_code as \"Item Code:Link/Item:120\",\n\tpo_item.item_name as \"Item Name::120\",\n        po_item.item_group as \"Item Group:Link/Item Group:120\",\n\tpo_item.description as \"Description::150\",\n\tpo_item.qty as \"Qty:Float:100\",\n\tpo_item.stock_uom as \"UOM:Link/UOM:80\",\n\tpo_item.base_rate as \"Rate:Currency:120\",\n\tpo_item.base_amount as \"Amount:Currency:120\",\n\tpo.name as \"Purchase Order:Link/Purchase Order:120\",\n\tpo.transaction_date as \"Transaction Date:Date:140\",\n\tpo.supplier as \"Supplier:Link/Supplier:130\",\n        sup.supplier_name as \"Supplier Name::150\",\n\tpo_item.project_name as \"Project:Link/Project:130\",\n\tifnull(po_item.received_qty, 0) as \"Received Qty:Float:120\",\n\tpo.company as \"Company:Link/Company:\"\nfrom\n\t`tabPurchase Order` po, `tabPurchase Order Item` po_item, `tabSupplier` sup\nwhere\n\tpo.name = po_item.parent and po.supplier = sup.name and po.docstatus = 1\norder by po.name desc", 
+ "query": "select\n    po_item.item_code as \"Item Code:Link/Item:120\",\n\tpo_item.item_name as \"Item Name::120\",\n        po_item.item_group as \"Item Group:Link/Item Group:120\",\n\tpo_item.description as \"Description::150\",\n\tpo_item.qty as \"Qty:Float:100\",\n\tpo_item.uom as \"UOM:Link/UOM:80\",\n\tpo_item.base_rate as \"Rate:Currency:120\",\n\tpo_item.base_amount as \"Amount:Currency:120\",\n\tpo.name as \"Purchase Order:Link/Purchase Order:120\",\n\tpo.transaction_date as \"Transaction Date:Date:140\",\n\tpo.supplier as \"Supplier:Link/Supplier:130\",\n        sup.supplier_name as \"Supplier Name::150\",\n\tpo_item.project_name as \"Project:Link/Project:130\",\n\tifnull(po_item.received_qty, 0) as \"Received Qty:Float:120\",\n\tpo.company as \"Company:Link/Company:\"\nfrom\n\t`tabPurchase Order` po, `tabPurchase Order Item` po_item, `tabSupplier` sup\nwhere\n\tpo.name = po_item.parent and po.supplier = sup.name and po.docstatus = 1\norder by po.name desc", 
  "ref_doctype": "Purchase Order", 
  "report_name": "Item-wise Purchase History", 
  "report_type": "Query Report"
-}
+}
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/accounts/multi-currency-accounting.md b/erpnext/docs/user/manual/en/accounts/multi-currency-accounting.md
index 6080dcc..c5887bb 100644
--- a/erpnext/docs/user/manual/en/accounts/multi-currency-accounting.md
+++ b/erpnext/docs/user/manual/en/accounts/multi-currency-accounting.md
@@ -27,7 +27,7 @@
 
 In Sales Invoice, transaction currency must be same as accounting currency of Customer if Customer's accounting currency is other than Company Currency. Otherwise, you can select any currency in Invoice. On selection of Customer, system will fetch Receivable account from Customer / Company. The currency of receivable account must be same as Customer's accounting currency.
 
-Now, in POS, Paid Amount will be enetered in transaction currency, instead of earlier Company Currency. Write Off Amount will also be entered in transaction currency.
+Now, in POS, Paid Amount will be entered in transaction currency, instead of earlier Company Currency. Write Off Amount will also be entered in transaction currency.
 
 Outstanding Amount and Advance Amount will always be calculated and shown in Customer's Account Currency.
 
@@ -115,4 +115,4 @@
 
 In Accounts Receivable / Payable report, system shows all the amounts in Party / Account Currency.
 
-<img class="screenshot" alt="Accounts Receivable Report"  	src="{{docs_base_url}}/assets/img/accounts/multi-currency/accounts-receivable.png">
\ No newline at end of file
+<img class="screenshot" alt="Accounts Receivable Report"  	src="{{docs_base_url}}/assets/img/accounts/multi-currency/accounts-receivable.png">
diff --git a/erpnext/docs/user/manual/en/accounts/opening-accounts.md b/erpnext/docs/user/manual/en/accounts/opening-accounts.md
index 214642d..28ba0c2 100644
--- a/erpnext/docs/user/manual/en/accounts/opening-accounts.md
+++ b/erpnext/docs/user/manual/en/accounts/opening-accounts.md
@@ -32,7 +32,7 @@
 A nice way to simplify opening is to use a temporary account
 just for opening. These accounts will become zero once all your old
 invoices and opening balances of bank, debt stock etc are entered.
-In the standard chart of accounts, a **Temperory Opening** account is created under
+In the standard chart of accounts, a **Temporary Opening** account is created under
 assets
 
 #### The Opening Entry
@@ -63,8 +63,8 @@
 
 You can make two Opening Journal Entrys:
 
-  * For all assets (excluding Accounts Receivables): This entry will contain all your assets except the amounts you are expecting from your Customers against outstanding Sales Invoices. You will have to update your receivables by making an individual entry for each Invoice (this is because, the system will help you track the invoices which are yet to be paid). You can credit the sum of all these debits against the **Temperory Opening** account.
-  * For all liabilities: Similarly you need to pass a Journal Entry for your Opening Liabilities (except for the bills you have to pay) against **Temperory Opening** account.
+  * For all assets (excluding Accounts Receivables): This entry will contain all your assets except the amounts you are expecting from your Customers against outstanding Sales Invoices. You will have to update your receivables by making an individual entry for each Invoice (this is because, the system will help you track the invoices which are yet to be paid). You can credit the sum of all these debits against the **Temporary Opening** account.
+  * For all liabilities: Similarly you need to pass a Journal Entry for your Opening Liabilities (except for the bills you have to pay) against **Temporary Opening** account.
   * In this method you can update opening balance of specific balancesheet accounts and not for all.
   * Opening entry is only for balance sheet accounts and not for expense or Income accounts.
 
@@ -89,6 +89,6 @@
 in the Invoice. Item code in the Invoice is not necessary, so it should not be
 such a problem.
 
-Once all your invoices are entered, your **Temperory Opening** account will have a balance of zero!
+Once all your invoices are entered, your **Temporary Opening** account will have a balance of zero!
 
 {next}
diff --git a/erpnext/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/date-validation.md b/erpnext/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/date-validation.md
index 0d080af..d68ab56 100644
--- a/erpnext/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/date-validation.md
+++ b/erpnext/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/date-validation.md
@@ -1,10 +1,10 @@
 # Date Validation
 
 
-	frappe.ui.form.on("Event", "validate", function(frm) {
+	frappe.ui.form.on("Task", "validate", function(frm) {
         if (frm.doc.from_date < get_today()) {
             msgprint(__("You can not select past date in From Date"));
-            throw "past date selected"
+            validated = false;
         }
 	});
 
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 83cec04..3e90b97 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -47,6 +47,7 @@
 		}
 
 		this.toggle_reqd_lead_customer();
+		
 	},
 
 	quotation_to: function() {
@@ -162,3 +163,9 @@
 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) {
+	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/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json
index 0146f38..b1bb6f7 100644
--- a/erpnext/selling/doctype/quotation_item/quotation_item.json
+++ b/erpnext/selling/doctype/quotation_item/quotation_item.json
@@ -696,6 +696,128 @@
   {
    "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": 0, 
+   "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, 
    "collapsible": 0, 
    "fieldname": "reference", 
    "fieldtype": "Section Break", 
@@ -910,7 +1032,7 @@
  "istable": 1, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-02-08 08:02:06.257910", 
+ "modified": "2016-02-23 18:12:49.939175", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Quotation Item", 
diff --git a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
index d27816c..c7baf0c 100644
--- a/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
+++ b/erpnext/selling/report/sales_person_target_variance_item_group_wise/sales_person_target_variance_item_group_wise.py
@@ -87,14 +87,12 @@
 	return target_details
 
 #Get achieved details from sales order
-def get_achieved_details(filters, sales_person, item_groups):
+def get_achieved_details(filters, sales_person, all_sales_persons, target_item_group, item_groups):
 	start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
 
-	lft, rgt = frappe.get_value("Sales Person", sales_person, ["lft", "rgt"])
-
 	item_details = frappe.db.sql("""
 		select
-			soi.item_code, sum(soi.qty * (st.allocated_percentage/100)) as qty,
+			sum(soi.qty * (st.allocated_percentage/100)) as qty,
 			sum(soi.base_net_amount * (st.allocated_percentage/100)) as amount,
 			st.sales_person, MONTHNAME(so.transaction_date) as month_name
 		from
@@ -103,35 +101,36 @@
 			soi.parent=so.name and so.docstatus=1 and st.parent=so.name
 			and so.transaction_date>=%s and so.transaction_date<=%s
 			and exists(select name from `tabSales Person` where lft >= %s and rgt <= %s and name=st.sales_person)
+			and exists(select name from `tabItem Group` where lft >= %s and rgt <= %s and name=soi.item_group)
 		group by
-			sales_person, item_code, month_name
+			sales_person, month_name
 			""",
-		(start_date, end_date, lft, rgt), as_dict=1)
+		(start_date, end_date, all_sales_persons[sales_person].lft, all_sales_persons[sales_person].rgt, 
+			item_groups[target_item_group].lft, item_groups[target_item_group].rgt), as_dict=1)
 
-	item_actual_details = {}
+	actual_details = {}
 	for d in item_details:
-		item_group = item_groups[d.item_code]
-		item_actual_details.setdefault(item_group, frappe._dict()).setdefault(d.month_name,\
-			frappe._dict({
-				"quantity" : 0,
-				"amount" : 0
-			}))
+		actual_details.setdefault(d.month_name, frappe._dict({
+			"quantity" : 0,
+			"amount" : 0
+		}))
 
-		value_dict = item_actual_details[item_group][d.month_name]
+		value_dict = actual_details[d.month_name]
 		value_dict.quantity += flt(d.qty)
 		value_dict.amount += flt(d.amount)
 
-	return item_actual_details
+	return actual_details
 
 def get_salesperson_item_month_map(filters):
 	import datetime
 	salesperson_details = get_salesperson_details(filters)
 	tdd = get_target_distribution_details(filters)
 	item_groups = get_item_groups()
+	sales_persons = get_sales_persons()
 
 	sales_person_achievement_dict = {}
 	for sd in salesperson_details:
-		achieved_details = get_achieved_details(filters, sd.name, item_groups)
+		achieved_details = get_achieved_details(filters, sd.name, sales_persons, sd.item_group, item_groups)
 
 		for month_id in range(1, 13):
 			month = datetime.date(2013, month_id, 1).strftime('%B')
@@ -149,10 +148,26 @@
 			else:
 				sales_target_achieved.target = flt(sd.target_amount) * month_percentage / 100
 
-			sales_target_achieved.achieved = achieved_details.get(sd.item_group, frappe._dict()).\
-					get(month, frappe._dict()).get(filters["target_on"].lower())
+			sales_target_achieved.achieved = achieved_details.get(month, frappe._dict())\
+				.get(filters["target_on"].lower())
 
 	return sales_person_achievement_dict
 
 def get_item_groups():
-	return dict(frappe.get_all("Item", fields=["name", "item_group"], as_list=True))
+	item_groups = frappe._dict()
+	for d in frappe.get_all("Item Group", fields=["name", "lft", "rgt"]):
+		item_groups.setdefault(d.name, frappe._dict({
+			"lft": d.lft,
+			"rgt": d.rgt
+		}))
+	return item_groups
+
+def get_sales_persons():
+	sales_persons = frappe._dict()
+	for d in frappe.get_all("Sales Person", fields=["name", "lft", "rgt"]):
+		sales_persons.setdefault(d.name, frappe._dict({
+			"lft": d.lft,
+			"rgt": d.rgt
+		}))
+	return sales_persons	
+	
\ No newline at end of file
diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py
index 00ac76c..d32e14f 100644
--- a/erpnext/setup/doctype/company/delete_company_transactions.py
+++ b/erpnext/setup/doctype/company/delete_company_transactions.py
@@ -29,7 +29,7 @@
 
 		else:
 			# un-set company
-			frappe.db.sql('update `tab{0}` set company="" where company=%s', company_name)
+			frappe.db.sql('update `tab{0}` set company="" where company=%s'.format(doctype), company_name)
 
 	# Clear notification counts
 	clear_notifications()
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index 0b69d31..2078eeb 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -14,7 +14,7 @@
 	pass
 
 def get_product_bundle_items(item_code):
-	return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom
+	return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom, t1.description
 		from `tabProduct Bundle Item` t1, `tabProduct Bundle` t2
 		where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1)
 
@@ -27,14 +27,14 @@
 		where item_code = %s and warehouse = %s""", (item, warehouse), as_dict = 1)
 	return det and det[0] or frappe._dict()
 
-def update_packing_list_item(doc, packing_item_code, qty, main_item_row):
+def update_packing_list_item(doc, packing_item_code, qty, main_item_row, description):
 	bin = get_bin_qty(packing_item_code, main_item_row.warehouse)
 	item = get_packing_item_details(packing_item_code)
 
 	# check if exists
 	exists = 0
 	for d in doc.get("packed_items"):
-		if d.parent_item == main_item_row.item_code and d.item_code == packing_item_code and d.parent_detail_docname == main_item_row.name:
+		if d.parent_item == main_item_row.item_code and d.item_code == packing_item_code and d.parent_detail_docname == main_item_row.name and d.description == description:
 			pi, exists = d, 1
 			break
 
@@ -50,6 +50,7 @@
 	pi.qty = flt(qty)
 	pi.actual_qty = flt(bin.get("actual_qty"))
 	pi.projected_qty = flt(bin.get("projected_qty"))
+	pi.description = description
 	if not pi.warehouse:
 		pi.warehouse = main_item_row.warehouse
 	if not pi.batch_no:
@@ -66,7 +67,7 @@
 	for d in doc.get("items"):
 		if frappe.db.get_value("Product Bundle", {"new_item_code": d.item_code}):
 			for i in get_product_bundle_items(d.item_code):
-				update_packing_list_item(doc, i.item_code, flt(i.qty)*flt(d.qty), d)
+				update_packing_list_item(doc, i.item_code, flt(i.qty)*flt(d.qty), d, i.description)
 
 			if [d.item_code, d.name] not in parent_items:
 				parent_items.append([d.item_code, d.name])
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 22dbe51..6860486 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -164,7 +164,7 @@
 		"net_amount": 0.0,
 		"discount_percentage": 0.0,
 		"supplier": item.default_supplier,
-		"delivered_by_supplier": item.delivered_by_supplier,
+		"delivered_by_supplier": item.delivered_by_supplier
 	})
 
 	# if default specified in item is for another company, fetch from company
diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py
index cca2456..c637a12 100644
--- a/erpnext/stock/reorder_item.py
+++ b/erpnext/stock/reorder_item.py
@@ -48,7 +48,7 @@
 		# projected_qty will be 0 if Bin does not exist
 		projected_qty = flt(item_warehouse_projected_qty.get(item_code, {}).get(warehouse))
 
-		if reorder_level and projected_qty <= reorder_level:
+		if (reorder_level or reorder_qty) and projected_qty < reorder_level:
 			deficiency = reorder_level - projected_qty
 			if deficiency > reorder_qty:
 				reorder_qty = deficiency
diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
index dbbcb38..b21b402 100644
--- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
+++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
@@ -47,7 +47,7 @@
 				re_order_level = d.warehouse_reorder_level
 				re_order_qty = d.warehouse_reorder_qty
 
-		shortage_qty = re_order_level - flt(bin.projected_qty) if re_order_level else 0
+		shortage_qty = re_order_level - flt(bin.projected_qty) if (re_order_level or re_order_qty) else 0
 
 		data.append([item.name, item.item_name, item.description, item.item_group, item.brand, bin.warehouse,
 			item.stock_uom, bin.actual_qty, bin.planned_qty, bin.indented_qty, bin.ordered_qty,