@Pejay
How much transaction you have from 12/31/2024 to today’s date?
if count is huge then it may slowdown system when you try to change, because when you enter date 12/31/2024, system will auto update next SLE entries for that item and warehouse.
Although you can write a script to update date and also update Stock Ledger Entry, You can use existing function update_stock_ledger/ repost_future_sle_and_gle, but its not recommended.
best way is you can change posting date in delivery note and stock ledger entry.
Run Repost Item Valuation , while running this select oldest modified delivery note
Sample script from AI, check once in test delivery note.
import frappe
def fix_delivery_note_date(dn_name, new_posting_date, new_posting_time="12:00:00"):
"""
Fix delivery note date using db_set and repost item valuation
"""
# Step 1: Update Delivery Note dates using db_set
dn = frappe.get_doc("Delivery Note", dn_name)
dn.db_set("posting_date", new_posting_date, update_modified=False)
dn.db_set("posting_time", new_posting_time, update_modified=False)
# Step 2: Update related Stock Ledger Entries
sle_list = frappe.get_all(
"Stock Ledger Entry",
filters={
"voucher_type": "Delivery Note",
"voucher_no": dn_name,
"is_cancelled": 0
},
pluck="name"
)
for sle_name in sle_list:
frappe.db.set_value(
"Stock Ledger Entry",
sle_name,
{
"posting_date": new_posting_date,
"posting_time": new_posting_time
},
update_modified=False
)
# Step 3: Update related GL Entries (if any)
gl_entries = frappe.get_all(
"GL Entry",
filters={
"voucher_type": "Delivery Note",
"voucher_no": dn_name,
"is_cancelled": 0
},
pluck="name"
)
for gl_name in gl_entries:
frappe.db.set_value(
"GL Entry",
gl_name,
{
"posting_date": new_posting_date
},
update_modified=False
)
frappe.db.commit()
# Step 4: Create Repost Item Valuation for each item
for item in dn.items:
repost = frappe.get_doc({
"doctype": "Repost Item Valuation",
"posting_date": new_posting_date,
"posting_time": new_posting_time,
"item_code": item.item_code,
"warehouse": item.warehouse,
"allow_negative_stock": 1,
"via_landed_cost_voucher": 0
})
repost.insert(ignore_permissions=True)
repost.submit()
print(f"Created Repost Item Valuation: {repost.name} for {item.item_code}")
return f"Updated {dn_name} to {new_posting_date}"
# Usage
# fix_delivery_note_date("DN-00123", "2025-11-15", "14:30:00")