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