How to set default return sales invoice series for sales return?

I tested creating a sales return. I opened the source delivery note and created a sales return, checked the Issue Credit Note checkbox so that a Credit Note will be automatically created and submitted the new sales return. Everything went okay except that the Return Sales Invoice series it used was for the new Sales Invoice being the default and not the Return Sales Invoice series. Is there a way i can define a default Return Sales Invoice series? Thanks.

Hi @jon632,

that for please apply custom/client script.

frappe.ui.form.on('Sales Invoice', {
	refresh(frm) {
	    if (frm.doc.is_return == 1) {
	        frm.set_value('naming_series',"ACC-SINV-RET-.YYYY.-");
	    //  frm.set_value('naming_series',"Set your series here");
	    }
	},
	
	is_return(frm) {
	    frm.set_value('naming_series',"ACC-SINV-RET-.YYYY.-");
    //  frm.set_value('naming_series',"Set your series here");
	}
});

Then reload and check it.

Thank You!

Thanks! I will try it!

Hi! @Solufy,

I tried your script and it worked but I noticed something, when I checked Is Return (Credit Note), it changed the series into the return series but when i unchecked it, the series remained the return series. With that, I tweak your script a little bit and now when I check that option it changes to the return series and when I uncheck, it also changes to the sales series.

frappe.ui.form.on('Sales Invoice', {    
  refresh(frm) {
      if (frm.doc.is_return == 1) {
        frm.set_value('naming_series',"SI-RET-.abbr.-.YYYY.-.#####");
      }
      else {
        frm.set_value('naming_series',"SI-.abbr.-.YYYY.-.#####");
      }
	},

	is_return(frm) {
          if (frm.doc.is_return == 1) {
            frm.set_value('naming_series',"SI-RET-.abbr.-.YYYY.-.#####");
	  }
          else {
            frm.set_value('naming_series',"SI-.abbr.-.YYYY.-.#####");
          }

	}

})

I hope you find this helpful.

Thanks.

Good :+1: @jon632

Instead of client script, you can use Document Naming Rule

That is also a good idea. Thanks a lot!

@ahmed.sharaf,

Hi! I tried to do your suggestion of using Document Naming Rule, it works but my naming series is SI-RET-.abbr.-.YYYY.-.##### where abbr is the abbreviation of the company defined in the Company Master and YYYY is the current year. This doesn’t work, it takes the entire naming series as prefix and doesn’t replace the correct value. Do you have any idea how will I make this work?

Thanks.

I’m trying this solution for auto naming series for Sales Return but it will still use the default naming starting with INV-22-11-#### instead of RF-22-11-####

image

any idea how to make this work?