mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-28 23:51:48 +01:00
fix: same posting date and time, creation causing incorrect balance qty (#42904)
fix: same posting date and time, creation causing incorrect balance quantity
(cherry picked from commit 27364b7e6b)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import add_days, cint, cstr, flt, getdate, nowtime, today
|
from frappe.utils import add_days, cint, cstr, flt, get_datetime, getdate, nowtime, today
|
||||||
from pypika import functions as fn
|
from pypika import functions as fn
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@@ -3592,6 +3592,71 @@ class TestPurchaseReceipt(FrappeTestCase):
|
|||||||
inter_transfer_dn.cancel()
|
inter_transfer_dn.cancel()
|
||||||
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1)
|
frappe.db.set_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1)
|
||||||
|
|
||||||
|
def test_sles_with_same_posting_datetime_and_creation(self):
|
||||||
|
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||||
|
from erpnext.stock.report.stock_balance.stock_balance import execute
|
||||||
|
|
||||||
|
item_code = "Test Item for SLE with same posting datetime and creation"
|
||||||
|
create_item(item_code)
|
||||||
|
|
||||||
|
pr = make_purchase_receipt(
|
||||||
|
item_code=item_code,
|
||||||
|
qty=10,
|
||||||
|
rate=100,
|
||||||
|
posting_date="2023-11-06",
|
||||||
|
posting_time="00:00:00",
|
||||||
|
)
|
||||||
|
|
||||||
|
sr = make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
source=pr.items[0].warehouse,
|
||||||
|
qty=10,
|
||||||
|
posting_date="2023-11-07",
|
||||||
|
posting_time="14:28:0.330404",
|
||||||
|
)
|
||||||
|
|
||||||
|
sle = frappe.db.get_value(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"voucher_type": sr.doctype, "voucher_no": sr.name, "item_code": sr.items[0].item_code},
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
|
||||||
|
sle_doc = frappe.get_doc("Stock Ledger Entry", sle)
|
||||||
|
sle_doc.db_set("creation", "2023-11-07 14:28:01.208930")
|
||||||
|
|
||||||
|
sle_doc.reload()
|
||||||
|
self.assertEqual(get_datetime(sle_doc.creation), get_datetime("2023-11-07 14:28:01.208930"))
|
||||||
|
|
||||||
|
sr = make_stock_entry(
|
||||||
|
item_code=item_code,
|
||||||
|
target=pr.items[0].warehouse,
|
||||||
|
qty=50,
|
||||||
|
posting_date="2023-11-07",
|
||||||
|
posting_time="14:28:0.920825",
|
||||||
|
)
|
||||||
|
|
||||||
|
sle = frappe.db.get_value(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"voucher_type": sr.doctype, "voucher_no": sr.name, "item_code": sr.items[0].item_code},
|
||||||
|
"name",
|
||||||
|
)
|
||||||
|
|
||||||
|
sle_doc = frappe.get_doc("Stock Ledger Entry", sle)
|
||||||
|
sle_doc.db_set("creation", "2023-11-07 14:28:01.044561")
|
||||||
|
|
||||||
|
sle_doc.reload()
|
||||||
|
self.assertEqual(get_datetime(sle_doc.creation), get_datetime("2023-11-07 14:28:01.044561"))
|
||||||
|
|
||||||
|
pr.repost_future_sle_and_gle(force=True)
|
||||||
|
|
||||||
|
columns, data = execute(
|
||||||
|
filters=frappe._dict(
|
||||||
|
{"item_code": item_code, "warehouse": pr.items[0].warehouse, "company": pr.company}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(data[0].get("bal_qty"), 50.0)
|
||||||
|
|
||||||
|
|
||||||
def prepare_data_for_internal_transfer():
|
def prepare_data_for_internal_transfer():
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||||
|
|||||||
@@ -1187,7 +1187,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
|
|||||||
qty=5,
|
qty=5,
|
||||||
posting_date="2021-01-01",
|
posting_date="2021-01-01",
|
||||||
rate=10,
|
rate=10,
|
||||||
posting_time="02:00:00.1234",
|
posting_time="02:00:00",
|
||||||
)
|
)
|
||||||
|
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -1199,7 +1199,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin):
|
|||||||
qty=100,
|
qty=100,
|
||||||
rate=10,
|
rate=10,
|
||||||
posting_date="2021-01-01",
|
posting_date="2021-01-01",
|
||||||
posting_time="02:00:00",
|
posting_time="02:00:00.1234",
|
||||||
)
|
)
|
||||||
|
|
||||||
sle = frappe.get_all(
|
sle = frappe.get_all(
|
||||||
|
|||||||
@@ -1543,7 +1543,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
|
|||||||
and (
|
and (
|
||||||
posting_datetime {operator} %(posting_datetime)s
|
posting_datetime {operator} %(posting_datetime)s
|
||||||
)
|
)
|
||||||
order by posting_datetime desc, creation desc
|
order by posting_date desc, posting_time desc, creation desc
|
||||||
limit 1
|
limit 1
|
||||||
for update""",
|
for update""",
|
||||||
{
|
{
|
||||||
@@ -1636,7 +1636,7 @@ def get_stock_ledger_entries(
|
|||||||
where item_code = %(item_code)s
|
where item_code = %(item_code)s
|
||||||
and is_cancelled = 0
|
and is_cancelled = 0
|
||||||
{conditions}
|
{conditions}
|
||||||
order by posting_datetime {order}, creation {order}
|
order by posting_date {order}, posting_time {order}, creation {order}
|
||||||
{limit} {for_update}""".format(
|
{limit} {for_update}""".format(
|
||||||
conditions=conditions,
|
conditions=conditions,
|
||||||
limit=limit or "",
|
limit=limit or "",
|
||||||
@@ -1753,7 +1753,7 @@ def get_valuation_rate(
|
|||||||
AND valuation_rate >= 0
|
AND valuation_rate >= 0
|
||||||
AND is_cancelled = 0
|
AND is_cancelled = 0
|
||||||
AND NOT (voucher_no = %s AND voucher_type = %s)
|
AND NOT (voucher_no = %s AND voucher_type = %s)
|
||||||
order by posting_datetime desc, name desc limit 1""",
|
order by posting_date desc, posting_time desc, name desc limit 1""",
|
||||||
(item_code, warehouse, voucher_no, voucher_type),
|
(item_code, warehouse, voucher_no, voucher_type),
|
||||||
):
|
):
|
||||||
return flt(last_valuation_rate[0][0])
|
return flt(last_valuation_rate[0][0])
|
||||||
@@ -2004,7 +2004,7 @@ def get_future_sle_with_negative_qty(args):
|
|||||||
and posting_datetime >= %(posting_datetime)s
|
and posting_datetime >= %(posting_datetime)s
|
||||||
and is_cancelled = 0
|
and is_cancelled = 0
|
||||||
and qty_after_transaction < 0
|
and qty_after_transaction < 0
|
||||||
order by posting_datetime asc
|
order by posting_date asc, posting_time asc
|
||||||
limit 1
|
limit 1
|
||||||
""",
|
""",
|
||||||
args,
|
args,
|
||||||
@@ -2018,14 +2018,14 @@ def get_future_sle_with_negative_batch_qty(args):
|
|||||||
with batch_ledger as (
|
with batch_ledger as (
|
||||||
select
|
select
|
||||||
posting_date, posting_time, posting_datetime, voucher_type, voucher_no,
|
posting_date, posting_time, posting_datetime, voucher_type, voucher_no,
|
||||||
sum(actual_qty) over (order by posting_datetime, creation) as cumulative_total
|
sum(actual_qty) over (order by posting_date, posting_time, creation) as cumulative_total
|
||||||
from `tabStock Ledger Entry`
|
from `tabStock Ledger Entry`
|
||||||
where
|
where
|
||||||
item_code = %(item_code)s
|
item_code = %(item_code)s
|
||||||
and warehouse = %(warehouse)s
|
and warehouse = %(warehouse)s
|
||||||
and batch_no=%(batch_no)s
|
and batch_no=%(batch_no)s
|
||||||
and is_cancelled = 0
|
and is_cancelled = 0
|
||||||
order by posting_datetime, creation
|
order by posting_date, posting_time, creation
|
||||||
)
|
)
|
||||||
select * from batch_ledger
|
select * from batch_ledger
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user