Naming series, multiple companies, different counter


In case anyone has encounter this problem, I have a requirement where I need an installation with 4 companies (A,B,C,D). Those companies use the same naming series for government fiscal control, but they have different counters.

Let’s say company “A” has generated NR00025 series but company “B” needs NR00008. Is there a way to accomplish this or is it recommended to have all companies on separate tenants?


1 Like

If you are having custom application then you can use autoname doc_events in hooks to execute method for custom naming series according to your requirement.

Its not a custom app, its same erpnext, is there a way to do it by custom script?

first of all
is it recommended to have all companies on separate tenants? → you can manage multi-company in single-tenant that is why the multi-company structure has been provided in ERPNext.

Naming Series → by below method you create your own naming series

def autoname(self):

Thank you @khushal_t given the type of naming series we need is why I am asking the “tenant thing”.

Maybe is more the logic I should find than the ERPNext capability. Since it will be same name but different counters, because in DB I can’t have same name with different counter, I will probable need to prefix the abbr of the company and then clear that part when I am going to show it on invoices.

Given that solution where can I set it? your code seems like python, I am not making custom APP maybe custom changes through custom script, is that possible? I don’t want to mess with code unless mandatory.

As of v12 you can use fieldnames in the auto name field for a doctype. You have to add the field in braces and separated by periods.

For example {company}.-LET-.##### would give something like A-LET-00001 as long as the company field exists otherwise it just gives -LET-00001

Getting just the company abbr, I guess you could add a custom field to a doctype and write a custom script to fetch the abbr with the company.

For Doctypes that use a naming series field, you can just use the naming series page to modify it.


Will work, if you simply create a custom filed in doctype Sales Invoice, with following details:

And there you have it.

You may choose to hide the above filed.

1 Like

yeah, it works.

When i use the .abbr. function at start it gives an error … it in only works for 1 doc series. If i want to use it for another doc series it doesnt work. e.g. abbr.-sales-#### would work but when i add abbr.-purchase-#### it gives error that the series already exists in sales.

What is it that you are actually looking to achieve?

I want all naming series to start with the company abbreviation. e.g. sales invoice, purchase invoice, sales order, etc. each to start with company abbreviation:
Sales Invoices : .abbr.-SINV-####
Sales Order : .abbr.-SO-####
Purchase Invoices : .abbr.-PINV-####
Purchase Quotation : .abbr.-PQ-####


We can create an app for you that can handle this.

What is your budget for it?

You do not need an app

Follow the steps below

In each of the doctypes create a custom field for company abbreviation. Let it fetch from company ( use company.abbr in the “fetch from” field).

You can then use this abbreviation in the naming series as follows


abr in this case is the name of the custom field you created for the doctype

This should work, ask more questions if it does not


1 Like

@olamide_shodunke Thanks for support.

I had already created the custom fields. The issue is that when I use abr in naming series of one doc it works fine but when i add it to a second doc, it gives error that already used.
e.g. {{abr}}.-PINV-.YYYY works fine but as soon as I add {{abr}}.-SINV-.YYYY, it is not allowed by system showing an error that this already exists for Purchase Invoice. Now this is technically incorrect as {{abr}}.-SINV is not used in any other doc. But somehow using the .abr. field second time as a first prefix in naming series results in error.

change the name of the custom fields in each doctype

pabr for purchase invoice sabr for sales invoice etc



@olamide_shodunke Thanks mate!!! Got it Working.

Maybe this picture can further help future readers. It took us quite a while to understand the system with all the fragmented information around.