feat: Accounting Ledger Preview
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 8cb2950..1ef0c51 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -88,6 +88,7 @@
}
this.show_general_ledger();
+ this.show_ledger_preview();
if(doc.update_stock) this.show_stock_ledger();
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index befde71..30dcc7f 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -15,6 +15,7 @@
make_reverse_gl_entries,
process_gl_map,
)
+from erpnext.accounts.report.general_ledger.general_ledger import get_columns
from erpnext.accounts.utils import get_fiscal_year
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.stock import get_warehouse_account_map
@@ -824,6 +825,18 @@
gl_entries.append(self.get_gl_dict(gl_entry, item=item))
+@frappe.whitelist()
+def show_ledger_preview(company, doctype, docname):
+ filters = {"company": company}
+ doc = frappe.get_doc(doctype, docname)
+ columns = get_columns(filters)
+ data = doc.get_gl_entries()
+ return {
+ "columns": columns,
+ "data": data,
+ }
+
+
def repost_required_for_queue(doc: StockController) -> bool:
"""check if stock document contains repeated item-warehouse with queue based valuation.
diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js
index d346357..919ffda 100644
--- a/erpnext/public/js/controllers/stock_controller.js
+++ b/erpnext/public/js/controllers/stock_controller.js
@@ -66,7 +66,7 @@
}
show_general_ledger() {
- var me = this;
+ let me = this;
if(this.frm.doc.docstatus > 0) {
cur_frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.route_options = {
@@ -81,4 +81,38 @@
}, __("View"));
}
}
+
+ show_ledger_preview() {
+ let me = this
+ if(this.frm.doc.docstatus == 0) {
+ cur_frm.add_custom_button(__('Accounting Ledger Preview'), function() {
+ frappe.call({
+ "method": "erpnext.controllers.stock_controller.show_ledger_preview",
+ "args": {
+ "company": me.frm.doc.company,
+ "doctype": me.frm.doc.doctype,
+ "docname": me.frm.doc.name
+ },
+ "callback": function(response) {
+ me.get_datatable(response);
+ }
+ })
+ }, __("View"));
+ }
+ }
+
+ get_datatable(response) {
+ const datatable_options = {
+ columns: response.columns,
+ data: response.data,
+ dynamicRowHeight: true,
+ checkboxColumn: false,
+ inlineFilters: true,
+ };
+
+ this.datatable = new frappe.DataTable(
+ this.frm.page.main.parent,
+ datatable_options
+ );
+ }
};