Erpnext server error 'limit 1 offset 0'

Hi all, I create a client script to handle batch description duplication. No same batch description is allowed ( From Stock > Batch )

frappe.ui.form.on(‘Batch’, {
validate(frm) {

	if (frappe.db.exists('Batch', {'description': frm.doc.description}))
	{
	   frappe.throw(__('Already exist, kindly provide a unique Batch Description')) 
               frappe.validated = false;                                                    
    }
  }
}

)

When I try to create a new batch, by entering the existing batch description to test the code, below error is displayed.

image

I did not found anything helpful regarding the error. Therefore I am seeking advise/helpful explanations for the above errors. What does it means? And did my code need amendment ? Kindly let me know. Any help is much appreciated.

Thank you.

“Copy error to clipboard” and paste here?

Hi Ankush, below are the code copied over :

App Versions

{
	"erpnext": "13.32.0",
	"frappe": "13.31.0"
}

Route

Form/Batch/new-batch-1

Trackeback

Syntax error in query:
select `name`
			from `tabBatch`
			where `tabBatch`.`name` = {'description': 'F2102021-001'}
			
			 order by `tabBatch`.`naming_series` DESC
			limit 1 offset 0

Request Data

{
	"type": "GET",
	"args": {
		"doctype": "Batch",
		"fieldname": "name",
		"filters": "{\"name\":{\"description\":\"F2102021-001\"}}"
	},
	"headers": {},
	"error_handlers": {},
	"url": "/api/method/frappe.client.get_value"
}

Response Data

{}

Oh well this just looks like an issue with the way function is called. Client-side DB functions aren’t same as server side.

You’ll have to use frappe.db.get_value, something like:

frappe.db.get_value("Batch", {"description": new_desc}, "name")

Also, client-side DB calls are async, so you need to use returned promises or pass a callback.


Alternatively, you can just add a “unique” constraint on that field without doing these custom validations.

My apologize, I was reading the answer by mistakes.

Adjusted the code as you guide :

frappe.ui.form.on(‘Batch’, ‘validate’, function(frm) {

	frappe.call({
    method: "frappe.client.get_value",
    args: {
            doctype: "Batch",
            fieldname: "name",
            filters: {
                    description: frm.doc.description,
		            //supplier: frm.doc.supplier
		
            }
    },
    callback: function(response) {
         var description = response.message;
         if (description) {
              frappe.msgprint("Same Batch Desc already Exist in Record.");
		validated=false;
			return false;		
         }
    }

However where I tried to create new Batch with different Batch Description, its still unallowed me to do so. Can you point me where I should make the improvement in the code ?

image

If you mean from Customize menu option, I tried but below message is prompted :

image

I believe this is because there are already Batch with same Batch Description. Another cause of this custom validation is because we want to handle specific condition where same Supplier cannot have same Batch Description at 1 time.

Any other suggestion/advise ?

Hi @ankush ,

thankyou for your help and guide, I am able to solved it.

I refer to these as a reference as well :

  1. https://discuss.frappe.io/t/validate-duplication-on-two-fields/37285/4

  2. https://discuss.frappe.io/t/valididation-of-no-duplication-in-item-price/82808

Thankyou once again.

1 Like