Merge pull request #8172 from rohitwaghchaure/credit_note_serial_no_issue

[fix] During making credit note from sales invoice, system fetching new serial no instead of old serial no from the sales invoice
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index df6cb3c..887d5f8 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -5,6 +5,7 @@
 import frappe
 from frappe import _, scrub
 from erpnext.stock.utils import get_incoming_rate
+from erpnext.stock.stock_ledger import get_valuation_rate
 from frappe.utils import flt
 
 
@@ -220,7 +221,10 @@
 					from `tabPurchase Invoice Item`
 					where item_code = %s and docstatus=1""", item_code)[0][0])
 			else:
-				self.average_buying_rate[item_code] = get_incoming_rate(row)
+				average_buying_rate = get_incoming_rate(row)
+				if not average_buying_rate:
+					average_buying_rate = get_valuation_rate(item_code, row.warehouse, allow_zero_rate=True)
+				self.average_buying_rate[item_code] =  average_buying_rate
 
 		return self.average_buying_rate[item_code]
 
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index aaa0e95..bc166aa 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -42,7 +42,7 @@
 			select distinct so.name, so.transaction_date, so.customer, so.base_grand_total
 			from `tabSales Order` so, `tabSales Order Item` so_item
 			where so_item.parent = so.name
-				and so.docstatus = 1 and so.status != "Stopped"
+				and so.docstatus = 1 and so.status not in ("Stopped", "Closed")
 				and so.company = %(company)s
 				and so_item.qty > so_item.delivered_qty {0} {1}
 				and (exists (select name from `tabBOM` bom where bom.item=so_item.item_code