Naming Series based on posting date

Hi,

I have created naming series of sales Doctype based on .YY.MM. but it takes year & month of system date. I want to generate YY.MM based on document date / posting date. Any ideas how to do it.

I want to implement this feature in multiple doctypes. Any common solution which will used naming series based on posting date in similar doctypes ?

Ravi Modi

1 Like

Hello,

You can try setting the following in Naming Series (SINV-.posting_date.-.####):

However, this will also fetch the date with the month and the year as shown below.

Hope this helps.

what do you mean by “posting date” vs “system” date? ERPNext default behavior creates the number in the moment the document is created (unless to change that manually) no matter when you Submit it. I’d say it is not possible to change that, so the number is generated based on the date of the submit.

I think the term posting_date as in @michelle’s suggestion is a bit misleading because it does not refer to the moment of clicking SUBMIT but the moment when you SAVE a document for the first time.

The “Posting Date” in the previous suggestion is the field, posting date in the invoice document. This is editable and based on that, the naming series will be set if SINV-.posting_date.-.#### is set as the naming series.

@Ravi_Modikindly elaborate the term posting date in your query.

ok thanks for clarifying.

Do you know whether there is a way to influence the format (default seems to be yyyy-mm-dd) that posting_date is displayed (like yymmdd or ddmmyy i.e.) in the document number or whether it is related to the date format you have defined in the company Settings?

Hello,

Thanks for your suggestion. Can I extract only year (last 2 digits) and month (2 digits) from posting date. I want my document numbers to restart every month and not every day.

You can add naming series as SINV-.YY.-.DD.-.#### This will give you the desired result

Sales Invoice :

In this format YY & DD is taken from system date. I want YY DD to be taken from document date. For eg. if today on 26-Apr-2020 & I enter Sales BIll having date of march month, then I want the Series should be SINV-20-03-##### but ERPNEXT will take the series consisting of 20-04 .

1 Like

As of now, if you set it as posting date the entire date (yy-mm-dd) format will be captured. As an alternative, you can create a custom field with only year and month and set it to hidden. And configure the naming series as per the custom field.

Hope this helps.

1 Like

Hi,
I have created custom field & through custom scrip update required data from posting_date and able to generate series properly as required.

Now I am having another issue. I am creating opening inovices through Opening Invoice Creating Tool. This tool updated Sales Invoice Doctype. When Opening Invoice are added through this tool, this custom field is not populated properly due to which series is not generated as required. I feel there is bug in Opening Invoice creation tool.

1 Like

Is there a new solution without having to create a new hidden custom field?

Thank you!

I have created this custom code for my purchase orders and others. You can use it in client script.

frappe.ui.form.on('Purchase Order', {
	validate(frm) {
	    
    frm.doc.naming_series = "";	
	    
	let year = frm.doc.transaction_date.slice(2,4);
	let month = frm.doc.transaction_date.slice(5,7);
	let day = frm.doc.transaction_date.slice(8,10);
	
	frm.doc.naming_series += "POR-" + day + month + year + "-.#####";
	
	}
	
	
})