From a73ba2c0d26b9d27bb5a75bc6c9739e49035f266 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 21 Feb 2024 17:32:02 +0530 Subject: [PATCH] chore: remove microsecond from posting_datetime --- erpnext/stock/doctype/stock_entry/test_stock_entry.py | 10 ++++------ .../stock_ledger_entry/test_stock_ledger_entry.py | 4 ++-- erpnext/stock/stock_ledger.py | 9 +-------- erpnext/stock/utils.py | 2 +- .../test_subcontracting_receipt.py | 4 ---- 5 files changed, 8 insertions(+), 21 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 99c050afa2..9d1a3f7e62 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -1611,24 +1611,22 @@ class TestStockEntry(FrappeTestCase): 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( diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 26c5c6400b..40a2d5a566 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -1227,7 +1227,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin): 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( @@ -1235,7 +1235,7 @@ class TestStockLedgerEntry(FrappeTestCase, StockTestMixin): 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}) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index e8bd3fcbb1..2ae6c197a1 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -11,7 +11,6 @@ from frappe import _, scrub 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, @@ -637,7 +636,7 @@ class update_entries_after(object): posting_datetime = %(posting_datetime)s ) order by - posting_datetime ASC, creation ASC + creation ASC for update """, self.args, @@ -1403,17 +1402,12 @@ class update_entries_after(object): 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") @@ -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 diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 5dc9dd45ab..93e2fa46c7 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -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) diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py index 5523c318a5..0450038d80 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py @@ -643,10 +643,6 @@ class TestSubcontractingReceipt(FrappeTestCase): ) 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()