Skip to content

Commit

Permalink
chore: remove microsecond from posting_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Feb 21, 2024
1 parent f37f7ca commit a73ba2c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 21 deletions.
10 changes: 4 additions & 6 deletions erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,24 +1611,22 @@ def test_negative_stock_reco(self):
item_code = "Test Negative Item - 001"
item_doc = create_item(item_code=item_code, is_stock_item=1, valuation_rate=10)

make_stock_entry(
se1 = make_stock_entry(
item_code=item_code,
posting_date=add_days(today(), -3),
posting_time="00:00:00",
purpose="Material Receipt",
target="_Test Warehouse - _TC",
qty=10,
to_warehouse="_Test Warehouse - _TC",
do_not_save=True,
)

make_stock_entry(
se2 = make_stock_entry(
item_code=item_code,
posting_date=today(),
posting_time="00:00:00",
purpose="Material Receipt",
source="_Test Warehouse - _TC",
qty=8,
from_warehouse="_Test Warehouse - _TC",
do_not_save=True,
)

sr_doc = create_stock_reconciliation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1227,15 +1227,15 @@ def test_backdated_sle_with_same_timestamp(self):
filters={"voucher_no": reciept1.name},
fields=["qty_after_transaction", "actual_qty"],
)
self.assertEqual(sle[0].qty_after_transaction, 105)
self.assertEqual(sle[0].qty_after_transaction, 5)
self.assertEqual(sle[0].actual_qty, 5)

sle = frappe.get_all(
"Stock Ledger Entry",
filters={"voucher_no": reciept2.name},
fields=["qty_after_transaction", "actual_qty"],
)
self.assertEqual(sle[0].qty_after_transaction, 100)
self.assertEqual(sle[0].qty_after_transaction, 105)
self.assertEqual(sle[0].actual_qty, 100)

@change_settings("System Settings", {"float_precision": 3, "currency_precision": 2})
Expand Down
9 changes: 1 addition & 8 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from frappe.model.meta import get_field_precision
from frappe.query_builder.functions import Sum
from frappe.utils import (
add_to_date,
cint,
cstr,
flt,
Expand Down Expand Up @@ -637,7 +636,7 @@ def get_sle_against_current_voucher(self):
posting_datetime = %(posting_datetime)s
)
order by
posting_datetime ASC, creation ASC
creation ASC
for update
""",
self.args,
Expand Down Expand Up @@ -1403,17 +1402,12 @@ def update_bin(self):
def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_voucher=False):
"""get stock ledger entries filtered by specific posting datetime conditions"""

args["time_format"] = "%H:%i:%s"
if not args.get("posting_date"):
args["posting_datetime"] = "1900-01-01 00:00:00"

if not args.get("posting_datetime"):
args["posting_datetime"] = get_combine_datetime(args["posting_date"], args["posting_time"])

if operator == "<=":
# Add 1 second to handle millisecond for less than and equal to condition
args["posting_datetime"] = add_to_date(args["posting_datetime"], seconds=1)

voucher_condition = ""
if exclude_current_voucher:
voucher_no = args.get("voucher_no")
Expand Down Expand Up @@ -1701,7 +1695,6 @@ def update_qty_in_future_sle(args, allow_negative_stock=False):
datetime_limit_condition = ""
qty_shift = args.actual_qty

args["time_format"] = "%H:%i:%s"
args["posting_datetime"] = get_combine_datetime(args["posting_date"], args["posting_time"])

# find difference/shift in qty caused by stock reconciliation
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ def get_combine_datetime(posting_date, posting_time):
if isinstance(posting_time, datetime.timedelta):
posting_time = (datetime.datetime.min + posting_time).time()

return datetime.datetime.combine(posting_date, posting_time)
return datetime.datetime.combine(posting_date, posting_time).replace(microsecond=0)
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,6 @@ def test_subcontracting_receipt_valuation_with_auto_created_serial_batch_bundle(
)
scr = make_subcontracting_receipt(sco.name)
scr.save()
for row in scr.supplied_items:
self.assertNotEqual(row.rate, 300.00)
self.assertFalse(row.serial_and_batch_bundle)

scr.submit()
scr.reload()

Expand Down

0 comments on commit a73ba2c

Please sign in to comment.