feat: Show stock ledger preview
This commit is contained in:
parent
e7d2bcf108
commit
0e68da5a2a
@ -155,6 +155,7 @@ frappe.ui.form.on('Payment Entry', {
|
||||
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) => {
|
||||
|
@ -54,9 +54,11 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
|
||||
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){
|
||||
|
@ -88,9 +88,12 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
@ -846,20 +846,31 @@ class StockController(AccountsController):
|
||||
|
||||
|
||||
@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 @@ def get_accounting_ledger_preview(doc, filters):
|
||||
"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 @@ def get_stock_ledger_preview(doc, filters):
|
||||
"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 @@ def get_sl_entries_for_preview(doctype, docname, fields):
|
||||
entry["out_qty"] = abs(entry.actual_qty)
|
||||
entry["in_qty"] = 0
|
||||
|
||||
entry["in_out_rate"] = entry["valuation_rate"]
|
||||
|
||||
return sl_entries
|
||||
|
||||
|
||||
|
@ -81,69 +81,4 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
|
||||
}, __("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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -17,6 +17,7 @@ import "./utils/customer_quick_entry";
|
||||
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";
|
||||
|
76
erpnext/public/js/utils/ledger_preview.js
Normal file
76
erpnext/public/js/utils/ledger_preview.js
Normal file
@ -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
|
||||
);
|
||||
}
|
||||
}
|
@ -200,6 +200,9 @@ erpnext.stock.DeliveryNoteController = class DeliveryNoteController extends erpn
|
||||
}
|
||||
}
|
||||
|
||||
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)) {
|
||||
|
@ -121,6 +121,10 @@ erpnext.stock.PurchaseReceiptController = class PurchaseReceiptController extend
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user