I created a field in the sales invoice doctype, and I want to validate the field name so that a particular data cannot be used multiple times to create a sales invoice. That is to say that if a user wishes to select data that has already been used to raise a sales invoice, the application will prevent the user from selecting the data, and then prompt a user to select a different data out of several other options in a drop-down list of items.
Here is my custom python script:
def clean_unique_id(self): unique_id = self.clean_unique_id.get(‘unique_id’) if(unique_id == ‘’"): frappe.msgprint(‘This field cannot be left blank’) for doc in frappe.get_doc('Sales Invoice'): if doc.unique_id == unique_id: frappe.throw(title='Error', msg='This plot number is no longer available', exc=ValidationError)
After writing this script, I was still able to raise a sales invoice multi times.
I will be immensely grateful if you can correct my custom script if it’s wrong and guide me on how I can achieve my desired aim with this script.
Thank you very much.