Error while creating item variants

I,m using item code auto generation script from item group + brand . While creating variant I,m getting this error :

Traceback (innermost last): File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 57, in application response = frappe.handler.handle() File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle execute_cmd(cmd) File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd ret = frappe.call(method, **frappe.form_dict) File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 806, in call return fn(*args, **newargs) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/item_variant.py", line 120, in create_variant copy_attributes_to_variant(template, variant) File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/item_variant.py", line 135, in copy_attributes_to_variant variant.description += "\n" TypeError: unsupported operand type(s) for +=: 'NoneType' and 'unicode'

Here is my item code auto generation script

 cur_frm.cscript.custom_validate = function(doc) {
    // clear item_code (name is from item_code)
    doc.item_code = "";

    // first 2 characters based on item_group
    switch(doc.item_group) {
   // Woven Label starts here
        case "Care Label":
            doc.item_code = "CARL";
            break;
        case "Fit Label":
            doc.item_code = "FITL";
            break;
        case "Hanger Loop":
            doc.item_code = "HANL";
            break;
        case "Loop Label":
            doc.item_code = "LOOL";
            break;
        case "Main label":
            doc.item_code = "MAIL";
            break;
        case "Main with Size Label":
            doc.item_code = "MWSL";
            break;
        case "Neck Tape":
            doc.item_code = "NECT";
            break;
        case "Patch Label":
            doc.item_code = "PATL";
            break;
        case "Size Label":
            doc.item_code = "SIZL";
            break;
        case "Tab Label":
            doc.item_code = "TABL";
            break;
        case "Woven Tape Label":
            doc.item_code = "WOVT";
            break;
        case "Zipper Puller":
            doc.item_code = "ZIPP";
            break;
        // Printed Items Start Here
        case "Additional Hangtag":
            doc.item_code = "ADDH";
            break;
        case "Barcode Sticker":
            doc.item_code = "BARS";
            break;
        case "Box":
            doc.item_code = "BOX";
            break;
        case "Carton Sticker":
            doc.item_code = "CARS";
            break;
        case "Caution Sticker":
            doc.item_code = "CAUS";
            break;
        case "Common Tag":
            doc.item_code = "COMT";
            break;
        case "Feather Card":
            doc.item_code = "FEAC";
            break;
        case "Hang Tag":
            doc.item_code = "HANT";
            break;
        case "Hang Tag Film":
            doc.item_code = "HANTF";
            break;
        case "Hangar Card":
            doc.item_code = "HANC";
            break;
        case "Oeko Tex":
            doc.item_code = "OEKT";
            break;
        case "Oeko Tex Sticker":
            doc.item_code = "OEKTS";
            break;
        case "Off Sticker":
            doc.item_code = "OFFS";
            break;
        case "Photo Board":
            doc.item_code = "PHOB";
            break;
        case "Photo Card":
            doc.item_code = "NT";
            break;
        case "Poly Sticker":
            doc.item_code = "POLS";
            break;
        case "Price Tag":
            doc.item_code = "PRIT";
            break;
        case "Round Sticker":
            doc.item_code = "ROUS";
            break;
        case "UPF thirty Sticker":
            doc.item_code = "UPF3S";
            break;
        case "Waist Tag":
            doc.item_code = "WAIT";
            break;
        // Printed Label Starts Here
        case "Barcode Label":
            doc.item_code = "BARL";
            break;
        case "Printed care label":
            doc.item_code = "PRICL";
            break;
        // Other Items Start Here
        case "Gum Tape Navy Lock":
            doc.item_code = "GUMTNL";
            break;
        case "Gum Tape White":
            doc.item_code = "GUMTW";
            break;
        case "Hanger":
            doc.item_code = "HAN";
            break;
        case "Jute String":
            doc.item_code = "JUTS";
            break;
        case "PU Badge":
            doc.item_code = "PUB";
            break;
        case "PU Label":
            doc.item_code = "PUL";
            break;
        case "PU Puller":
            doc.item_code = "PUP";
            break;
        case "PVC Belt":
            doc.item_code = "PVCB";
            break;
        case "Safety Pins":
            doc.item_code = "SAFP";
            break;
        default:
            doc.item_code = "WL";
    }

    // add next 2 characters based on brand
    switch(doc.brand) {
        case "Colours of the world":
            doc.item_code += "COLOTW";
            break;
        case "Southern":
            doc.item_code += "SOU";
            break;
        case " Maxi blue":
            doc.item_code += "MAXB";
            break;
        case "Jean Pascale":
            doc.item_code += "JEAP";
            break;
        case "Flame":
            doc.item_code += "FLA";
            break;
        case "Page one":
            doc.item_code += "PAGO";
            break;
        case "Chapter":
            doc.item_code += "CHA";
            break;
        case "Dopodopo Boys":
            doc.item_code += "DOPB";
            break;
        case "Dopodopo Girls":
            doc.item_code += "DOPG";
            break;
        case "Dopo Dopo Mini Boys":
            doc.item_code += "DOPDMB";
            break;
        case "Dopo Dopo Mini Girls":
            doc.item_code += "DOPDMG";
            break;
        case "Dopo Dopo Newborn Boys":
            doc.item_code += "DOPDNB";
            break;
        case "Dopo Dopo Newborn girls":
            doc.item_code += "DOPDNG";
            break;
        case "Page One young":
            doc.item_code += "PAGOY";
            break;
        case "Pizza Over thirty":
            doc.item_code += "PIZOT";
            break;
        case "Pizza Boys Collection":
            doc.item_code += "PIZBC";
            break;
        case "Pizza Baby Boys collection":
            doc.item_code += "PIZBBC";
            break;
        case "Pizza Boys Easy basic":
            doc.item_code += "PIZBEB";
            break;
        case "Pizza Baby Boys easy basic":
            doc.item_code += "PIZBBEB";
            break;
        case "Pizza Boys Denim Easy Basic":
            doc.item_code += "PIZBDEB";
            break;
        case "Pizza Man":
            doc.item_code += "PIZM";
            break;
        case "Teddysmith":
            doc.item_code += "TED";
            break;
        case "Colors and Sons":
            doc.item_code += "COLS";
            break;
        case "Club Royal":
            doc.item_code += "CLUR";
            break;
        case "Hudsons Rivers":
            doc.item_code += "HUDR";
            break;
        case "Kitaro":
            doc.item_code += "KIT";
            break;
        case "QVC":
            doc.item_code += "QVC";
            break;
        case "Mcgragor":
            doc.item_code += "MCG";
            break;
        case "NZA":
            doc.item_code += "NZA";
            break;
        case "Gaastra":
            doc.item_code += "GAA";
            break;
        case "Denim":
            doc.item_code += "DEN";
            break;
        case "Ocean Cup":
            doc.item_code += "OCE";
            break;
        case "Box":
            doc.item_code += "BOX";
            break;
        case "Riyandunn":
            doc.item_code += "RIY";
            break;
        case "Pree Master":
            doc.item_code += "PREM";
            break;
        case "World Tui":
            doc.item_code += "WORT";
            break;
        case "Hangard Card":
            doc.item_code += "HANC";
            break;
        case "Custom Kit":
            doc.item_code += "CUSK";
            break;
        case "Bang Bang":
            doc.item_code += "BANB";
            break;
        case "Henus Edwin":
            doc.item_code += "HENE";
            break;
        case "White Sierra":
            doc.item_code += "WHIS";
            break;
        case "NT Gravel Gear":
            doc.item_code += "NTGG";
            break;
        case "Mister and Lady":
            doc.item_code += "MISL";
            break;
        case "Clride":
            doc.item_code += "CLR";
            break;
        case "Pizza Boys Denim Easy Basic":
            doc.item_code += "PIZBDEB";
            break;
        case "Pizza Man":
            doc.item_code += "PIZM";
            break;
        case "Teddysmith":
            doc.item_code += "TED";
            break;
        case "Colors and Sons":
            doc.item_code += "SCOLS";
            break;
        case "Club Royal":
            doc.item_code += "CLUR";
            break;
        case "Hudsons Rivers":
            doc.item_code += "HUDR";
            break;

        default:
            doc.item_code += "BX";
    }
}

Can anyone help please ?

Thanks

Hi @inventobd,

Getting an error because variant.description is blank, try below code
doc.description = doc.item_code after switch

Thanks, Rohit

Thanks a lot for your replay. Can you please tell me where to add this ? That will be a great help

After this code put doc.description = doc.item_code

Thanks

Thanks a lot man , it works perfectly fine . But now when I,m saving variants I,m getting duplicate item code error . I have changed item code , item name and item description but still it give me duplicate item code error .

Like when I have saved an item template with a code MLWSCOLOTW, my variant item code for it will be MLWSCOLOTW-XXS , but while trying to save it shows duplicate entry MLWSCOLOTW item code already exists