Clearing Posting Date on Duplication

As we migrate to ERPnext a minor repeated nuisance is that on duplicating a transaction (be it a sales order, purchase invoice, journal entry, etc.) user forgets to put correct Posting date for new transaction as that field already has a value (generally the date of the transaction being duplicated).

Can probably write a custom script for every doctype, but is there a way across the board to have the Posting date field be cleared on duplication? As it is a required field user will be reminded to choose if they forget.

Custom Script is you best shot. Because in nature duplicate is doing what it should do.

@Mohammad_Ahmad_Zulfi OK. Had preferred not to go that route as then need a custom script for every doctype can possibly be duplicated.

Also, what is the trigger for custom script, it is just a new transaction with some fields pre-filled. Not clear what field would advise this new transaction came from duplicate and not new?

Option 1
on page refresh check if the form is new.
frm.is_new() and compare the date field with today. If it is different set it to undefined and refresh the field. frm.refresh_field("fieldname")

Option 2
Add a custom menu button to replicate duplicate function. There you may set the posting date as undefined.

@Mohammad_Ahmad_Zulfi
Thanks will try on a few doctypes and see.

You are very Welcome

@Mohammad_Ahmad_Zulfi
Did not work.

Here is script

frappe.ui.form.on(“Purchase Invoice”, “refresh”, function(frm) {
if(frm.is_new())
{
frm.doc.posting_date = null;
frm.refresh_field(“posting_date”);
console.log(‘posting_date=>’ + frm.doc.posting_date + ‘<=’);
}
});

And here is console log showing script executed
posting_date=>null<=

But in form posting date still shows as todays date.

It should be undefined not null. Please try again.

frappe.ui.form.on(“Purchase Invoice”, “refresh”, function(frm) {
if(frm.is_new())
{
frm.doc.posting_date = undefined;
frm.refresh_field(“posting_date”);
console.log(‘posting_date=>’ + frm.doc.posting_date + ‘<=’);
}
});

Forgot to comment I had tried undefined first with same result. As I have other scripts using null effectively I was trying that.

that is not 100% true in all scenarios with ERPNext. I.e. if you duplicate a Supplier, the “Billing Currency” field is cleared, even if the original Supplier had a non-default currency.

Another example is a multi-currency Journal Entry. If you duplicate that all accounts involved are set to the default currency. The actual currency of any non-default currency accounts is not copied from the original document.

that actually is how a fresh document behaves. It has the current datetime as posting time.

@vrms Agree that duplicate does not always duplicate things like currency, reference number, description we would want it to.

Understood that fresh document is going to have today’s date, but it is being cleared by the script yet not shown as such in form.

not 100% clear what you mean here. is it that the script you had posted

  • clears the date completely and likewise you need to put it manually, or that
  • it does not clear the date at all and likewise the posting date of the original document stays intact?

It appears to do both though that is contradictory:

  • script clears posting date
  • script sends to console value of posting_date which confirms it is null (console.log(‘posting_date=>’ + frm.doc.posting_date + ‘<=’); results in posting_date=>null<= in console)
  • posting date value visible on form is still current date despite reading as null

Hope did not confuse issue more