Generate auto name for sales order as random digits only without letters

Hello Guys,

Could you please advise if it is possible to generate random digits only in naming series or any other way.

Thank you
Abduljaleel

I would say yes that is doable -

Possibly this library https://docs.python.org/2/library/random.html might work, where the integer sequence does not repeat. You may want to browse https://github.com/frappe/frappe/blob/develop/frappe/model/naming.py

As you say, a server side script with the naming_series you require that implements the ‘autoname’ method for the SalesOrder DocType.

It’s doable. By combining @clarkej random python library and the autoname function you won’t have to do any checking for duplicate names, though you’ll need to error handle it I think.

Here’s how I approached it - take out the business logic and drop in the randomization function.

Hi @abduljalyl, Let me walk you through how I’d approach this. You’ll need beginner python skills and some patience.

  1. Use the before_insert function to:
    A) Generate your random number
    B) Assign that random number as part of your autoname key
    C) Generate the name key:
    self.meaningful_name = frappe.model.naming.make_autoname(name_key, self, self)
  2. Add a docfield called meaningful_name, which should probably be hidden. Set the Auto Name in the Doctype to:
    field:meaningful_name
    image

Good luck and post your results back here so that others can benefit from your efforts.

Thank you very much, I will try it and get back to you.

Abduljaleel