mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-29 09:01:14 +02:00
* fix: incorrect `Opening Value` in `Stock Balance` report
(cherry picked from commit b04a101c11)
# Conflicts:
# erpnext/stock/report/stock_balance/stock_balance.py
* chore: `conflicts`
---------
Co-authored-by: s-aga-r <sagarsharma.s312@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ from operator import itemgetter
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
|
from frappe.query_builder.functions import Coalesce
|
||||||
from frappe.utils import cint, date_diff, flt, getdate
|
from frappe.utils import cint, date_diff, flt, getdate
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
|
|
||||||
@@ -276,11 +277,39 @@ def get_stock_ledger_entries(filters, items):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_opening_vouchers(to_date):
|
||||||
|
opening_vouchers = {"Stock Entry": [], "Stock Reconciliation": []}
|
||||||
|
|
||||||
|
se = frappe.qb.DocType("Stock Entry")
|
||||||
|
sr = frappe.qb.DocType("Stock Reconciliation")
|
||||||
|
|
||||||
|
vouchers_data = (
|
||||||
|
frappe.qb.from_(
|
||||||
|
(
|
||||||
|
frappe.qb.from_(se)
|
||||||
|
.select(se.name, Coalesce("Stock Entry").as_("voucher_type"))
|
||||||
|
.where((se.docstatus == 1) & (se.posting_date <= to_date) & (se.is_opening == "Yes"))
|
||||||
|
)
|
||||||
|
+ (
|
||||||
|
frappe.qb.from_(sr)
|
||||||
|
.select(sr.name, Coalesce("Stock Reconciliation").as_("voucher_type"))
|
||||||
|
.where((sr.docstatus == 1) & (sr.posting_date <= to_date) & (sr.purpose == "Opening Stock"))
|
||||||
|
)
|
||||||
|
).select("voucher_type", "name")
|
||||||
|
).run(as_dict=True)
|
||||||
|
|
||||||
|
if vouchers_data:
|
||||||
|
for d in vouchers_data:
|
||||||
|
opening_vouchers[d.voucher_type].append(d.name)
|
||||||
|
|
||||||
|
return opening_vouchers
|
||||||
|
|
||||||
|
|
||||||
def get_item_warehouse_map(filters, sle):
|
def get_item_warehouse_map(filters, sle):
|
||||||
iwb_map = {}
|
iwb_map = {}
|
||||||
from_date = getdate(filters.get("from_date"))
|
from_date = getdate(filters.get("from_date"))
|
||||||
to_date = getdate(filters.get("to_date"))
|
to_date = getdate(filters.get("to_date"))
|
||||||
|
opening_vouchers = get_opening_vouchers(to_date)
|
||||||
float_precision = cint(frappe.db.get_default("float_precision")) or 3
|
float_precision = cint(frappe.db.get_default("float_precision")) or 3
|
||||||
|
|
||||||
for d in sle:
|
for d in sle:
|
||||||
@@ -309,11 +338,7 @@ def get_item_warehouse_map(filters, sle):
|
|||||||
|
|
||||||
value_diff = flt(d.stock_value_difference)
|
value_diff = flt(d.stock_value_difference)
|
||||||
|
|
||||||
if d.posting_date < from_date or (
|
if d.posting_date < from_date or d.voucher_no in opening_vouchers.get(d.voucher_type, []):
|
||||||
d.posting_date == from_date
|
|
||||||
and d.voucher_type == "Stock Reconciliation"
|
|
||||||
and frappe.db.get_value("Stock Reconciliation", d.voucher_no, "purpose") == "Opening Stock"
|
|
||||||
):
|
|
||||||
qty_dict.opening_qty += qty_diff
|
qty_dict.opening_qty += qty_diff
|
||||||
qty_dict.opening_val += value_diff
|
qty_dict.opening_val += value_diff
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user