This generates a serial number based on set parameters.
Custom Script:
Enter this into your custom script file for ‘Stock Entry’
frappe.ui.form.on("Stock Entry Detail", {
generate_serial_sequence: function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
var serial_number = d.starting_number;
var serial_array = [];
var sequence_number = 0;
if(d.starting_number > d.end_number) {
msgprint("Starting serial sequence number must not be larger than end number.");
} else if((d.end_number - d.starting_number) > 100) {
msgprint("Maximum 100 serial numbers.");
} else {
while ( serial_number <= d.end_number) {
serial_array.push(d.prefix + serial_number);
if(!d.serial_no) {
frappe.model.set_value(d.doctype, d.name, 'serial_no', serial_array[sequence_number]);
} else{
frappe.model.set_value(d.doctype, d.name, 'serial_no', d.serial_no + "\n" + serial_array[sequence_number]);
} serial_number++;
sequence_number++;
}
}}
});
Custom Fields:
Copy this into a text editor and save as .csv, then use the import tool to upload.
Data Import Template,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Table:,Custom Field,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Notes:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Please do not change the template headings.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
First data column must be blank.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"If you are uploading new records, leave the ""name"" (ID) column blank.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"If you are uploading new records, ""Naming Series"" becomes mandatory, if present.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Only mandatory fields are necessary for new records. You can delete non-mandatory columns if you wish.,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"For updating, you can update only selective columns.",,,,,,,,,,,,,,,,,,,,,,,,,,,,,
You can only upload upto 5000 records in one go. (may be less in some cases),,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
DocType:,Custom Field,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Column Labels:,ID,Document,Field Type,Label,Fieldname,Insert After,Precision,Options,Collapsible,Collapsible Depends On,Default Value,Depends On,Field Description,Permission Level,Width,Is Mandatory Field,Unique,Read Only,Ignore User Permissions,Hidden,Print Hide,Print Hide If No Value,No Copy,Allow on Submit,In Report Filter,In List View,In Standard Filter,Report Hide,Ignore XSS Filter
Column Name:,name,dt,fieldtype,label,fieldname,insert_after,precision,options,collapsible,collapsible_depends_on,default,depends_on,description,permlevel,width,reqd,unique,read_only,ignore_user_permissions,hidden,print_hide,print_hide_if_no_value,no_copy,allow_on_submit,in_filter,in_list_view,in_standard_filter,report_hide,ignore_xss_filter
Mandatory:,Yes,Yes,Yes,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No,No
Type:,Data (text),Link,Select,Data,Data,Select,Select,Text,Check,Code,Text,Code,Text,Int,Data,Check,Check,Check,Check,Check,Check,Check,Check,Check,Check,Check,Check,Check,Check
Info:,,Valid DocType,"One of: Attach, Attach Image, Button, Check, Code, Column Break, Currency, Data, Date, Datetime, Dynamic Link, Float, HTML, Image, Int, Link, Long Text, Password, Percent, Read Only, Section Break, Select, Small Text, Table, Text, Text Editor, Time",,,,"One of: 1, 2, 3, 4, 5, 6, 7, 8, 9",,0 or 1,,,,,Integer,,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1,0 or 1
Start entering data below this line,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"""Stock Entry Detail-serial_number_generator""",Stock Entry Detail,Section Break,Serial Number Generator,serial_number_generator,transfer_qty,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-prefix""",Stock Entry Detail,Data,Prefix,prefix,serial_number_generator,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-cbsng2""",Stock Entry Detail,Column Break,,cbsng2,end_number,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-starting_number""",Stock Entry Detail,Int,Starting Number,starting_number,cbsng1,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-end_number""",Stock Entry Detail,Int,End Number,end_number,starting_number,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-cbsng1""",Stock Entry Detail,Column Break,,cbsng1,prefix,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,"""Stock Entry Detail-generate_serial_sequence""",Stock Entry Detail,Button,Generate Serial Sequence,generate_serial_sequence,cbsng2,,,0,,,,,0,,0,0,0,0,0,0,0,0,0,0,0,0,0,0
This limits you to generating 100 serial numbers at a time, in case of a typo.