mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-16 08:05:00 +00:00
fix: incorrect current qty calculation for the batch
(cherry picked from commit 535f8657ed)
This commit is contained in:
committed by
Mergify
parent
fea0ca8e8e
commit
bf48cf02e5
@@ -218,6 +218,7 @@ def get_batch_qty(
|
|||||||
batch_no=None,
|
batch_no=None,
|
||||||
warehouse=None,
|
warehouse=None,
|
||||||
item_code=None,
|
item_code=None,
|
||||||
|
creation=None,
|
||||||
posting_date=None,
|
posting_date=None,
|
||||||
posting_time=None,
|
posting_time=None,
|
||||||
ignore_voucher_nos=None,
|
ignore_voucher_nos=None,
|
||||||
@@ -244,6 +245,7 @@ def get_batch_qty(
|
|||||||
{
|
{
|
||||||
"item_code": item_code,
|
"item_code": item_code,
|
||||||
"warehouse": warehouse,
|
"warehouse": warehouse,
|
||||||
|
"creation": creation,
|
||||||
"posting_date": posting_date,
|
"posting_date": posting_date,
|
||||||
"posting_time": posting_time,
|
"posting_time": posting_time,
|
||||||
"batch_no": batch_no,
|
"batch_no": batch_no,
|
||||||
|
|||||||
@@ -2358,6 +2358,16 @@ def get_available_batches(kwargs):
|
|||||||
kwargs.posting_date, kwargs.posting_time
|
kwargs.posting_date, kwargs.posting_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if kwargs.get("creation"):
|
||||||
|
timestamp_condition = stock_ledger_entry.posting_datetime < get_combine_datetime(
|
||||||
|
kwargs.posting_date, kwargs.posting_time
|
||||||
|
)
|
||||||
|
|
||||||
|
timestamp_condition |= (
|
||||||
|
stock_ledger_entry.posting_datetime
|
||||||
|
== get_combine_datetime(kwargs.posting_date, kwargs.posting_time)
|
||||||
|
) & (stock_ledger_entry.creation < kwargs.creation)
|
||||||
|
|
||||||
query = query.where(timestamp_condition)
|
query = query.where(timestamp_condition)
|
||||||
|
|
||||||
for field in ["warehouse", "item_code"]:
|
for field in ["warehouse", "item_code"]:
|
||||||
@@ -2599,6 +2609,16 @@ def get_stock_ledgers_for_serial_nos(kwargs):
|
|||||||
kwargs.posting_date, kwargs.posting_time
|
kwargs.posting_date, kwargs.posting_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if kwargs.get("creation"):
|
||||||
|
timestamp_condition = stock_ledger_entry.posting_datetime < get_combine_datetime(
|
||||||
|
kwargs.posting_date, kwargs.posting_time
|
||||||
|
)
|
||||||
|
|
||||||
|
timestamp_condition |= (
|
||||||
|
stock_ledger_entry.posting_datetime
|
||||||
|
== get_combine_datetime(kwargs.posting_date, kwargs.posting_time)
|
||||||
|
) & (stock_ledger_entry.creation < kwargs.creation)
|
||||||
|
|
||||||
query = query.where(timestamp_condition)
|
query = query.where(timestamp_condition)
|
||||||
|
|
||||||
for field in ["warehouse", "item_code", "serial_no"]:
|
for field in ["warehouse", "item_code", "serial_no"]:
|
||||||
@@ -2657,6 +2677,16 @@ def get_stock_ledgers_batches(kwargs):
|
|||||||
kwargs.posting_date, kwargs.posting_time
|
kwargs.posting_date, kwargs.posting_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if kwargs.get("creation"):
|
||||||
|
timestamp_condition = stock_ledger_entry.posting_datetime < get_combine_datetime(
|
||||||
|
kwargs.posting_date, kwargs.posting_time
|
||||||
|
)
|
||||||
|
|
||||||
|
timestamp_condition |= (
|
||||||
|
stock_ledger_entry.posting_datetime
|
||||||
|
== get_combine_datetime(kwargs.posting_date, kwargs.posting_time)
|
||||||
|
) & (stock_ledger_entry.creation < kwargs.creation)
|
||||||
|
|
||||||
query = query.where(timestamp_condition)
|
query = query.where(timestamp_condition)
|
||||||
|
|
||||||
if kwargs.get("ignore_voucher_nos"):
|
if kwargs.get("ignore_voucher_nos"):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, bold, json, msgprint
|
from frappe import _, bold, json, msgprint
|
||||||
from frappe.query_builder.functions import CombineDatetime, Sum
|
from frappe.query_builder.functions import CombineDatetime, Sum
|
||||||
from frappe.utils import add_to_date, cint, cstr, flt, get_datetime
|
from frappe.utils import add_to_date, cint, cstr, flt, get_datetime, now
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.utils import get_company_default
|
from erpnext.accounts.utils import get_company_default
|
||||||
@@ -1034,7 +1034,7 @@ class StockReconciliation(StockController):
|
|||||||
val_rate = 0.0
|
val_rate = 0.0
|
||||||
current_qty = 0.0
|
current_qty = 0.0
|
||||||
if row.current_serial_and_batch_bundle:
|
if row.current_serial_and_batch_bundle:
|
||||||
current_qty = self.get_current_qty_for_serial_or_batch(row)
|
current_qty = self.get_current_qty_for_serial_or_batch(row, sle_creation)
|
||||||
elif row.serial_no:
|
elif row.serial_no:
|
||||||
item_dict = get_stock_balance_for(
|
item_dict = get_stock_balance_for(
|
||||||
row.item_code,
|
row.item_code,
|
||||||
@@ -1143,17 +1143,17 @@ class StockReconciliation(StockController):
|
|||||||
|
|
||||||
return allow_negative_stock
|
return allow_negative_stock
|
||||||
|
|
||||||
def get_current_qty_for_serial_or_batch(self, row):
|
def get_current_qty_for_serial_or_batch(self, row, sle_creation):
|
||||||
doc = frappe.get_doc("Serial and Batch Bundle", row.current_serial_and_batch_bundle)
|
doc = frappe.get_doc("Serial and Batch Bundle", row.current_serial_and_batch_bundle)
|
||||||
current_qty = 0.0
|
current_qty = 0.0
|
||||||
if doc.has_serial_no:
|
if doc.has_serial_no:
|
||||||
current_qty = self.get_current_qty_for_serial_nos(doc)
|
current_qty = self.get_current_qty_for_serial_nos(doc, sle_creation)
|
||||||
elif doc.has_batch_no:
|
elif doc.has_batch_no:
|
||||||
current_qty = self.get_current_qty_for_batch_nos(doc)
|
current_qty = self.get_current_qty_for_batch_nos(doc, sle_creation)
|
||||||
|
|
||||||
return abs(current_qty)
|
return abs(current_qty)
|
||||||
|
|
||||||
def get_current_qty_for_serial_nos(self, doc):
|
def get_current_qty_for_serial_nos(self, doc, sle_creation):
|
||||||
serial_nos_details = get_available_serial_nos(
|
serial_nos_details = get_available_serial_nos(
|
||||||
frappe._dict(
|
frappe._dict(
|
||||||
{
|
{
|
||||||
@@ -1161,6 +1161,7 @@ class StockReconciliation(StockController):
|
|||||||
"warehouse": doc.warehouse,
|
"warehouse": doc.warehouse,
|
||||||
"posting_date": self.posting_date,
|
"posting_date": self.posting_date,
|
||||||
"posting_time": self.posting_time,
|
"posting_time": self.posting_time,
|
||||||
|
"creation": sle_creation,
|
||||||
"voucher_no": self.name,
|
"voucher_no": self.name,
|
||||||
"ignore_warehouse": 1,
|
"ignore_warehouse": 1,
|
||||||
}
|
}
|
||||||
@@ -1190,7 +1191,7 @@ class StockReconciliation(StockController):
|
|||||||
|
|
||||||
return current_qty
|
return current_qty
|
||||||
|
|
||||||
def get_current_qty_for_batch_nos(self, doc):
|
def get_current_qty_for_batch_nos(self, doc, sle_creation):
|
||||||
current_qty = 0.0
|
current_qty = 0.0
|
||||||
precision = doc.entries[0].precision("qty")
|
precision = doc.entries[0].precision("qty")
|
||||||
for d in doc.entries:
|
for d in doc.entries:
|
||||||
@@ -1198,6 +1199,7 @@ class StockReconciliation(StockController):
|
|||||||
get_batch_qty(
|
get_batch_qty(
|
||||||
d.batch_no,
|
d.batch_no,
|
||||||
doc.warehouse,
|
doc.warehouse,
|
||||||
|
creation=sle_creation,
|
||||||
posting_date=doc.posting_date,
|
posting_date=doc.posting_date,
|
||||||
posting_time=doc.posting_time,
|
posting_time=doc.posting_time,
|
||||||
ignore_voucher_nos=[doc.voucher_no],
|
ignore_voucher_nos=[doc.voucher_no],
|
||||||
@@ -1494,6 +1496,7 @@ def get_stock_balance_for(
|
|||||||
"company": company,
|
"company": company,
|
||||||
"posting_date": posting_date,
|
"posting_date": posting_date,
|
||||||
"posting_time": posting_time,
|
"posting_time": posting_time,
|
||||||
|
"creation": row.get("creation") if row and row.get("creation") else now(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user