Rename Sales Invoice to similar to Sales Order name

Hi Guys,

Due to using an external Accounts system, we need to rename the Sales Invoice to be similar to the Sales Order. Sales order prefix is M and I was going to have Sales Invoice prefix set to M-.

I have a custom script setup to do this via user button click:

frappe.ui.form.on('Sales Invoice', 'refresh', function(frm){
var sales_order = frm.doc.items[0].sales_order;
if (!frm.doc.__islocal & !frm.doc.docstatus & frm.docname != sales_order){
    cur_frm.add_custom_button(__('Rename Invoice '), function(){{
        method: 'frappe.model.rename_doc.rename_doc',
        args: {
            doctype: frm.doctype,
            old: frm.docname,
            "new": sales_order.replace('M','M-'),
            "merge": false
      callback: function(r){cur_frm.refresh();}

And my Sales Invoice prefix is set to M-. However when clicking the button to rename I get the message:

Sales Invoice not allowed to be renamed

Shouldn’t this work - if not what do I need to change to:

a. get this working


b. once working make it fully automated - ie no button clicking necessary just update on Submit?


Renaming isn’t permitted for a user because the naming is a sequence. Imaging people changing the sequence. It could cause a lot of problems.

The workaround is to set a property setter record that allows rename of Sales Invoice. But I wouldn’t recommend that. Renaming a name based on series manually could cause problems if not carefully handled.

What you need is a patch to rename all Sales Invoices at a go! If you are on cloud, we can help you out with that. Just drop a mail on support.


Hi @anand I can understand it causing problems if users could edit manually but:

a. there’s a duplicate checker inbuilt - I know because at first I had it trying to generate I00020 (again) so you have that covered :smile:

b. It’s only able to be renamed via the button script so there is no “free” ability for the user to choose their number.

Given we can’t generate a duplicate Sales Order I think we’re safe in doing it this way.

But I’m interested in your support option - how would the patch work? System Manager clicks a button and it renames? I will send the email and go from there.



The problem isn’t duplication, it is skipping a number in the sequence. eg. a user renames ABC-2002 to XYZ-2020, when he/she was supposed to rename it to XYZ-2002.

The patch will rename all sales invoices in one go. Isn’t that better for consistency rather than renaming only a few invoices?

If you still want to go ahead with your custom script, create a property setter document for Sales Invoice with “allow_rename” as 1. But this is could lead you into an unknown territory, so test all possibilities and eventualities in a test setup.


Hi @anand, thanks for the response. Unfortunately Support have declined to make the patch script:

Sorry Liam, I have discussed with the team internally, we will not be able to write customised script for this. This will require a server side script to overwrite standard autoname function. And you know there are no provision for custom server script for cloud users.

The chance for renaming to the wrong value is much reduced (removed) by only giving the user the button option like I have which forces the value to be correct with no user intervention or typing required. I think that’s safe enough that I’m prepared to try it.

My problem now is the inability on frappecloud to enable Property Setter mode - is that possible or is that only available on self hosted servers?

Thanks again