fix: Stock ledger preview

This commit is contained in:
Deepesh Garg 2023-06-12 11:46:51 +05:30
parent 2e52a63b0d
commit e30c3eafef
4 changed files with 104 additions and 13 deletions

View File

@ -211,7 +211,12 @@
"is_discounted",
"remarks",
"repost_required",
"connections_tab"
"connections_tab",
"ledger_preview",
"accounting_ledger_section",
"accounting_ledger_preview_html",
"stock_ledger_section",
"stock_ledger_preview_html"
],
"fields": [
{
@ -2142,6 +2147,29 @@
"fieldname": "use_company_roundoff_cost_center",
"fieldtype": "Check",
"label": "Use Company default Cost Center for Round off"
},
{
"fieldname": "ledger_preview",
"fieldtype": "Tab Break",
"label": "Ledger Preview"
},
{
"fieldname": "accounting_ledger_section",
"fieldtype": "Section Break",
"label": "Accounting Ledger"
},
{
"fieldname": "accounting_ledger_preview_html",
"fieldtype": "HTML"
},
{
"fieldname": "stock_ledger_section",
"fieldtype": "Section Break",
"label": "Stock Ledger"
},
{
"fieldname": "stock_ledger_preview_html",
"fieldtype": "HTML"
}
],
"icon": "fa fa-file-text",
@ -2154,7 +2182,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2023-04-28 14:15:59.901154",
"modified": "2023-06-11 11:18:14.024258",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@ -511,6 +511,7 @@ class BuyingController(SubcontractingController):
if self.get("is_old_subcontracting_flow"):
self.make_sl_entries_for_supplier_warehouse(sl_entries)
self.make_sl_entries(
sl_entries,
allow_negative_stock=allow_negative_stock,

View File

@ -15,7 +15,6 @@ from erpnext.accounts.general_ledger import (
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
@ -827,16 +826,76 @@ class StockController(AccountsController):
@frappe.whitelist()
def show_ledger_preview(company, doctype, docname):
from erpnext.accounts.report.general_ledger.general_ledger import get_columns as get_gl_columns
from erpnext.stock.report.stock_ledger.stock_ledger import get_columns as get_sl_columns
frappe.db.savepoint("show_ledger_preview")
filters = {"company": company}
doc = frappe.get_doc(doctype, docname)
columns = get_columns(filters)
data = doc.get_gl_entries()
datatable_sl_columns = []
datatable_sl_data = []
if doc.update_stock or doc.doctype in ("Purchase Receipt", "Delivery Note"):
sl_columns = get_sl_columns(filters)
doc.docstatus = 1
doc.update_stock_ledger()
sl_entries = get_sl_entries_for_preview(doc.doctype, doc.name)
datatable_sl_columns = get_columns(sl_columns)
datatable_sl_data = get_data(sl_columns, sl_entries)
doc.docstatus = 1
gl_columns = get_gl_columns(filters)
doc.make_gl_entries()
gl_data = get_gl_entries_for_preview(doc.doctype, doc.name)
datatable_gl_columns = get_columns(gl_columns)
datatable_gl_data = get_data(gl_columns, gl_data)
frappe.db.rollback(save_point="show_ledger_preview")
return {
"columns": columns,
"data": data,
"gl_columns": datatable_gl_columns,
"gl_data": datatable_gl_data,
"sl_columns": datatable_sl_columns,
"sl_data": datatable_sl_data,
}
def get_sl_entries_for_preview(doctype, docname):
return frappe.get_all(
"Stock Ledger Entry", filters={"voucher_type": doctype, "voucher_no": docname}, fields=["*"]
)
def get_gl_entries_for_preview(doctype, docname):
return frappe.get_all(
"GL Entry", filters={"voucher_type": doctype, "voucher_no": docname}, fields=["*"]
)
def get_columns(raw_columns):
return [
{"name": d.get("label"), "editable": False, "width": 100}
for d in raw_columns
if not d.get("hidden")
]
def get_data(raw_columns, raw_data):
datatable_data = []
for row in raw_data:
data_row = []
for column in raw_columns:
if not column.get("hidden"):
data_row.append(row.get(column.get("fieldname")))
datatable_data.append(data_row)
return datatable_data
def repost_required_for_queue(doc: StockController) -> bool:
"""check if stock document contains repeated item-warehouse with queue based valuation.

View File

@ -94,24 +94,27 @@ erpnext.stock.StockController = class StockController extends frappe.ui.form.Con
"docname": me.frm.doc.name
},
"callback": function(response) {
me.get_datatable(response);
console.log(response.message);
me.get_datatable(response.message.gl_columns, response.message.gl_data, me.frm.get_field("accounting_ledger_preview_html").wrapper);
me.get_datatable(response.message.sl_columns, response.message.sl_data, me.frm.get_field("stock_ledger_preview_html").wrapper);
me.frm.scroll_to_field("accounting_ledger_preview_html");
}
})
}, __("View"));
}
}
get_datatable(response) {
get_datatable(columns, data, wrapper) {
const datatable_options = {
columns: response.columns,
data: response.data,
columns: columns,
data: data,
dynamicRowHeight: true,
checkboxColumn: false,
inlineFilters: true,
};
this.datatable = new frappe.DataTable(
this.frm.page.main.parent,
new frappe.DataTable(
wrapper,
datatable_options
);
}