mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-11 13:41:47 +00:00
Merge pull request #56235 from mihir-kandoi/pg-remove-dead-get-batches
refactor(stock): remove dead get_batches() in batch.py
This commit is contained in:
@@ -9,7 +9,6 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.naming import make_autoname, revert_series_if_last
|
||||
from frappe.query_builder.functions import CurDate, Sum
|
||||
from frappe.utils import cint, flt, get_link_to_form
|
||||
from frappe.utils.data import DateTimeLikeObject, add_days
|
||||
|
||||
@@ -381,50 +380,6 @@ def make_batch_bundle(
|
||||
)
|
||||
|
||||
|
||||
def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
|
||||
batch = frappe.qb.DocType("Batch")
|
||||
sle = frappe.qb.DocType("Stock Ledger Entry")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(batch)
|
||||
.join(sle)
|
||||
.on(batch.batch_id == sle.batch_no)
|
||||
.select(
|
||||
batch.batch_id,
|
||||
Sum(sle.actual_qty).as_("qty"),
|
||||
)
|
||||
.where(
|
||||
(sle.item_code == item_code)
|
||||
& (sle.warehouse == warehouse)
|
||||
& (sle.is_cancelled == 0)
|
||||
& ((batch.expiry_date >= CurDate()) | (batch.expiry_date.isnull()))
|
||||
)
|
||||
.groupby(batch.batch_id)
|
||||
.orderby(batch.expiry_date, batch.creation)
|
||||
)
|
||||
|
||||
if serial_no and frappe.get_cached_value("Item", item_code, "has_batch_no"):
|
||||
serial_nos = get_serial_nos(serial_no)
|
||||
batches = frappe.get_all(
|
||||
"Serial No",
|
||||
fields=["batch_no"],
|
||||
filters={"item_code": item_code, "warehouse": warehouse, "name": ("in", serial_nos)},
|
||||
distinct=True,
|
||||
)
|
||||
|
||||
if not batches:
|
||||
validate_serial_no_with_batch(serial_nos, item_code)
|
||||
|
||||
if batches and len(batches) > 1:
|
||||
return []
|
||||
|
||||
query = query.where(batch.name == batches[0].batch_no)
|
||||
|
||||
return query.run(as_dict=True)
|
||||
|
||||
|
||||
def validate_serial_no_with_batch(serial_nos, item_code):
|
||||
if frappe.get_cached_value("Serial No", serial_nos[0], "item_code") != item_code:
|
||||
frappe.throw(
|
||||
|
||||
Reference in New Issue
Block a user