Numbering Counter Duplicate Issue

Dear Awesome Team,

We have implemented an increment counter for Purchase Order using the server script.
It basically numbers our PO as : OAA-PO-2024-06-24-1
where OAA-PO is fixed string.
2024-06-24 is PO Date field and
1 is the counter which gets incremented.

For eg, If I am creating 2nd PO with Date = 2024-06-24, then the numbering will be as : OAA-PO-2024-06-24-2.

Now, everything is going perfect except for few PAST dates for eg (date = 2024-06-24), PO creation fails with the below duplicate numbering issue. By some or other way, counter is not getting incremented and hence it is not allowing to create PO with same PO number.

Issue :

COunter Increment Server script:

frappe.msgprint(doc.name)

po = frappe.db.get_list(‘Purchase Order’,
filters={
‘transaction_date’: doc.transaction_date
},
fields=[‘custom_counter’, ‘name’, ‘amended_from’],
order_by=‘custom_counter desc’, # highest number first
page_length=1, # will return only first record
as_list=True
)

If we need to number get

if doc.amended_from is None:
if po:
if po[0][0] is None:
doc.custom_counter = 1
else:
doc.custom_counter = po[0][0] + 1

else:
    doc.custom_counter = 1

Pls can you help us understand why this script is generating duplicate no in few past dates for many other dates it goes well with expected numbering.

Thanks

you can refer this Set Current Value for Naming Series

1 Like

All the advices highly appreciated.

Last Naming Series Counter value is given below in the image as 51.

Below is the PO report view, which shows last PO’s created.

Since we have implemented this counter feature not from the start, I cant make out what shall be the last value of the counter from the report view.
So I am not clear how shall I update the Counter in the Document Naming settings Screen? to which value?

Pls share some useful clues on this. Glad to hear.

I just updated the Naming Series Counter from 51 to 52. It has solved the issue for now.
But still not clear as why it was not allowing only on that particular date and it was working fine on other past dates.

Anyways Thanks so much to Jeel.