Automatic Numbering from Customer's Criteria

Hello Eldy.
Greetings of the day.

I have Installed and started learning Dolibarr 19.0.1. It is like a charm and full with features. I found it more powerful than SAP.

I have a question on Automatic Numbering of each Third Party Like this :
TP Name : ABC Cement
TP Type : Customer
TP Country : India (IN)
TP State : Gujrat (GJ)

So Code will be “C8I-AC(IN)-(GJ)-000001”
Where, C8I = Prefix (anything Predefined)
AC = A(First Letter of Party), C(first letter of Type - C/P/V)
(IN) = Country Code
(GJ) = State Code
000001 = Serial Number

Similarly “C8I-AV(IN)-(GJ)-000001” for Vendor & “C8I-AP(IN)-(GJ)-000001” for Prospect

How to apply this mask.

Kindly help.
Regards
Alok

I think that what you’re asking for is not possible with the current automatic customer reference generation system in Dolibarr, mainly due to the fact that the code is generated PRIOR to the creation of the third party.

So, when you load the empty form to populate the data for the new third party, Dolibarr has pre-populated the “Customer code” and “Vendor code” fields.

The good news is that you can modify those values, because these text boxes are not blocked. But obviously, it’s not convenient to manually build a customer code as complicated as yours: C8I-AP(IN)-(GJ)-000001.

Furthermore, maybe you want the incremental integer 000001 to follow a different counting for each prefix like C8I-AP(IN)-(GJ)- ?

So, it seems that if you need an automatic code generation so “complex” and AFTER having populated fields like those involved in the code (name of customer, type, country, and state), the only way to do it 100% correctly would be using a “hook” which is executed when saving the record in the database and detecting, for example, if the “customer code” is empty. If it is, then the function executed by the hook could build this “complex” customer code and assign it to this customer.

To preserve this hook when updating your Dolibarr, the proper way to implement it is to generate a third-party module to be installed in your Dolibarr. These modules can define a function to respond to this hook.

If you’re interested in developing something like this, please DM. I could do that with 2 hours of work.

Disclaimer: Maybe some other people might suggest an alternative that doesn’t require developing PHP code. But I see that this post is from 4 months ago, so I’m probably on the right track.

Cheers