How to safely change the date of delivery note transaction from 02/05/2025 to 12/31/2024?

I’m working on a case where we need to update the Delivery Note date to reflect the correct posting month—specifically, to move the entry back to December 2024. This adjustment is purely for correction purposes to ensure the report shows accurate figures for that month. No other values or linked transactions need to be changed.

Best Regards,
Peter

You Can Do using System Console by writing a Script to update the dates
And Use frappe.db.set_value() so no validation Triggers and you can do it without affecting any other fields and flow

For Example:


dn_names = frappe.get_all("Delivery Note", filters={"posting_date": [">", "2024-12-31"]}, fields=["name"])
for dn in dn_names:
    frappe.db.set_value("Delivery Note", dn.name, "posting_date", "2024-12-01")
    frappe.db.commit()
    print(f"Updated {dn.name} to Dec 2024")

I would be cautious about changing values manually. If I’m not mistaken, Delivery Notes generate entries in both the stock ledger and the accounting ledger. Force-changing the date could lead to incoherent data.

1 Like

Please don’t :folded_hands:


Cancel and amend the delivery note

3 Likes

Yes, I think also of that way, but I am struggling with this process on how to solve this kind of problem. That I want to change the date backwards without affecting onwards transaction but since using Moving Average it requires to repost the onwards transaction.

any insights guys would be greatly appreciated. Thank you

@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")
1 Like

That’s 100% by design. If you change the data of a stock transaction retroactively, the valuation of your stock from that point forward is supposed to change. Why are you trying to avoid that? You’d be creating inconsistencies in your data.

1 Like

I understand that we need to use Reposting to maintain accurate data. However, the issue is this:

The transactions involved are from 2024. When ERPNext re-posts the item from 2024, it will re-evaluate the valuation rate, as well as all incoming and outgoing quantities. This will create significant changes in the GL Entries. The accounting team has already generated and reconciled the reports for that period.

Because of this, if we start the reposting from 2024, the accounting team would be required to regenerate and revalidate the financial reports for 2025.

I’m not an accountant, but my accountant always tells me that “accounting is done in pen, not pencil”.

I understand the problem you’re facing. But, you asked for a way to safely change the date of a delivery note transaction, and the answer is “There isn’t one”. Once an accounting period is closed, it’s immutable. That’s what closing the period means. This isn’t a limitation of the software but a fundamental principle of how accounting works.

If I were to ask my account how to move forward, I’m sure he would say “Either reopen and reprocess the period or leave it booked incorrectly and write a note in the report.” If needed, add an adjustment journal entry in the current period.

If you want to break that rule of accounting, you can. Frappe will let you do that, as described above in this thread. But, your books will be incoherent going forward. There’s no way around that.

2 Likes

Thank you for the explanation. You’re right and I fully understand the accounting principle that once a period is closed, it should remain unchanged.

I think that is all. Thanks again for the help

1 Like

This one also a best practice, you can create a report / calculate what difference you are having in system.
Once you know, you can simply pass adjustment journal entry for that difference instead of changing old records.

1 Like

You can do this using frappe.db.set_value() by using Python Script in System Console from UI
as I suggested above