Merge pull request #35882 from ruthra-kumar/refactor_cr_note_reconciliation_with_exchange_gain_loss

refactor: simplify exchange logic on cr/dr note reconciliation
diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml
index e2d8957..aae2928 100644
--- a/.github/workflows/patch.yml
+++ b/.github/workflows/patch.yml
@@ -52,7 +52,7 @@
       - name: Setup Node
         uses: actions/setup-node@v2
         with:
-          node-version: 14
+          node-version: 18
           check-latest: true
 
       - name: Add to Hosts
diff --git a/.github/workflows/semantic-commits.yml b/.github/workflows/semantic-commits.yml
index 1744bc3..0e478d5 100644
--- a/.github/workflows/semantic-commits.yml
+++ b/.github/workflows/semantic-commits.yml
@@ -21,7 +21,7 @@
 
       - uses: actions/setup-node@v3
         with:
-          node-version: 14
+          node-version: 18
           check-latest: true
 
       - name: Check commit titles
diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml
index 8959f7f..9b4db49 100644
--- a/.github/workflows/server-tests-mariadb.yml
+++ b/.github/workflows/server-tests-mariadb.yml
@@ -71,7 +71,7 @@
       - name: Setup Node
         uses: actions/setup-node@v2
         with:
-          node-version: 14
+          node-version: 18
           check-latest: true
 
       - name: Add to Hosts
diff --git a/.github/workflows/server-tests-postgres.yml b/.github/workflows/server-tests-postgres.yml
index df43801..a688706 100644
--- a/.github/workflows/server-tests-postgres.yml
+++ b/.github/workflows/server-tests-postgres.yml
@@ -59,7 +59,7 @@
       - name: Setup Node
         uses: actions/setup-node@v2
         with:
-          node-version: 14
+          node-version: 18
           check-latest: true
 
       - name: Add to Hosts
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
index 8a6b021..6f0b6fc 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
@@ -68,6 +68,16 @@
 		frm.refresh_field("dimensions");
 		frm.trigger('setup_filters');
 	},
+	apply_restriction_on_values: function(frm) {
+		/** If restriction on values is not applied, we should set "allow_or_restrict" to "Restrict" with an empty allowed dimension table.
+		 * Hence it's not "restricted" on any value.
+		  */
+		if (!frm.doc.apply_restriction_on_values) {
+			frm.set_value("allow_or_restrict", "Restrict");
+			frm.clear_table("dimensions");
+			frm.refresh_field("dimensions");
+		}
+	}
 });
 
 frappe.ui.form.on('Allowed Dimension', {
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
index 0f3fbc0..2bd6c12 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
@@ -10,6 +10,7 @@
   "disabled",
   "column_break_2",
   "company",
+  "apply_restriction_on_values",
   "allow_or_restrict",
   "section_break_4",
   "accounts",
@@ -24,94 +25,80 @@
    "fieldtype": "Select",
    "in_list_view": 1,
    "label": "Accounting Dimension",
-   "reqd": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "reqd": 1
   },
   {
    "fieldname": "column_break_2",
-   "fieldtype": "Column Break",
-   "show_days": 1,
-   "show_seconds": 1
+   "fieldtype": "Column Break"
   },
   {
    "fieldname": "section_break_4",
    "fieldtype": "Section Break",
-   "hide_border": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "hide_border": 1
   },
   {
    "fieldname": "column_break_6",
-   "fieldtype": "Column Break",
-   "show_days": 1,
-   "show_seconds": 1
+   "fieldtype": "Column Break"
   },
   {
+   "depends_on": "eval:doc.apply_restriction_on_values == 1;",
    "fieldname": "allow_or_restrict",
    "fieldtype": "Select",
    "label": "Allow Or Restrict Dimension",
    "options": "Allow\nRestrict",
-   "reqd": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "reqd": 1
   },
   {
    "fieldname": "accounts",
    "fieldtype": "Table",
    "label": "Applicable On Account",
    "options": "Applicable On Account",
-   "reqd": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "reqd": 1
   },
   {
-   "depends_on": "eval:doc.accounting_dimension",
+   "depends_on": "eval:doc.accounting_dimension && doc.apply_restriction_on_values",
    "fieldname": "dimensions",
    "fieldtype": "Table",
    "label": "Applicable Dimension",
-   "options": "Allowed Dimension",
-   "reqd": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "mandatory_depends_on": "eval:doc.apply_restriction_on_values == 1;",
+   "options": "Allowed Dimension"
   },
   {
    "default": "0",
    "fieldname": "disabled",
    "fieldtype": "Check",
-   "label": "Disabled",
-   "show_days": 1,
-   "show_seconds": 1
+   "label": "Disabled"
   },
   {
    "fieldname": "company",
    "fieldtype": "Link",
    "label": "Company",
    "options": "Company",
-   "reqd": 1,
-   "show_days": 1,
-   "show_seconds": 1
+   "reqd": 1
   },
   {
    "fieldname": "dimension_filter_help",
    "fieldtype": "HTML",
-   "label": "Dimension Filter Help",
-   "show_days": 1,
-   "show_seconds": 1
+   "label": "Dimension Filter Help"
   },
   {
    "fieldname": "section_break_10",
-   "fieldtype": "Section Break",
-   "show_days": 1,
-   "show_seconds": 1
+   "fieldtype": "Section Break"
+  },
+  {
+   "default": "1",
+   "fieldname": "apply_restriction_on_values",
+   "fieldtype": "Check",
+   "label": "Apply restriction on dimension values"
   }
  ],
  "index_web_pages_for_search": 1,
  "links": [],
