fix: dont fetch qty in reco if batch is required

This commit is contained in:
Ankush Menat 2022-04-02 13:24:37 +05:30 committed by Ankush Menat
parent f83a1c1989
commit deca1aaf06

View File

@ -1,6 +1,7 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from typing import Optional
import frappe
from frappe import _, msgprint
@ -706,29 +707,43 @@ def get_itemwise_batch(warehouse, posting_date, company, item_code=None):
@frappe.whitelist()
def get_stock_balance_for(
item_code, warehouse, posting_date, posting_time, batch_no=None, with_valuation_rate=True
item_code: str,
warehouse: str,
posting_date: str,
posting_time: str,
batch_no: Optional[str] = None,
with_valuation_rate: bool = True,
):
frappe.has_permission("Stock Reconciliation", "write", throw=True)
item_dict = frappe.db.get_value("Item", item_code, ["has_serial_no", "has_batch_no"], as_dict=1)
item_dict = frappe.get_cached_value(
"Item", item_code, ["has_serial_no", "has_batch_no"], as_dict=1
)
if not item_dict:
# In cases of data upload to Items table
msg = _("Item {} does not exist.").format(item_code)
frappe.throw(msg, title=_("Missing"))
serial_nos = ""
with_serial_no = True if item_dict.get("has_serial_no") else False
serial_nos = None
has_serial_no = bool(item_dict.get("has_serial_no"))
has_batch_no = bool(item_dict.get("has_batch_no"))
if not batch_no and has_batch_no:
# Not enough information to fetch data
return {"qty": 0, "rate": 0, "serial_nos": None}
# TODO: fetch only selected batch's values
data = get_stock_balance(
item_code,
warehouse,
posting_date,
posting_time,
with_valuation_rate=with_valuation_rate,
with_serial_no=with_serial_no,
with_serial_no=has_serial_no,
)
if with_serial_no:
if has_serial_no:
qty, rate, serial_nos = data
else:
qty, rate = data