feat: Show stock ledger preview
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 9f55ba1..bac84db 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -155,6 +155,7 @@
frm.events.hide_unhide_fields(frm);
frm.events.set_dynamic_labels(frm);
frm.events.show_general_ledger(frm);
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(frm);
},
validate_company: (frm) => {
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index ab7884d..6a558ca 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -54,9 +54,11 @@
hide_fields(this.frm.doc);
// Show / Hide button
this.show_general_ledger();
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
- if(doc.update_stock==1 && doc.docstatus==1) {
+ if(doc.update_stock==1) {
this.show_stock_ledger();
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
}
if(!doc.is_return && doc.docstatus == 1 && doc.outstanding_amount != 0){
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 1ef0c51..68407e0 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -88,9 +88,12 @@
}
this.show_general_ledger();
- this.show_ledger_preview();
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
- if(doc.update_stock) this.show_stock_ledger();
+ if(doc.update_stock){
+ this.show_stock_ledger();
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+ }
if (doc.docstatus == 1 && doc.outstanding_amount!=0
&& !(cint(doc.is_return) && doc.return_against)) {
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 0b057bc..903ef65 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -846,20 +846,31 @@
@frappe.whitelist()
-def show_ledger_preview(company, doctype, docname):
- frappe.db.savepoint("show_ledger_preview")
+def show_accounting_ledger_preview(company, doctype, docname):
+ frappe.db.savepoint("show_accounting_ledger_preview")
+
+ filters = {"company": company, "include_dimensions": 1}
+ doc = frappe.get_doc(doctype, docname)
+
+ gl_columns, gl_data = get_accounting_ledger_preview(doc, filters)
+
+ frappe.db.rollback(save_point="show_accounting_ledger_preview")
+
+ return {"gl_columns": gl_columns, "gl_data": gl_data}
+
+
+@frappe.whitelist()
+def show_stock_ledger_preview(company, doctype, docname):
+ frappe.db.savepoint("show_stock_ledger_preview")
filters = {"company": company}
doc = frappe.get_doc(doctype, docname)
sl_columns, sl_data = get_stock_ledger_preview(doc, filters)
- gl_columns, gl_data = get_accounting_ledger_preview(doc, filters)
- frappe.db.rollback(save_point="show_ledger_preview")
+ frappe.db.rollback(save_point="show_stock_ledger_preview")
return {
- "gl_columns": gl_columns,
- "gl_data": gl_data,
"sl_columns": sl_columns,
"sl_data": sl_data,
}
@@ -877,11 +888,16 @@
"against",
"party",
"party_type",
+ "cost_center",
"against_voucher_type",
"against_voucher",
]
doc.docstatus = 1
+
+ if doc.get("update_stock") or doc.doctype in ("Purchase Receipt", "Delivery Note"):
+ doc.update_stock_ledger()
+
doc.make_gl_entries()
columns = get_gl_columns(filters)
gl_entries = get_gl_entries_for_preview(doc.doctype, doc.name, fields)
@@ -915,12 +931,12 @@
"qty_after_transaction",
"warehouse",
"incoming_rate",
- "valuation_rate",
+ "in_out_rate",
"stock_value",
"stock_value_difference",
]
- if doc.update_stock or doc.doctype in ("Purchase Receipt", "Delivery Note"):
+ if doc.get("update_stock") or doc.doctype in ("Purchase Receipt", "Delivery Note"):
doc.docstatus = 1
doc.update_stock_ledger()
columns = get_sl_columns(filters)
@@ -945,6 +961,8 @@
entry["out_qty"] = abs(entry.actual_qty)
entry["in_qty"] = 0
+ entry["in_out_rate"] = entry["valuation_rate"]
+
return sl_entries
diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js
index ff59348..720423b 100644
--- a/erpnext/public/js/controllers/stock_controller.js
+++ b/erpnext/public/js/controllers/stock_controller.js
@@ -81,69 +81,4 @@
}, __("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.make_dialog(response.message);
- }
- })
- }, __("View"));
- }
- }
-
- make_dialog(data) {
- let me = this;
- let gl_columns = data.gl_columns;
- let gl_data = data.gl_data;
- let sl_columns = data.sl_columns;
- let sl_data = data.sl_data;
-
- let dialog = new frappe.ui.Dialog({
- "size": "extra-large",
- "title": __("Ledger Preview"),
- "fields": [
- {
- "fieldtype": "HTML",
- "fieldname": "accounting_ledger_preview_html",
- "label": __("Accounting Ledger"),
- },
- {
- "fieldtype": "HTML",
- "fieldname": "stock_ledger_preview_html",
- "label": __("Stock Ledger"),
- }
- ]
- });
-
- setTimeout(function() {
- me.get_datatable(gl_columns, gl_data, dialog.get_field("accounting_ledger_preview_html").wrapper);
- }, 200);
-
- dialog.show();
- }
-
- get_datatable(columns, data, wrapper) {
- const datatable_options = {
- columns: columns,
- data: data,
- dynamicRowHeight: true,
- checkboxColumn: false,
- inlineFilters: true,
- };
-
- new frappe.DataTable(
- wrapper,
- datatable_options
- );
- }
};
diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js
index cc020fc..4e028e4 100644
--- a/erpnext/public/js/erpnext.bundle.js
+++ b/erpnext/public/js/erpnext.bundle.js
@@ -17,6 +17,7 @@
import "./utils/supplier_quick_entry";
import "./call_popup/call_popup";
import "./utils/dimension_tree_filter";
+import "./utils/ledger_preview.js"
import "./utils/barcode_scanner";
import "./telephony";
import "./templates/call_link.html";
diff --git a/erpnext/public/js/utils/ledger_preview.js b/erpnext/public/js/utils/ledger_preview.js
new file mode 100644
index 0000000..d1ee67b
--- /dev/null
+++ b/erpnext/public/js/utils/ledger_preview.js
@@ -0,0 +1,76 @@
+frappe.provide('erpnext.accounts');
+
+erpnext.accounts.ledger_preview = {
+ show_accounting_ledger_preview(frm) {
+ let me = this;
+ if(!frm.is_new() && frm.doc.docstatus == 0) {
+ frm.add_custom_button(__('Accounting Ledger'), function() {
+ frappe.call({
+ "method": "erpnext.controllers.stock_controller.show_accounting_ledger_preview",
+ "args": {
+ "company": frm.doc.company,
+ "doctype": frm.doc.doctype,
+ "docname": frm.doc.name
+ },
+ "callback": function(response) {
+ me.make_dialog("Accounting Ledger Preview", "accounting_ledger_preview_html", response.message.gl_columns, response.message.gl_data);
+ }
+ })
+ }, __("Preview"));
+ }
+ },
+
+ show_stock_ledger_preview(frm) {
+ let me = this
+ if(!frm.is_new() && frm.doc.docstatus == 0) {
+ frm.add_custom_button(__('Stock Ledger'), function() {
+ frappe.call({
+ "method": "erpnext.controllers.stock_controller.show_stock_ledger_preview",
+ "args": {
+ "company": frm.doc.company,
+ "doctype": frm.doc.doctype,
+ "docname": frm.doc.name
+ },
+ "callback": function(response) {
+ me.make_dialog("Stock Ledger Preview", "stock_ledger_preview_html", response.message.sl_columns, response.message.sl_data);
+ }
+ })
+ }, __("Preview"));
+ }
+ },
+
+ make_dialog(label, fieldname, columns, data) {
+ let me = this;
+ let dialog = new frappe.ui.Dialog({
+ "size": "extra-large",
+ "title": __(label),
+ "fields": [
+ {
+ "fieldtype": "HTML",
+ "fieldname": fieldname,
+ },
+ ]
+ });
+
+ setTimeout(function() {
+ me.get_datatable(columns, data, dialog.get_field(fieldname).wrapper);
+ }, 200);
+
+ dialog.show();
+ },
+
+ get_datatable(columns, data, wrapper) {
+ const datatable_options = {
+ columns: columns,
+ data: data,
+ dynamicRowHeight: true,
+ checkboxColumn: false,
+ inlineFilters: true,
+ };
+
+ new frappe.DataTable(
+ wrapper,
+ datatable_options
+ );
+ }
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 77545e0..a648195 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -200,6 +200,9 @@
}
}
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+
if (doc.docstatus > 0) {
this.show_stock_ledger();
if (erpnext.is_perpetual_inventory_enabled(doc.company)) {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index 312c166..685209c 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -121,6 +121,10 @@
refresh() {
var me = this;
super.refresh();
+
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+
if(this.frm.doc.docstatus > 0) {
this.show_stock_ledger();
//removed for temporary