ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How can I automatically submit Draft invoices based on a condition?

pos_point_of_sale

#1

Continuing the discussion from What's the best known restaurant POS integration?:

I’m integrating SambaPOS with ERPNext directly from MS SQL database to Frappe API through Myddleware. I have successfully received Sales Invoices into ERPNext but they are in Draft mode.

I think a script running every 5 minutes would do this, it needs to a condition so that it’s not attempting to send the wrong Invoices, e.g. Checks only draft Sales Invoices with from_sambapos=1

I think a second condition is necessary. In case of an increasing number of invoices not submitting due to some error. Only Draft invoices with auto_submit_attempted=0 should also be a condition and should be set to 1 by the script after first attempt.

How would such a script look? I’m quite new to ERPNext scripting. What kind of script would work without the user taking any action?

Below is my attempt. But I keep getting console issues like base_amount… and Frappe call… @

frappe.ui.form.on('Sales Invoice', {
   refresh(frm) {
    
   	if (frm.doc.docstatus===0 && frm.doc.auto_submit_attempted === 0){
	    
    	frm.doc.docstatus = 1;
        frm.save();
        
        frm.doc.auto_submit_attempted = 1;
	}
  }
})

#2

Hi
you can write your script on py side and can use doc.submit() to submit your documents.


#3

@lokesh

I think that’s the better version. But I can only find database examples for server side scripting.

Could you kindly guide me on how to do it, with a sample to start from if possible?

Thank you for your time.


#4

Hi
Please explain me the whole scenario, when you want to submit the document? when user open the draft mode document or when user saves the new document in draft mode and then immediately it should get submitted.


#5

Hello @lokesh

Thank you for your interest in helping. Please note that we have already developed a script to do this. The only remaining step is to reduce the interval to 5minutes from 1 hour