fix: same posting date and time causing incorrect valuation rate (#42351)
(cherry picked from commit 85d2d34116)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -1918,6 +1918,93 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
returned_serial_nos = get_serial_nos_from_bundle(dn_return.items[0].serial_and_batch_bundle)
|
||||
self.assertEqual(serial_nos, returned_serial_nos)
|
||||
|
||||
def test_same_posting_date_and_posting_time(self):
|
||||
item_code = make_item(
|
||||
"Test Same Posting Datetime Item",
|
||||
properties={
|
||||
"has_batch_no": 1,
|
||||
"create_new_batch": 1,
|
||||
"batch_number_series": "SS-ART11-TESTBATCH.#####",
|
||||
"is_stock_item": 1,
|
||||
},
|
||||
).name
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code=item_code,
|
||||
target="_Test Warehouse - _TC",
|
||||
qty=100,
|
||||
basic_rate=50,
|
||||
posting_date=add_days(nowdate(), -1),
|
||||
)
|
||||
|
||||
batch_no = get_batch_from_bundle(se.items[0].serial_and_batch_bundle)
|
||||
|
||||
posting_date = today()
|
||||
posting_time = nowtime()
|
||||
dn1 = create_delivery_note(
|
||||
posting_date=posting_date,
|
||||
posting_time=posting_time,
|
||||
item_code=item_code,
|
||||
rate=300,
|
||||
qty=25,
|
||||
batch_no=batch_no,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
dn2 = create_delivery_note(
|
||||
posting_date=posting_date,
|
||||
posting_time=posting_time,
|
||||
item_code=item_code,
|
||||
rate=300,
|
||||
qty=25,
|
||||
batch_no=batch_no,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
dn3 = create_delivery_note(
|
||||
posting_date=posting_date,
|
||||
posting_time=posting_time,
|
||||
item_code=item_code,
|
||||
rate=300,
|
||||
qty=25,
|
||||
batch_no=batch_no,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
dn4 = create_delivery_note(
|
||||
posting_date=posting_date,
|
||||
posting_time=posting_time,
|
||||
item_code=item_code,
|
||||
rate=300,
|
||||
qty=25,
|
||||
batch_no=batch_no,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
for dn in [dn1, dn2, dn3, dn4]:
|
||||
sles = frappe.get_all(
|
||||
"Stock Ledger Entry",
|
||||
fields=["stock_value_difference", "actual_qty"],
|
||||
filters={"is_cancelled": 0, "voucher_no": dn.name, "docstatus": 1},
|
||||
)
|
||||
|
||||
for sle in sles:
|
||||
self.assertEqual(sle.actual_qty, 25.0 * -1)
|
||||
self.assertEqual(sle.stock_value_difference, 25.0 * 50 * -1)
|
||||
|
||||
dn5 = create_delivery_note(
|
||||
posting_date=posting_date,
|
||||
posting_time=posting_time,
|
||||
item_code=item_code,
|
||||
rate=300,
|
||||
qty=25,
|
||||
batch_no=batch_no,
|
||||
use_serial_batch_fields=1,
|
||||
do_not_submit=True,
|
||||
)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, dn5.submit)
|
||||
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
||||
@@ -300,6 +300,7 @@ class SerialandBatchBundle(Document):
|
||||
"batch_nos": {row.batch_no: row for row in self.entries if row.batch_no},
|
||||
"voucher_type": self.voucher_type,
|
||||
"voucher_detail_no": self.voucher_detail_no,
|
||||
"creation": self.creation,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -599,9 +599,15 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
||||
|
||||
timestamp_condition = ""
|
||||
if self.sle.posting_date and self.sle.posting_time:
|
||||
timestamp_condition = CombineDatetime(
|
||||
parent.posting_date, parent.posting_time
|
||||
) <= CombineDatetime(self.sle.posting_date, self.sle.posting_time)
|
||||
timestamp_condition = CombineDatetime(parent.posting_date, parent.posting_time) < CombineDatetime(
|
||||
self.sle.posting_date, self.sle.posting_time
|
||||
)
|
||||
|
||||
if self.sle.creation:
|
||||
timestamp_condition |= (
|
||||
CombineDatetime(parent.posting_date, parent.posting_time)
|
||||
== CombineDatetime(self.sle.posting_date, self.sle.posting_time)
|
||||
) & (parent.creation < self.sle.creation)
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(parent)
|
||||
|
||||
Reference in New Issue
Block a user