From 42f7ee905ca9a0ebfc5bfa145c7a9af8ba736307 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:17:14 +0530 Subject: [PATCH] fix: batch qty calculation (backport #45367) (#45388) fix: batch qty calculation (cherry picked from commit f07a71a882d940db3d1c1e28c011410fdb279aa3) Co-authored-by: Rohit Waghchaure (cherry picked from commit 767529f0ec4d982e2eaba40de00b39234c400fda) --- .../accounts/doctype/pos_invoice/test_pos_invoice.py | 3 ++- erpnext/stock/serial_batch_bundle.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 1dbc630e62e..7b6b8b50543 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -835,7 +835,8 @@ class TestPOSInvoice(unittest.TestCase): { "item_code": item.name, "warehouse": pos_inv2.items[0].warehouse, - "voucher_type": "Delivery Note", + "voucher_type": "POS Invoice", + "voucher_no": pos_inv2.name, "qty": 2, "avg_rate": 300, "batches": frappe._dict({"TestBatch 01": 2}), diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 59c299de352..85adb0348d9 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -6,6 +6,7 @@ from frappe.model.naming import make_autoname from frappe.query_builder.functions import CombineDatetime, Sum, Timestamp from frappe.utils import add_days, cint, cstr, flt, get_link_to_form, now, nowtime, today from pypika import Order +from pypika.terms import ExistsCriterion from erpnext.stock.deprecated_serial_batch import ( DeprecatedBatchNoValuation, @@ -650,6 +651,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): parent = frappe.qb.DocType("Serial and Batch Bundle") child = frappe.qb.DocType("Serial and Batch Entry") + sle = frappe.qb.DocType("Stock Ledger Entry") timestamp_condition = "" if self.sle.posting_date: @@ -682,6 +684,14 @@ class BatchNoValuation(DeprecatedBatchNoValuation): & (parent.docstatus == 1) & (parent.is_cancelled == 0) & (parent.type_of_transaction.isin(["Inward", "Outward"])) + & ( + ExistsCriterion( + frappe.qb.from_(sle) + .select(sle.name) + .where((parent.name == sle.serial_and_batch_bundle) & (sle.is_cancelled == 0)) + ) + | (parent.voucher_type == "POS Invoice") + ) ) .groupby(child.batch_no) )