Merge pull request #32347 from s-aga-r/refactor/stock/report/incorrect-stock-value
refactor: rewrite `Incorrect Stock Value Report` queries in `QB`
This commit is contained in:
commit
a80e8726e7
@ -4,6 +4,8 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.query_builder import Field
|
||||
from frappe.query_builder.functions import Min, Timestamp
|
||||
from frappe.utils import add_days, getdate, today
|
||||
|
||||
import erpnext
|
||||
@ -28,7 +30,7 @@ def execute(filters=None):
|
||||
def get_unsync_date(filters):
|
||||
date = filters.from_date
|
||||
if not date:
|
||||
date = frappe.db.sql(""" SELECT min(posting_date) from `tabStock Ledger Entry`""")
|
||||
date = (frappe.qb.from_("Stock Ledger Entry").select(Min(Field("posting_date")))).run()
|
||||
date = date[0][0]
|
||||
|
||||
if not date:
|
||||
@ -54,22 +56,27 @@ def get_data(report_filters):
|
||||
result = []
|
||||
|
||||
voucher_wise_dict = {}
|
||||
data = frappe.db.sql(
|
||||
"""
|
||||
SELECT
|
||||
name, posting_date, posting_time, voucher_type, voucher_no,
|
||||
stock_value_difference, stock_value, warehouse, item_code
|
||||
FROM
|
||||
`tabStock Ledger Entry`
|
||||
WHERE
|
||||
posting_date
|
||||
= %s and company = %s
|
||||
and is_cancelled = 0
|
||||
ORDER BY timestamp(posting_date, posting_time) asc, creation asc
|
||||
""",
|
||||
(from_date, report_filters.company),
|
||||
as_dict=1,
|
||||
)
|
||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||
data = (
|
||||
frappe.qb.from_(sle)
|
||||
.select(
|
||||
sle.name,
|
||||
sle.posting_date,
|
||||
sle.posting_time,
|
||||
sle.voucher_type,
|
||||
sle.voucher_no,
|
||||
sle.stock_value_difference,
|
||||
sle.stock_value,
|
||||
sle.warehouse,
|
||||
sle.item_code,
|
||||
)
|
||||
.where(
|
||||
(sle.posting_date == from_date)
|
||||
& (sle.company == report_filters.company)
|
||||
& (sle.is_cancelled == 0)
|
||||
)
|
||||
.orderby(Timestamp(sle.posting_date, sle.posting_time), sle.creation)
|
||||
).run(as_dict=True)
|
||||
|
||||
for d in data:
|
||||
voucher_wise_dict.setdefault((d.item_code, d.warehouse), []).append(d)
|
||||
|
Loading…
x
Reference in New Issue
Block a user