- "modified": "2021-02-03 12:04:58.678402",
+ "modified": "2023-06-07 14:59:41.869117",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Accounting Dimension Filter",
+ "naming_rule": "Expression",
  "owner": "Administrator",
  "permissions": [
   {
@@ -154,5 +141,6 @@
  "quick_entry": 1,
  "sort_field": "modified",
  "sort_order": "DESC",
+ "states": [],
  "track_changes": 1
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
index 80f736f..de1b82c 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
@@ -8,6 +8,12 @@
 
 
 class AccountingDimensionFilter(Document):
+	def before_save(self):
+		# If restriction is not applied on values, then remove all the dimensions and set allow_or_restrict to Restrict
+		if not self.apply_restriction_on_values:
+			self.allow_or_restrict = "Restrict"
+			self.set("dimensions", [])
+
 	def validate(self):
 		self.validate_applicable_accounts()
 
@@ -44,12 +50,12 @@
 			a.applicable_on_account, d.dimension_value, p.accounting_dimension,
 			p.allow_or_restrict, a.is_mandatory
 		FROM
-			`tabApplicable On Account` a, `tabAllowed Dimension` d,
+			`tabApplicable On Account` a,
 			`tabAccounting Dimension Filter` p
+		LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name
 		WHERE
 			p.name = a.parent
 			AND p.disabled = 0
-			AND p.name = d.parent
 	""",
 		as_dict=1,
 	)
@@ -76,4 +82,5 @@
 		(dimension, account),
 		{"allowed_dimensions": [], "is_mandatory": is_mandatory, "allow_or_restrict": allow_or_restrict},
 	)
-	map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)
+	if filter_value:
+		map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
index f13f2f9..6aba2ab 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
@@ -64,6 +64,7 @@
 				"accounting_dimension": "Cost Center",
 				"allow_or_restrict": "Allow",
 				"company": "_Test Company",
+				"apply_restriction_on_values": 1,
 				"accounts": [
 					{
 						"applicable_on_account": "Sales - _TC",
@@ -85,6 +86,7 @@
 				"doctype": "Accounting Dimension Filter",
 				"accounting_dimension": "Department",
 				"allow_or_restrict": "Allow",
+				"apply_restriction_on_values": 1,
 				"company": "_Test Company",
 				"accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}],
 				"dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}],
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 1f23fe1..712023f 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1735,7 +1735,7 @@
 		if not total_amount:
 			if party_account_currency == company_currency:
 				# for handling cases that don't have multi-currency (base field)
-				total_amount = ref_doc.get("grand_total") or ref_doc.get("base_grand_total")
+				total_amount = ref_doc.get("base_grand_total") or ref_doc.get("grand_total")
 				exchange_rate = 1
 			else:
 				total_amount = ref_doc.get("grand_total")
diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
index 278b12f..ae2625b 100644
--- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py
@@ -11,6 +11,7 @@
 from erpnext.accounts.doctype.payment_entry.payment_entry import (
 	InvalidPaymentEntry,
 	get_payment_entry,
+	get_reference_details,
 )
 from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import (
 	make_purchase_invoice,
@@ -1037,6 +1038,29 @@
 
 		self.assertRaises(frappe.ValidationError, pe_draft.submit)
 
+	def test_details_update_on_reference_table(self):
+		so = make_sales_order(
+			customer="_Test Customer USD", currency="USD", qty=1, rate=100, do_not_submit=True
+		)
+		so.conversion_rate = 50
+		so.submit()
+		pe = get_payment_entry("Sales Order", so.name)
+		pe.references.clear()
+		pe.paid_from = "Debtors - _TC"
+		pe.paid_from_account_currency = "INR"
+		pe.source_exchange_rate = 50
+		pe.save()
+
+		ref_details = get_reference_details(so.doctype, so.name, pe.paid_from_account_currency)
+		expected_response = {
+			"total_amount": 5000.0,
+			"outstanding_amount": 5000.0,
+			"exchange_rate": 1.0,
+			"due_date": None,
+			"bill_no": None,
+		}
+		self.assertDictEqual(ref_details, expected_response)
+
 
 def create_payment_entry(**args):
 	payment_entry = frappe.new_doc("Payment Entry")
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
index e6d9fe2..a6c0102 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
@@ -123,22 +123,29 @@
 			row.expected_amount = row.opening_amount;
 		}
 
-		const pos_inv_promises = frm.doc.pos_transactions.map(
-			row => frappe.db.get_doc("POS Invoice", row.pos_invoice)
-		);
-
-		const pos_invoices = await Promise.all(pos_inv_promises);
-
-		for (let doc of pos_invoices) {
-			frm.doc.grand_total += flt(doc.grand_total);
-			frm.doc.net_total += flt(doc.net_total);
-			frm.doc.total_quantity += flt(doc.total_qty);
-			refresh_payments(doc, frm);
-			refresh_taxes(doc, frm);
-			refresh_fields(frm);
-			set_html_data(frm);
-		}
-
+		await Promise.all([
+			frappe.call({
+				method: 'erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices',
+				args: {
+					start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date),
+					end: frappe.datetime.get_datetime_as_string(frm.doc.period_end_date),
+					pos_profile: frm.doc.pos_profile,
+					user: frm.doc.user
+				},
+				callback: (r) => {
+					let pos_invoices = r.message;
+					for (let doc of pos_invoices) {
+						frm.doc.grand_total += flt(doc.grand_total);
+						frm.doc.net_total += flt(doc.net_total);
+						frm.doc.total_quantity += flt(doc.total_qty);
+						refresh_payments(doc, frm);
+						refresh_taxes(doc, frm);
+						refresh_fields(frm);
+						set_html_data(frm);
+					}
+				}
+			})
+		])
 		frappe.dom.unfreeze();
 	}
 });
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
index 03abc93..5307ccb 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
@@ -1,6 +1,6 @@
 <div class="page-break">
 	<div id="header-html" class="hidden-pdf">
-		{% if letter_head %}
+		{% if letter_head.content %}
 		<div class="letter-head text-center">{{ letter_head.content }}</div>
 		<hr style="height:2px;border-width:0;color:black;background-color:black;">
 		{% endif %}
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
index 7dd5ef3..cec48c1 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
@@ -65,6 +65,20 @@
 			frm.set_value('to_date', frappe.datetime.get_today());
 		}
 	},
+	report: function(frm){
+		let filters = {
+			'company': frm.doc.company,
+		}
+		if(frm.doc.report == 'Accounts Receivable'){
+			filters['account_type'] = 'Receivable';
+		}
+		frm.set_query("account", function() {
+			return {
+				filters: filters
+			};
+		});
+
+	},
 	customer_collection: function(frm){
 		frm.set_value('collection_name', '');
 		if(frm.doc.customer_collection){
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
index e23620f..8004659 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
@@ -6,17 +6,24 @@
  "editable_grid": 1,
  "engine": "InnoDB",
  "field_order": [
+  "report",
   "section_break_11",
   "from_date",
+  "posting_date",
   "company",
   "account",
   "group_by",
   "cost_center",
+  "territory",
   "column_break_14",
   "to_date",
   "finance_book",
   "currency",
   "project",
+  "payment_terms_template",
+  "sales_partner",
+  "sales_person",
+  "based_on_payment_terms",
   "section_break_3",
   "customer_collection",
   "collection_name",
@@ -67,14 +74,14 @@
    "reqd": 1
   },
   {
-   "depends_on": "eval:doc.enable_auto_email == 0;",
+   "depends_on": "eval:(doc.enable_auto_email == 0 && doc.report == 'General Ledger');",
    "fieldname": "from_date",
    "fieldtype": "Date",
    "label": "From Date",
    "mandatory_depends_on": "eval:doc.frequency == '';"
   },
   {
-   "depends_on": "eval:doc.enable_auto_email == 0;",
+   "depends_on": "eval:(doc.enable_auto_email == 0 && doc.report == 'General Ledger');",
    "fieldname": "to_date",
    "fieldtype": "Date",
    "label": "To Date",
@@ -87,6 +94,7 @@
    "options": "PSOA Cost Center"
   },
   {
+   "depends_on": "eval: (doc.report == 'General Ledger');",
    "fieldname": "project",
    "fieldtype": "Table MultiSelect",
    "label": "Project",
@@ -104,7 +112,7 @@
   {
    "fieldname": "section_break_11",
    "fieldtype": "Section Break",
-   "label": "General Ledger Filters"
+   "label": "Report Filters"
   },
   {
    "fieldname": "column_break_14",
@@ -164,12 +172,14 @@
   },
   {
    "default": "Group by Voucher (Consolidated)",
+   "depends_on": "eval:(doc.report == 'General Ledger');",
    "fieldname": "group_by",
    "fieldtype": "Select",
    "label": "Group By",
    "options": "\nGroup by Voucher\nGroup by Voucher (Consolidated)"
   },
   {
+   "depends_on": "eval: (doc.report == 'General Ledger');",
    "fieldname": "currency",
    "fieldtype": "Link",
    "label": "Currency",
@@ -297,6 +307,7 @@
   },
   {
    "default": "0",
+   "depends_on": "eval: (doc.report == 'General Ledger');",
    "fieldname": "show_net_values_in_party_account",
    "fieldtype": "Check",
    "label": "Show Net Values in Party Account"
@@ -310,10 +321,59 @@
   {
    "fieldname": "column_break_ocfq",
    "fieldtype": "Column Break"
+  },
+  {
+   "fieldname": "report",
+   "fieldtype": "Select",
+   "label": "Report",
+   "options": "General Ledger\nAccounts Receivable",
+   "reqd": 1
+  },
+  {
+   "default": "Today",
+   "depends_on": "eval:(doc.report == 'Accounts Receivable');",
+   "fieldname": "posting_date",
+   "fieldtype": "Date",
+   "label": "Posting Date"
+  },
+  {
+   "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+   "fieldname": "payment_terms_template",
+   "fieldtype": "Link",
+   "label": "Payment Terms Template",
+   "options": "Payment Terms Template"
+  },
+  {
+   "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+   "fieldname": "sales_partner",
+   "fieldtype": "Link",
+   "label": "Sales Partner",
+   "options": "Sales Partner"
+  },
+  {
+   "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+   "fieldname": "sales_person",
+   "fieldtype": "Link",
+   "label": "Sales Person",
+   "options": "Sales Person"
+  },
+  {
+   "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+   "fieldname": "territory",
+   "fieldtype": "Link",
+   "label": "Territory",
+   "options": "Territory"
+  },
+  {
+   "default": "0",
+   "depends_on": "eval:(doc.report == 'Accounts Receivable');",
+   "fieldname": "based_on_payment_terms",
+   "fieldtype": "Check",
+   "label": "Based On Payment Terms"
   }
  ],
  "links": [],
- "modified": "2023-04-26 12:46:43.645455",
+ "modified": "2023-06-23 10:13:15.051950",
  "modified_by": "Administrator",
  "module": "Accounts",
  "name": "Process Statement Of Accounts",
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
index 67dbe09..08f4cf4 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
@@ -15,6 +15,7 @@
 
 from erpnext import get_company_currency
 from erpnext.accounts.party import get_party_account_currency
+from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute as get_ar_soa
 from erpnext.accounts.report.accounts_receivable_summary.accounts_receivable_summary import (
 	execute as get_ageing,
 )
@@ -43,29 +44,10 @@
 def get_report_pdf(doc, consolidated=True):
 	statement_dict = {}
 	ageing = ""
-	base_template_path = "frappe/www/printview.html"
-	template_path = (
-		"erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html"
-	)
 
 	for entry in doc.customers:
 		if doc.include_ageing:
-			ageing_filters = frappe._dict(
-				{
-					"company": doc.company,
-					"report_date": doc.to_date,
-					"ageing_based_on": doc.ageing_based_on,
-					"range1": 30,
-					"range2": 60,
-					"range3": 90,
-					"range4": 120,
-					"customer": entry.customer,
-				}
-			)
-			col1, ageing = get_ageing(ageing_filters)
-
-			if ageing:
-				ageing[0]["ageing_based_on"] = doc.ageing_based_on
+			ageing = set_ageing(doc, entry)
 
 		tax_id = frappe.get_doc("Customer", entry.customer).tax_id
 		presentation_currency = (
@@ -73,60 +55,25 @@
 			or doc.currency
 			or get_company_currency(doc.company)
 		)
-		if doc.letter_head:
-			from frappe.www.printview import get_letter_head
 
-			letter_head = get_letter_head(doc, 0)
+		filters = get_common_filters(doc)
 
-		filters = frappe._dict(
-			{
-				"from_date": doc.from_date,
-				"to_date": doc.to_date,
-				"company": doc.company,
-				"finance_book": doc.finance_book if doc.finance_book else None,
-				"account": [doc.account] if doc.account else None,
-				"party_type": "Customer",
-				"party": [entry.customer],
-				"party_name": [entry.customer_name] if entry.customer_name else None,
-				"presentation_currency": presentation_currency,
-				"group_by": doc.group_by,
-				"currency": doc.currency,
-				"cost_center": [cc.cost_center_name for cc in doc.cost_center],
-				"project": [p.project_name for p in doc.project],
-				"show_opening_entries": 0,
-				"include_default_book_entries": 0,
-				"tax_id": tax_id if tax_id else None,
-				"show_net_values_in_party_account": doc.show_net_values_in_party_account,
-			}
-		)
-		col, res = get_soa(filters)
+		if doc.report == "General Ledger":
+			filters.update(get_gl_filters(doc, entry, tax_id, presentation_currency))
+		else:
+			filters.update(get_ar_filters(doc, entry))
 
-		for x in [0, -2, -1]:
-			res[x]["account"] = res[x]["account"].replace("'", "")
+		if doc.report == "General Ledger":
+			col, res = get_soa(filters)
+			for x in [0, -2, -1]:
+				res[x]["account"] = res[x]["account"].replace("'", "")
+			if len(res) == 3:
+				continue
+		else:
+			ar_res = get_ar_soa(filters)
+			col, res = ar_res[0], ar_res[1]
 
-		if len(res) == 3:
-			continue
-
-		html = frappe.render_template(
-			template_path,
-			{
-				"filters": filters,
-				"data": res,
-				"ageing": ageing[0] if (doc.include_ageing and ageing) else None,
-				"letter_head": letter_head if doc.letter_head else None,
-				"terms_and_conditions": frappe.db.get_value(
-					"Terms and Conditions", doc.terms_and_conditions, "terms"
-				)
-				if doc.terms_and_conditions
-				else None,
-			},
-		)
-
-		html = frappe.render_template(
-			base_template_path,
-			{"body": html, "css": get_print_style(), "title": "Statement For " + entry.customer},
-		)
-		statement_dict[entry.customer] = html
+		statement_dict[entry.customer] = get_html(doc, filters, entry, col, res, ageing)
 
 	if not bool(statement_dict):
 		return False
@@ -140,6 +87,110 @@
 		return statement_dict
 
 
+def set_ageing(doc, entry):
+	ageing_filters = frappe._dict(
+		{
+			"company": doc.company,
+			"report_date": doc.to_date,
+			"ageing_based_on": doc.ageing_based_on,
+			"range1": 30,
+			"range2": 60,
+			"range3": 90,
+			"range4": 120,
+			"customer": entry.customer,
+		}
+	)
+	col1, ageing = get_ageing(ageing_filters)
+
+	if ageing:
+		ageing[0]["ageing_based_on"] = doc.ageing_based_on
+
+	return ageing
+
+
+def get_common_filters(doc):
+	return frappe._dict(
+		{
+			"company": doc.company,
+			"finance_book": doc.finance_book if doc.finance_book else None,
+			"account": [doc.account] if doc.account else None,
+			"cost_center": [cc.cost_center_name for cc in doc.cost_center],
+		}
+	)
+
+
+def get_gl_filters(doc, entry, tax_id, presentation_currency):
+	return {
+		"from_date": doc.from_date,
+		"to_date": doc.to_date,
+		"party_type": "Customer",
+		"party": [entry.customer],
+		"party_name": [entry.customer_name] if entry.customer_name else None,
+		"presentation_currency": presentation_currency,
+		"group_by": doc.group_by,
+		"currency": doc.currency,
+		"project": [p.project_name for p in doc.project],
+		"show_opening_entries": 0,
+		"include_default_book_entries": 0,
+		"tax_id": tax_id if tax_id else None,
+		"show_net_values_in_party_account": doc.show_net_values_in_party_account,
+	}
+
+
+def get_ar_filters(doc, entry):
+	return {
+		"report_date": doc.posting_date if doc.posting_date else None,
+		"customer_name": entry.customer,
+		"payment_terms_template": doc.payment_terms_template if doc.payment_terms_template else None,
+		"sales_partner": doc.sales_partner if doc.sales_partner else None,
+		"sales_person": doc.sales_person if doc.sales_person else None,
+		"territory": doc.territory if doc.territory else None,
+		"based_on_payment_terms": doc.based_on_payment_terms,
+		"report_name": "Accounts Receivable",
+		"ageing_based_on": doc.ageing_based_on,
+		"range1": 30,
+		"range2": 60,
+		"range3": 90,
+		"range4": 120,
+	}
+
+
+def get_html(doc, filters, entry, col, res, ageing):
+	base_template_path = "frappe/www/printview.html"
+	template_path = (
+		"erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html"
+		if doc.report == "General Ledger"
+		else "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html"
+	)
+
+	if doc.letter_head:
+		from frappe.www.printview import get_letter_head
+
+		letter_head = get_letter_head(doc, 0)
+
+	html = frappe.render_template(
+		template_path,
+		{
+			"filters": filters,
+			"data": res,
+			"report": {"report_name": doc.report, "columns": col},
+			"ageing": ageing[0] if (doc.include_ageing and ageing) else None,
+			"letter_head": letter_head if doc.letter_head else None,
+			"terms_and_conditions": frappe.db.get_value(
+				"Terms and Conditions", doc.terms_and_conditions, "terms"
+			)
+			if doc.terms_and_conditions
+			else None,
+		},
+	)
+
+	html = frappe.render_template(
+		base_template_path,
+		{"body": html, "css": get_print_style(), "title": "Statement For " + entry.customer},
+	)
+	return html
+
+
 def get_customers_based_on_territory_or_customer_group(customer_collection, collection_name):
 	fields_dict = {
 		"Customer Group": "customer_group",
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html
new file mode 100644
index 0000000..07e1896
--- /dev/null
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html
@@ -0,0 +1,348 @@
+<style>
+	.print-format {
+		padding: 4mm;
+		font-size: 8.0pt !important;
+	}
+	.print-format td {
+		vertical-align:middle !important;
+	}
+	</style>
+
+	<h2 class="text-center" style="margin-top:0">{{ _(report.report_name) }}</h2>
+	<h4 class="text-center">
+		{% if (filters.customer_name) %}
+			{{ filters.customer_name }}
+		{% else %}
+			{{ filters.customer ~ filters.supplier }}
+		{% endif %}
+	</h4>
+	<h6 class="text-center">
+			{% if (filters.tax_id) %}
+			{{ _("Tax Id: ") }}{{ filters.tax_id }}
+			{% endif %}
+	</h6>
+	<h5 class="text-center">
+		{{ _(filters.ageing_based_on) }}
+		{{ _("Until") }}
+		{{ frappe.format(filters.report_date, 'Date') }}
+	</h5>
+
+	<div class="clearfix">
+		<div class="pull-left">
+		{% if(filters.payment_terms) %}
+			<strong>{{ _("Payment Terms") }}:</strong> {{ filters.payment_terms }}
+		{% endif %}
+		</div>
+		<div class="pull-right">
+		{% if(filters.credit_limit) %}
+			<strong>{{ _("Credit Limit") }}:</strong> {{ frappe.utils.fmt_money(filters.credit_limit) }}
+		{% endif %}
+		</div>
+	</div>
+
+	{% if(filters.show_future_payments) %}
+		{% set balance_row = data.slice(-1).pop() %}
+		{% for i in report.columns %}
+			{% if i.fieldname == 'age' %}
+				{% set elem = i %}
+			{% endif %}
+		{% endfor %}
+		{% set start = report.columns.findIndex(elem) %}
+		{% set range1 = report.columns[start].label %}
+		{% set range2 = report.columns[start+1].label %}
+		{% set range3 = report.columns[start+2].label %}
+		{% set range4 = report.columns[start+3].label %}
+		{% set range5 = report.columns[start+4].label %}
+		{% set range6 = report.columns[start+5].label %}
+
+		{% if(balance_row) %}
+		<table class="table table-bordered table-condensed">
+			<caption class="text-right">(Amount in {{ data[0]["currency"] ~ "" }})</caption>
+				<colgroup>
+					<col style="width: 30mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+					<col style="width: 18mm;">
+				</colgroup>
+
+			<thead>
+				<tr>
+					<th>{{ _(" ") }}</th>
+					<th>{{ _(range1) }}</th>
+					<th>{{ _(range2) }}</th>
+					<th>{{ _(range3) }}</th>
+					<th>{{ _(range4) }}</th>
+					<th>{{ _(range5) }}</th>
+					<th>{{ _(range6) }}</th>
+					<th>{{ _("Total") }}</th>
+				</tr>
+			</thead>
+			<tbody>
+				<tr>
+					<td>{{ _("Total Outstanding") }}</td>
+					<td class="text-right">
+						{{ format_number(balance_row["age"], null, 2) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(balance_row["range1"], data[data.length-1]["currency"]) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(balance_row["range2"], data[data.length-1]["currency"]) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(balance_row["range3"], data[data.length-1]["currency"]) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(balance_row["range4"], data[data.length-1]["currency"]) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(balance_row["range5"], data[data.length-1]["currency"]) }}
+					</td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(flt(balance_row["outstanding"]), data[data.length-1]["currency"]) }}
+					</td>
+				</tr>
+					<td>{{ _("Future Payments") }}</td>
+					<td></td>
+					<td></td>
+					<td></td>
+					<td></td>
+					<td></td>
+					<td></td>
+					<td class="text-right">
+						{{ frappe.utils.fmt_money(flt(balance_row[("future_amount")]), data[data.length-1]["currency"]) }}
+					</td>
+				<tr class="cvs-footer">
+					<th class="text-left">{{ _("Cheques Required") }}</th>
+					<th></th>
+					<th></th>
+					<th></th>
+					<th></th>
+					<th></th>
+					<th></th>
+					<th class="text-right">
+						{{ frappe.utils.fmt_money(flt(balance_row["outstanding"] - balance_row[("future_amount")]), data[data.length-1]["currency"]) }}</th>
+				</tr>
+			</tbody>
+
+		</table>
+		{% endif %}
+	{% endif %}
+	<table class="table table-bordered">
+		<thead>
+			<tr>
+				{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
+					<th style="width: 10%">{{ _("Date") }}</th>
+					<th style="width: 4%">{{ _("Age (Days)") }}</th>
+
+					{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+						<th style="width: 14%">{{ _("Reference") }}</th>
+						<th style="width: 10%">{{ _("Sales Person") }}</th>
+					{% else %}
+						<th style="width: 24%">{{ _("Reference") }}</th>
+					{% endif %}
+					{% if not(filters.show_future_payments) %}
+						<th style="width: 20%">
+						{% if (filters.customer or filters.supplier or filters.customer_name) %}
+							{{ _("Remarks") }}
+						{% else %}
+							{{ _("Party") }}
+						{% endif %}
+						</th>
+					{% endif %}
+					<th style="width: 10%; text-align: right">{{ _("Invoiced Amount") }}</th>
+					{% if not(filters.show_future_payments) %}
+						<th style="width: 10%; text-align: right">{{ _("Paid Amount") }}</th>
+						<th style="width: 10%; text-align: right">
+							{% if report.report_name == "Accounts Receivable" %}
+								{{ _('Credit Note') }}
+							{% else %}
+								{{ _('Debit Note') }}
+							{% endif %}
+						</th>
+					{% endif %}
+					<th style="width: 10%; text-align: right">{{ _("Outstanding Amount") }}</th>
+					{% if(filters.show_future_payments) %}
+						{% if(report.report_name == "Accounts Receivable") %}
+							<th style="width: 12%">{{ _("Customer LPO No.") }}</th>
+						{% endif %}
+						<th style="width: 10%">{{ _("Future Payment Ref") }}</th>
+						<th style="width: 10%">{{ _("Future Payment Amount") }}</th>
+						<th style="width: 10%">{{ _("Remaining Balance") }}</th>
+					{% endif %}
+				{% else %}
+					<th style="width: 40%">
+						{% if (filters.customer or filters.supplier or filters.customer_name) %}
+							{{ _("Remarks")}}
+						{% else %}
+							{{ _("Party") }}
+						{% endif %}
+					</th>
+					<th style="width: 15%">{{ _("Total Invoiced Amount") }}</th>
+					<th style="width: 15%">{{ _("Total Paid Amount") }}</th>
+					<th style="width: 15%">
+						{% if report.report_name == "Accounts Receivable Summary" %}
+							{{ _('Credit Note Amount') }}
+						{% else %}
+							{{ _('Debit Note Amount') }}
+						{% endif %}
+					</th>
+					<th style="width: 15%">{{ _("Total Outstanding Amount") }}</th>
+				{% endif %}
+			</tr>
+		</thead>
+		<tbody>
+			{% for i in range(data|length) %}
+				<tr>
+				{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
+					{% if(data[i]["party"]) %}
+						<td>{{ (data[i]["posting_date"]) }}</td>
+						<td style="text-align: right">{{ data[i]["age"] }}</td>
+						<td>
+							{% if not(filters.show_future_payments) %}
+								{{ data[i]["voucher_type"] }}
+								<br>
+							{% endif %}
+							{{ data[i]["voucher_no"] }}
+						</td>
+
+						{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+						<td>{{ data[i]["sales_person"] }}</td>
+						{% endif %}
+
+						{% if not (filters.show_future_payments) %}
+						<td>
+							{% if(not(filters.customer or filters.supplier or filters.customer_name)) %}
+								{{ data[i]["party"] }}
+								{% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
+									<br> {{ data[i]["customer_name"] }}
+								{% elif(data[i]["supplier_name"] != data[i]["party"]) %}
+									<br> {{ data[i]["supplier_name"] }}
+								{% endif %}
+							{% endif %}
+							<div>
+							{% if data[i]["remarks"] %}
+								{{ _("Remarks") }}:
+								{{ data[i]["remarks"] }}
+							{% endif %}
+							</div>
+						</td>
+						{% endif %}
+
+						<td style="text-align: right">
+							{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
+
+						{% if not(filters.show_future_payments) %}
+							<td style="text-align: right">
+								{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+							<td style="text-align: right">
+								{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
+						{% endif %}
+						<td style="text-align: right">
+							{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+
+						{% if(filters.show_future_payments) %}
+							{% if(report.report_name == "Accounts Receivable") %}
+								<td style="text-align: right">
+									{{ data[i]["po_no"] }}</td>
+							{% endif %}
+							<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
+							<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
+							<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
+						{% endif %}
+					{% else %}
+						<td></td>
+						{% if not(filters.show_future_payments) %}
+						<td></td>
+						{% endif %}
+						{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+						<td></td>
+						{% endif %}
+						<td></td>
+						<td style="text-align: right"><b>{{ _("Total") }}</b></td>
+						<td style="text-align: right">
+							{{ frappe.utils.fmt_money(data[i]["invoiced"], data[i]["currency"]) }}</td>
+
+						{% if not(filters.show_future_payments) %}
+							<td style="text-align: right">
+								{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+							<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }} </td>
+						{% endif %}
+						<td style="text-align: right">
+							{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+
+						{% if(filters.show_future_payments) %}
+							{% if(report.report_name == "Accounts Receivable") %}
+								<td style="text-align: right">
+									{{ data[i]["po_no"] }}</td>
+							{% endif %}
+							<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
+							<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
+							<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
+						{% endif %}
+					{% endif %}
+				{% else %}
+					{% if(data[i]["party"] or "&nbsp;") %}
+						{% if not(data[i]["is_total_row"]) %}
+							<td>
+								{% if(not(filters.customer | filters.supplier)) %}
+									{{ data[i]["party"] }}
+									{% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
+										<br> {{ data[i]["customer_name"] }}
+									{% elif(data[i]["supplier_name"] != data[i]["party"]) %}
+										<br> {{ data[i]["supplier_name"] }}
+									{% endif %}
+								{% endif %}
+								<br>{{ _("Remarks") }}:
+								{{ data[i]["remarks"] }}
+							</td>
+						{% else %}
+							<td><b>{{ _("Total") }}</b></td>
+						{% endif %}
+						<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
+						<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+						<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
+						<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+					{% endif %}
+				{% endif %}
+				</tr>
+			{% endfor %}
+			<td></td>
+			<td></td>
+			<td></td>
+			<td></td>
+			<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="invoiced"), currency=data[0]["currency"]) }}</b></td>
+			<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="paid"), currency=data[0]["currency"]) }}</b></td>
+			<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="credit_note"), currency=data[0]["currency"]) }}</b></td>
+			<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="outstanding"), currency=data[0]["currency"]) }}</b></td>
+		</tbody>
+	</table>
+	<br>
+	{% if ageing %}
+	<h4 class="text-center">{{ _("Ageing Report based on ") }} {{ ageing.ageing_based_on }}
+		{{ _("up to " ) }}  {{ frappe.format(filters.report_date, 'Date')}}
+	</h4>
+	<table class="table table-bordered">
+		<thead>
+			<tr>
+				<th style="width: 25%">30 Days</th>
+				<th style="width: 25%">60 Days</th>
+				<th style="width: 25%">90 Days</th>
+				<th style="width: 25%">120 Days</th>
+			</tr>
+		</thead>
+		<tbody>
+			<tr>
+				<td>{{ frappe.utils.fmt_money(ageing.range1, currency=data[0]["currency"]) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range2, currency=data[0]["currency"]) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range3, currency=data[0]["currency"]) }}</td>
+				<td>{{ frappe.utils.fmt_money(ageing.range4, currency=data[0]["currency"]) }}</td>
+			</tr>
+		</tbody>
+	</table>
+	{% endif %}
+	<p class="text-right text-muted">{{ _("Printed On ") }}{{ frappe.utils.now() }}</p>
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
index f2bf942..ed3b991 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
@@ -284,4 +284,4 @@
 			{% } %}
 		</tbody>
 	</table>
-	<p class="text-right text-muted">{{ __("Printed On ") }}{%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
+	<p class="text-right text-muted">{{ __("Printed On ") }}{%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
\ No newline at end of file
diff --git a/erpnext/controllers/print_settings.py b/erpnext/controllers/print_settings.py
index c951154..d86607d 100644
--- a/erpnext/controllers/print_settings.py
+++ b/erpnext/controllers/print_settings.py
@@ -10,6 +10,7 @@
 	doc.child_print_templates = {
 		"items": {
 			"qty": "templates/print_formats/includes/item_table_qty.html",
+			"serial_and_batch_bundle": "templates/print_formats/includes/serial_and_batch_bundle.html",
 		}
 	}
 
diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
index 123a82a..a3f0d00 100644
--- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
+++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
@@ -30,7 +30,7 @@
 			"fieldname":"based_on_document",
 			"label": __("Based On Document"),
 			"fieldtype": "Select",
-			"options": ["Sales Order", "Delivery Note", "Quotation"],
+			"options": ["Sales Order", "Sales Invoice", "Delivery Note", "Quotation"],
 			"default": "Sales Order",
 			"reqd": 1
 		},
diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
index d3bce83..daef7f6 100644
--- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
+++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
@@ -99,7 +99,9 @@
 		parent = frappe.qb.DocType(self.doctype)
 		child = frappe.qb.DocType(self.child_doctype)
 
-		date_field = "posting_date" if self.doctype == "Delivery Note" else "transaction_date"
+		date_field = (
+			"posting_date" if self.doctype in ("Delivery Note", "Sales Invoice") else "transaction_date"
+		)
 
 		query = (
 			frappe.qb.from_(parent)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 18bd10f..8c0fa6b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -339,3 +339,4 @@
 execute:frappe.delete_doc('DocType', 'Cash Flow Mapping Template', ignore_missing=True)
 execute:frappe.delete_doc('DocType', 'Cash Flow Mapping Accounts', ignore_missing=True)
 erpnext.patches.v14_0.cleanup_workspaces
+erpnext.patches.v14_0.set_report_in_process_SOA 
diff --git a/erpnext/patches/v14_0/set_report_in_process_SOA.py b/erpnext/patches/v14_0/set_report_in_process_SOA.py
new file mode 100644
index 0000000..9eb5e3a
--- /dev/null
+++ b/erpnext/patches/v14_0/set_report_in_process_SOA.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
+# License: MIT. See LICENSE
+
+import frappe
+
+
+def execute():
+	process_soa = frappe.qb.DocType("Process Statement Of Accounts")
+	q = frappe.qb.update(process_soa).set(process_soa.report, "General Ledger")
+	q.run()
diff --git a/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py b/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py
index 5c46bf3..a53adf1 100644
--- a/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py
+++ b/erpnext/patches/v15_0/create_asset_depreciation_schedules_from_assets.py
@@ -6,10 +6,14 @@
 
 	assets = get_details_of_draft_or_submitted_depreciable_assets()
 
-	for asset in assets:
-		finance_book_rows = get_details_of_asset_finance_books_rows(asset.name)
+	asset_finance_books_map = get_asset_finance_books_map()
 
-		for fb_row in finance_book_rows:
+	asset_depreciation_schedules_map = get_asset_depreciation_schedules_map()
+
+	for asset in assets:
+		depreciation_schedules = asset_depreciation_schedules_map[asset.name]
+
+		for fb_row in asset_finance_books_map[asset.name]:
 			asset_depr_schedule_doc = frappe.new_doc("Asset Depreciation Schedule")
 
 			asset_depr_schedule_doc.set_draft_asset_depr_schedule_details(asset, fb_row)
@@ -19,7 +23,11 @@
 			if asset.docstatus == 1:
 				asset_depr_schedule_doc.submit()
 
-			update_depreciation_schedules(asset.name, asset_depr_schedule_doc.name, fb_row.idx)
+			depreciation_schedules_of_fb_row = [
+				ds for ds in depreciation_schedules if ds["finance_book_id"] == str(fb_row.idx)
+			]
+
+			update_depreciation_schedules(depreciation_schedules_of_fb_row, asset_depr_schedule_doc.name)
 
 
 def get_details_of_draft_or_submitted_depreciable_assets():
@@ -41,12 +49,33 @@
 	return records
 
 
-def get_details_of_asset_finance_books_rows(asset_name):
+def group_records_by_asset_name(records):
+	grouped_dict = {}
+
+	for item in records:
+		key = list(item.keys())[0]
+		value = item[key]
+
+		if value not in grouped_dict:
+			grouped_dict[value] = []
+
+		del item["asset_name"]
+
+		grouped_dict[value].append(item)
+
+	return grouped_dict
+
+
+def get_asset_finance_books_map():
 	afb = frappe.qb.DocType("Asset Finance Book")
+	asset = frappe.qb.DocType("Asset")
 
 	records = (
 		frappe.qb.from_(afb)
+		.join(asset)
+		.on(afb.parent == asset.name)
 		.select(
+			asset.name.as_("asset_name"),
 			afb.finance_book,
 			afb.idx,
 			afb.depreciation_method,
@@ -55,23 +84,44 @@
 			afb.rate_of_depreciation,
 			afb.expected_value_after_useful_life,
 		)
-		.where(afb.parent == asset_name)
+		.where(asset.docstatus < 2)
+		.orderby(afb.idx)
 	).run(as_dict=True)
 
-	return records
+	asset_finance_books_map = group_records_by_asset_name(records)
+
+	return asset_finance_books_map
 
 
-def update_depreciation_schedules(asset_name, asset_depr_schedule_name, fb_row_idx):
+def get_asset_depreciation_schedules_map():
 	ds = frappe.qb.DocType("Depreciation Schedule")
+	asset = frappe.qb.DocType("Asset")
 
-	depr_schedules = (
+	records = (
 		frappe.qb.from_(ds)
-		.select(ds.name)
-		.where((ds.parent == asset_name) & (ds.finance_book_id == str(fb_row_idx)))
+		.join(asset)
+		.on(ds.parent == asset.name)
+		.select(
+			asset.name.as_("asset_name"),
+			ds.name,
+			ds.finance_book_id,
+		)
+		.where(asset.docstatus < 2)
 		.orderby(ds.idx)
 	).run(as_dict=True)
 
-	for idx, depr_schedule in enumerate(depr_schedules, start=1):
+	asset_depreciation_schedules_map = group_records_by_asset_name(records)
+
+	return asset_depreciation_schedules_map
+
+
+def update_depreciation_schedules(
+	depreciation_schedules,
+	asset_depr_schedule_name,
+):
+	ds = frappe.qb.DocType("Depreciation Schedule")
+
+	for idx, depr_schedule in enumerate(depreciation_schedules, start=1):
 		(
 			frappe.qb.update(ds)
 			.set(ds.idx, idx)
diff --git a/erpnext/stock/doctype/item_reorder/item_reorder.json b/erpnext/stock/doctype/item_reorder/item_reorder.json
index fb4c558..a03bd45 100644
--- a/erpnext/stock/doctype/item_reorder/item_reorder.json
+++ b/erpnext/stock/doctype/item_reorder/item_reorder.json
@@ -81,7 +81,7 @@
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -147,7 +147,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-28 19:15:38.270046", 
+ "modified": "2023-06-21 15:13:38.270046", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item Reorder", 
@@ -158,4 +158,4 @@
  "read_only_onload": 0, 
  "sort_order": "ASC", 
  "track_seen": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/stock/print_format/purchase_receipt_serial_and_batch_bundle_print/purchase_receipt_serial_and_batch_bundle_print.json b/erpnext/stock/print_format/purchase_receipt_serial_and_batch_bundle_print/purchase_receipt_serial_and_batch_bundle_print.json
index 21132e0..a8ab8f6 100644
--- a/erpnext/stock/print_format/purchase_receipt_serial_and_batch_bundle_print/purchase_receipt_serial_and_batch_bundle_print.json
+++ b/erpnext/stock/print_format/purchase_receipt_serial_and_batch_bundle_print/purchase_receipt_serial_and_batch_bundle_print.json
@@ -8,14 +8,14 @@
  "docstatus": 0,
  "doctype": "Print Format",
  "font_size": 14,
- "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\t\\t\\t\\t<h2><div>Purchase Receipt</div><br><small class=\\\"sub-heading\\\">{{ doc.name }}</small>\\t\\t\\t\\t</h2></div>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"supplier_name\", \"print_hide\": 0, \"label\": \"Supplier Name\"}, {\"fieldname\": \"supplier_delivery_note\", \"print_hide\": 0, \"label\": \"Supplier Delivery Note\"}, {\"fieldname\": \"rack\", \"print_hide\": 0, \"label\": \"Rack\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"posting_date\", \"print_hide\": 0, \"label\": \"Date\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"apply_putaway_rule\", \"print_hide\": 0, \"label\": \"Apply Putaway Rule\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Accounting Dimensions\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"region\", \"print_hide\": 0, \"label\": \"Region\"}, {\"fieldname\": \"function\", \"print_hide\": 0, \"label\": \"Function\"}, {\"fieldname\": \"depot\", \"print_hide\": 0, \"label\": \"Depot\"}, {\"fieldname\": \"cost_center\", \"print_hide\": 0, \"label\": \"Cost Center\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"location\", \"print_hide\": 0, \"label\": \"Location\"}, {\"fieldname\": \"country\", \"print_hide\": 0, \"label\": \"Country\"}, {\"fieldname\": \"project\", \"print_hide\": 0, \"label\": \"Project\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Items\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"scan_barcode\", \"print_hide\": 0, \"label\": \"Scan Barcode\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"set_from_warehouse\", \"print_hide\": 0, \"label\": \"Set From Warehouse\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"_custom_html\", \"print_hide\": 0, \"label\": \"Custom HTML\", \"fieldtype\": \"HTML\", \"options\": \"<table class=\\\"table table-bordered\\\">\\n\\t<tbody>\\n\\t\\t<tr>\\n\\t\\t\\t<th>Sr</th>\\n\\t\\t\\t<th>Item Name</th>\\n\\t\\t\\t<th>Description</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Qty</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Rate</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Amount</th>\\n\\t\\t</tr>\\n\\t\\t{%- for row in doc.items -%}\\n\\t\\t<tr>\\n\\t\\t    {% set bundle_data = get_serial_or_batch_nos(row.serial_and_batch_bundle) %}\\n\\t\\t    {% set serial_nos = [] %}\\n            {% set batches = {} %}\\n\\n\\t\\t\\t<td style=\\\"width: 4%;\\\">{{ row.idx }}</td>\\n\\t\\t\\t<td style=\\\"width: 20%;\\\">\\n\\t\\t\\t\\t{{ row.item_name }}\\n\\t\\t\\t\\t{% if row.item_code != row.item_name -%}\\n\\t\\t\\t\\t<br>Item Code: {{ row.item_code}}\\n\\t\\t\\t\\t{%- endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t<td style=\\\"width: 30%;\\\">\\n\\t\\t\\t\\t<div style=\\\"border: 0px;\\\">{{ row.description }}</div></td>\\n\\t\\t\\t<td style=\\\"width: 10%; text-align: right;\\\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\\n\\t\\t\\t<td style=\\\"width: 18%; text-align: right;\\\">{{\\n\\t\\t\\t\\trow.get_formatted(\\\"rate\\\", doc) }}</td>\\n\\t\\t\\t<td style=\\\"width: 18%; text-align: right;\\\">{{\\n\\t\\t\\t\\trow.get_formatted(\\\"amount\\\", doc) }}</td>\\n\\t\\t\\t\\n\\t\\t</tr>\\n\\t\\t{%- endfor -%}\\n\\t</tbody>\\n</table>\\n\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"total_qty\", \"print_hide\": 0, \"label\": \"Total Quantity\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"total\", \"print_hide\": 0, \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"taxes\", \"print_hide\": 0, \"label\": \"Purchase Taxes and Charges\", \"visible_columns\": [{\"fieldname\": \"category\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"add_deduct_tax\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"charge_type\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"row_id\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"included_in_print_rate\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"included_in_paid_amount\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"account_head\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"description\", \"print_width\": \"300px\", \"print_hide\": 0}, {\"fieldname\": \"rate\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"region\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"function\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"location\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"cost_center\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"depot\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"country\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"account_currency\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"tax_amount\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"total\", \"print_width\": \"\", \"print_hide\": 0}]}, {\"fieldtype\": \"Section Break\", \"label\": \"Totals\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"grand_total\", \"print_hide\": 0, \"label\": \"Grand Total\"}, {\"fieldname\": \"rounded_total\", \"print_hide\": 0, \"label\": \"Rounded Total\"}, {\"fieldname\": \"in_words\", \"print_hide\": 0, \"label\": \"In Words\"}, {\"fieldname\": \"disable_rounded_total\", \"print_hide\": 0, \"label\": \"Disable Rounded Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Supplier Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"address_display\", \"print_hide\": 0, \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"contact_display\", \"print_hide\": 0, \"label\": \"Contact\"}, {\"fieldname\": \"contact_mobile\", \"print_hide\": 0, \"label\": \"Mobile No\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Company Billing Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"billing_address\", \"print_hide\": 0, \"label\": \"Billing Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"billing_address_display\", \"print_hide\": 0, \"label\": \"Billing Address\"}, {\"fieldname\": \"terms\", \"print_hide\": 0, \"label\": \"Terms and Conditions\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"_custom_html\", \"print_hide\": 0, \"label\": \"Custom HTML\", \"fieldtype\": \"HTML\", \"options\": \"<table class=\\\"table table-bordered\\\">\\n\\t<tbody>\\n\\t\\t<tr>\\n\\t\\t\\t<th>Sr</th>\\n\\t\\t\\t<th>Item Name</th>\\n\\t\\t\\t<th>Qty</th>\\n\\t\\t\\t<th class=\\\"text-left\\\">Serial Nos</th>\\n\\t\\t\\t<th class=\\\"text-left\\\">Batch Nos (Qty)</th>\\n\\t\\t</tr>\\n\\t\\t{%- for row in doc.items -%}\\n\\t\\t<tr>\\n\\t\\t    {% set bundle_data = get_serial_or_batch_nos(row.serial_and_batch_bundle) %}\\n\\t\\t    {% set serial_nos = [] %}\\n            {% set batches = {} %}\\n            \\n            {% if bundle_data %}\\n\\t\\t\\t    {% for data in bundle_data %}\\n\\t\\t\\t        {% if data.serial_no %}\\n\\t\\t\\t            {{ serial_nos.append(data.serial_no) or \\\"\\\" }}\\n\\t\\t\\t        {% endif %}\\n\\t\\t\\t        \\n\\t\\t\\t        {% if data.batch_no %}\\n\\t\\t\\t            {{ batches.update({data.batch_no: data.qty}) or \\\"\\\" }}\\n\\t\\t\\t        {% endif %}\\n\\t\\t\\t    {% endfor %}\\n\\t\\t\\t{% endif %}\\n\\n\\t\\t\\t<td style=\\\"width: 3%;\\\">{{ row.idx }}</td>\\n\\t\\t\\t<td style=\\\"width: 20%;\\\">\\n\\t\\t\\t\\t{{ row.item_name }}\\n\\t\\t\\t\\t{% if row.item_code != row.item_name -%}\\n\\t\\t\\t\\t<br>Item Code: {{ row.item_code}}\\n\\t\\t\\t\\t{%- endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t<td style=\\\"width: 10%; text-align: right;\\\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\\n\\t\\t\\t\\n\\t\\t\\t<td style=\\\"width: 30%; text-align: left;\\\">{{ serial_nos|join(',') }}</td>\\n\\t\\t\\t<td style=\\\"width: 30%;\\\">\\n\\t\\t\\t    {% if batches %}\\n                    {% for batch_no, qty in batches.items() %}\\n                        <p> {{batch_no}} : {{qty}} {{ row.uom or row.stock_uom }} </p>\\n                    {% endfor %}\\n                {% endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t\\n\\t\\t</tr>\\n\\t\\t{%- endfor -%}\\n\\t</tbody>\\n</table>\\n\"}]",
+ "format_data": "[{\"fieldname\": \"print_heading_template\", \"fieldtype\": \"Custom HTML\", \"options\": \"<div class=\\\"print-heading\\\">\\t\\t\\t\\t<h2><div>Purchase Receipt</div><br><small class=\\\"sub-heading\\\">{{ doc.name }}</small>\\t\\t\\t\\t</h2></div>\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"supplier_name\", \"print_hide\": 0, \"label\": \"Supplier Name\"}, {\"fieldname\": \"supplier_delivery_note\", \"print_hide\": 0, \"label\": \"Supplier Delivery Note\"}, {\"fieldname\": \"rack\", \"print_hide\": 0, \"label\": \"Rack\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"posting_date\", \"print_hide\": 0, \"label\": \"Date\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"apply_putaway_rule\", \"print_hide\": 0, \"label\": \"Apply Putaway Rule\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Accounting Dimensions\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"region\", \"print_hide\": 0, \"label\": \"Region\"}, {\"fieldname\": \"function\", \"print_hide\": 0, \"label\": \"Function\"}, {\"fieldname\": \"depot\", \"print_hide\": 0, \"label\": \"Depot\"}, {\"fieldname\": \"cost_center\", \"print_hide\": 0, \"label\": \"Cost Center\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"location\", \"print_hide\": 0, \"label\": \"Location\"}, {\"fieldname\": \"country\", \"print_hide\": 0, \"label\": \"Country\"}, {\"fieldname\": \"project\", \"print_hide\": 0, \"label\": \"Project\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Items\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"scan_barcode\", \"print_hide\": 0, \"label\": \"Scan Barcode\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"set_from_warehouse\", \"print_hide\": 0, \"label\": \"Set From Warehouse\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"_custom_html\", \"print_hide\": 0, \"label\": \"Custom HTML\", \"fieldtype\": \"HTML\", \"options\": \"<table class=\\\"table table-bordered\\\">\\n\\t<tbody>\\n\\t\\t<tr>\\n\\t\\t\\t<th>Sr</th>\\n\\t\\t\\t<th>Item Name</th>\\n\\t\\t\\t<th>Description</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Qty</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Rate</th>\\n\\t\\t\\t<th class=\\\"text-right\\\">Amount</th>\\n\\t\\t</tr>\\n\\t\\t{%- for row in doc.items -%}\\n\\t\\t<tr>\\n\\t\\t    {% set bundle_data = get_serial_or_batch_nos(row.serial_and_batch_bundle) %}\\n\\t\\t    {% set serial_nos = [] %}\\n            {% set batches = {} %}\\n\\n\\t\\t\\t<td style=\\\"width: 4%;\\\">{{ row.idx }}</td>\\n\\t\\t\\t<td style=\\\"width: 20%;\\\">\\n\\t\\t\\t\\t{{ row.item_name }}\\n\\t\\t\\t\\t{% if row.item_code != row.item_name -%}\\n\\t\\t\\t\\t<br>Item Code: {{ row.item_code}}\\n\\t\\t\\t\\t{%- endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t<td style=\\\"width: 30%;\\\">\\n\\t\\t\\t\\t<div style=\\\"border: 0px;\\\">{{ row.description }}</div></td>\\n\\t\\t\\t<td style=\\\"width: 10%; text-align: right;\\\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\\n\\t\\t\\t<td style=\\\"width: 18%; text-align: right;\\\">{{\\n\\t\\t\\t\\trow.get_formatted(\\\"rate\\\", doc) }}</td>\\n\\t\\t\\t<td style=\\\"width: 18%; text-align: right;\\\">{{\\n\\t\\t\\t\\trow.get_formatted(\\\"amount\\\", doc) }}</td>\\n\\t\\t\\t\\n\\t\\t</tr>\\n\\t\\t{%- endfor -%}\\n\\t</tbody>\\n</table>\\n\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"total_qty\", \"print_hide\": 0, \"label\": \"Total Quantity\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"total\", \"print_hide\": 0, \"label\": \"Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"taxes\", \"print_hide\": 0, \"label\": \"Purchase Taxes and Charges\", \"visible_columns\": [{\"fieldname\": \"category\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"add_deduct_tax\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"charge_type\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"row_id\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"included_in_print_rate\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"included_in_paid_amount\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"account_head\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"description\", \"print_width\": \"300px\", \"print_hide\": 0}, {\"fieldname\": \"rate\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"region\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"function\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"location\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"cost_center\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"depot\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"country\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"account_currency\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"tax_amount\", \"print_width\": \"\", \"print_hide\": 0}, {\"fieldname\": \"total\", \"print_width\": \"\", \"print_hide\": 0}]}, {\"fieldtype\": \"Section Break\", \"label\": \"Totals\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"grand_total\", \"print_hide\": 0, \"label\": \"Grand Total\"}, {\"fieldname\": \"rounded_total\", \"print_hide\": 0, \"label\": \"Rounded Total\"}, {\"fieldname\": \"in_words\", \"print_hide\": 0, \"label\": \"In Words\"}, {\"fieldname\": \"disable_rounded_total\", \"print_hide\": 0, \"label\": \"Disable Rounded Total\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Supplier Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"address_display\", \"print_hide\": 0, \"label\": \"Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"contact_display\", \"print_hide\": 0, \"label\": \"Contact\"}, {\"fieldname\": \"contact_mobile\", \"print_hide\": 0, \"label\": \"Mobile No\"}, {\"fieldtype\": \"Section Break\", \"label\": \"Company Billing Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"billing_address\", \"print_hide\": 0, \"label\": \"Billing Address\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"billing_address_display\", \"print_hide\": 0, \"label\": \"Billing Address\"}, {\"fieldname\": \"terms\", \"print_hide\": 0, \"label\": \"Terms and Conditions\"}, {\"fieldtype\": \"Section Break\", \"label\": \"\"}, {\"fieldtype\": \"Column Break\"}, {\"fieldname\": \"_custom_html\", \"print_hide\": 0, \"label\": \"Custom HTML\", \"fieldtype\": \"HTML\", \"options\": \"<table class=\\\"table table-bordered\\\">\\n\\t<tbody>\\n\\t\\t<tr>\\n\\t\\t\\t<th>Sr</th>\\n\\t\\t\\t<th>Item Name</th>\\n\\t\\t\\t<th>Qty</th>\\n\\t\\t\\t<th class=\\\"text-left\\\">Serial Nos</th>\\n\\t\\t\\t<th class=\\\"text-left\\\">Batch Nos (Qty)</th>\\n\\t\\t</tr>\\n\\t\\t{%- for row in doc.items -%}\\n\\t\\t<tr>\\n\\t\\t    {% set bundle_data = frappe.get_all(\\\"Serial and Batch Entry\\\", \\n\\t\\t        fields=[\\\"serial_no\\\", \\\"batch_no\\\", \\\"qty\\\"], \\n\\t\\t        filters={\\\"parent\\\": row.serial_and_batch_bundle}) %}\\n\\t\\t    {% set serial_nos = [] %}\\n            {% set batches = {} %}\\n            \\n            {% if bundle_data %}\\n\\t\\t\\t    {% for data in bundle_data %}\\n\\t\\t\\t        {% if data.serial_no %}\\n\\t\\t\\t            {{ serial_nos.append(data.serial_no) or \\\"\\\" }}\\n\\t\\t\\t        {% endif %}\\n\\t\\t\\t        \\n\\t\\t\\t        {% if data.batch_no %}\\n\\t\\t\\t            {{ batches.update({data.batch_no: data.qty}) or \\\"\\\" }}\\n\\t\\t\\t        {% endif %}\\n\\t\\t\\t    {% endfor %}\\n\\t\\t\\t{% endif %}\\n\\n\\t\\t\\t<td style=\\\"width: 3%;\\\">{{ row.idx }}</td>\\n\\t\\t\\t<td style=\\\"width: 20%;\\\">\\n\\t\\t\\t\\t{{ row.item_name }}\\n\\t\\t\\t\\t{% if row.item_code != row.item_name -%}\\n\\t\\t\\t\\t<br>Item Code: {{ row.item_code}}\\n\\t\\t\\t\\t{%- endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t<td style=\\\"width: 10%; text-align: right;\\\">{{ row.qty }} {{ row.uom or row.stock_uom }}</td>\\n\\t\\t\\t\\n\\t\\t\\t<td style=\\\"width: 30%; text-align: left;\\\">{{ serial_nos|join(',') }}</td>\\n\\t\\t\\t<td style=\\\"width: 30%;\\\">\\n\\t\\t\\t    {% if batches %}\\n                    {% for batch_no, qty in batches.items() %}\\n                        <p> {{batch_no}} : {{qty}} {{ row.uom or row.stock_uom }} </p>\\n                    {% endfor %}\\n                {% endif %}\\n\\t\\t\\t</td>\\n\\t\\t\\t\\n\\t\\t</tr>\\n\\t\\t{%- endfor -%}\\n\\t</tbody>\\n</table>\\n\"}]",
  "idx": 0,
  "line_breaks": 0,
  "margin_bottom": 15.0,
  "margin_left": 15.0,
  "margin_right": 15.0,
  "margin_top": 15.0,
- "modified": "2023-06-02 00:09:37.315002",
+ "modified": "2023-06-26 14:51:20.609682",
  "modified_by": "Administrator",
  "module": "Stock",
  "name": "Purchase Receipt Serial and Batch Bundle Print",
diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py
index 136c78f..9075608 100644
--- a/erpnext/stock/reorder_item.py
+++ b/erpnext/stock/reorder_item.py
@@ -67,7 +67,7 @@
 		else:
 			projected_qty = flt(item_warehouse_projected_qty.get(item_code, {}).get(warehouse))
 
-		if (reorder_level or reorder_qty) 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/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py
index 2c18f99..d6c840f 100644
--- a/erpnext/stock/serial_batch_bundle.py
+++ b/erpnext/stock/serial_batch_bundle.py
@@ -312,7 +312,35 @@
 
 
 def get_serial_or_batch_nos(bundle):
-	return frappe.get_all("Serial and Batch Entry", fields=["*"], filters={"parent": bundle})
+	# For print format
+
+	bundle_data = frappe.get_cached_value(
+		"Serial and Batch Bundle", bundle, ["has_serial_no", "has_batch_no"], as_dict=True
+	)
+
+	fields = []
+	if bundle_data.has_serial_no:
+		fields.append("serial_no")
+
+	if bundle_data.has_batch_no:
+		fields.extend(["batch_no", "qty"])
+
+	data = frappe.get_all("Serial and Batch Entry", fields=fields, filters={"parent": bundle})
+
+	if bundle_data.has_serial_no and not bundle_data.has_batch_no:
+		return ", ".join([d.serial_no for d in data])
+
+	elif bundle_data.has_batch_no:
+		html = "<table class= 'table table-borderless' style='margin-top: 0px;margin-bottom: 0px;'>"
+		for d in data:
+			if d.serial_no:
+				html += f"<tr><td>{d.batch_no}</th><th>{d.serial_no}</th	><th>{abs(d.qty)}</th></tr>"
+			else:
+				html += f"<tr><td>{d.batch_no}</td><td>{abs(d.qty)}</td></tr>"
+
+		html += "</table>"
+
+		return html
 
 
 class SerialNoValuation(DeprecatedSerialNoValuation):
diff --git a/erpnext/templates/print_formats/includes/serial_and_batch_bundle.html b/erpnext/templates/print_formats/includes/serial_and_batch_bundle.html
new file mode 100644
index 0000000..8e62586
--- /dev/null
+++ b/erpnext/templates/print_formats/includes/serial_and_batch_bundle.html
@@ -0,0 +1,4 @@
+{% if doc.get("serial_and_batch_bundle")  %}
+	{% set bundle_print = get_serial_or_batch_nos(doc.serial_and_batch_bundle) %}
+	{{bundle_print}}
+{%- endif %}
diff --git a/erpnext/translations/de.csv b/erpnext/translations/de.csv
index 68358c6..f9ec689 100644
--- a/erpnext/translations/de.csv
+++ b/erpnext/translations/de.csv
@@ -9905,3 +9905,7 @@
 Select an item from each set to be used in the Sales Order.,"Wählen Sie aus den Alternativen jeweils einen Artikel aus, der in die Auftragsbestätigung übernommen werden soll.",
 Is Alternative,Ist Alternative,
 Alternative Items,Alternativpositionen,
+Add Template,Vorlage einfügen,
+Prepend the template to the email message,Vorlage oberhalb der Email-Nachricht einfügen,
+Clear & Add Template,Leeren und Vorlage einfügen,
+Clear the email message and add the template,Email-Feld leeren und Vorlage einfügen,