nan = None
CD_file_format ={'IT': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="HD"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CLIENT': {'Processing': ['data[ci]="EM"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'STREAM_ID': {'Processing': ['data[ci]="IT"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}}}, 'IT': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'PRODUCT', 'DESCRIPTION', 'EXTRA_DESCRIPTION', 'BRAND/PRODUCT GROUP', 'MOQ', 'BARCODE_1 ( Unit)', 'BARCODE_2 ( Inner )', 'BARCODE_3 ( Outer )', 'INNER CARTON QTY', 'OUTER CARTON QTY', 'UNIT LENGTH', 'UNIT WIDTH ', 'UNIT HEIGHT', 'UNIT WEIGHT'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[PRODUCT]}|{data[DESCRIPTION]}|{data[EXTRA_DESCRIPTION]}|{data[BRAND/PRODUCT GROUP]}|{data[MOQ]}|{data[BARCODE_1 ( Unit)]}|{data[BARCODE_2 ( Inner )]}|{data[BARCODE_3 ( Outer )]}|{data[INNER CARTON QTY]}|{data[OUTER CARTON QTY]}|{data[UNIT LENGTH]}|{data[UNIT WIDTH ]}|{data[UNIT HEIGHT]}|{data[UNIT WEIGHT]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="IT"'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'ACTION_INDICATOR': {'Processing': ['data[ci]="U"'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'PRODUCT': {'Processing': ["data[ci]={var}['variations'][{index1}]['skus'][{index2}]['ean']\nif (not data[ci]) or (not isinstance(data[ci],str)):\n      error['IT']= 'No ean number'\n      error['send_to_CD'] = True\n      if 'sku_errors' in error.keys():\n          error['sku_errors'].append({var}['variations'][{index1}]['skus'][{index2}]['sku_number'])\n      else:\n          error['sku_errors']=[{var}['variations'][{index1}]['skus'][{index2}]['sku_number']]\n      blank_line[0] = True"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'DESCRIPTION': {'Processing': ["data[ci]={var}['variations'][{index1}]['skus'][{index2}]['product_name']"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'EXTRA_DESCRIPTION': {'Processing': ["data[ci]={var}['variations'][{index1}]['skus'][{index2}]['sku_number']"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'BRAND/PRODUCT GROUP': {'Processing': ["data[ci]={var}['variations'][{index1}]['skus'][{index2}]['category']"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'MOQ': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'BARCODE_1 ( Unit)': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'BARCODE_2 ( Inner )': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'BARCODE_3 ( Outer )': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'INNER CARTON QTY': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'OUTER CARTON QTY': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'UNIT LENGTH': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'UNIT WIDTH ': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'UNIT HEIGHT': {'Processing': ["data[ci]=''"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}, 'UNIT WEIGHT': {'Processing': ['data[ci]=""'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['variations'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['variations'][{index1}]['skus'])"]}}}}, 'OR': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="HD"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CLIENT': {'Processing': ['data[ci]="EM"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'STREAM_ID': {'Processing': ['data[ci]="OR"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}}}, 'OR1': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'CUST_ORDER_NUMBER', 'ORDER_DATE', 'E_T_D', 'VENDOR_ORD_NO', 'SHIP_TO_NAME', 'SHIP_TO_ADDRESS_1_1', 'SHIP_TO_ADDRESS_1_2', 'AREA', 'STATE', 'POSTCODE', 'COUNTRY', 'ORDER_TYPE', 'CARRIER_CODE', 'PHONE_NO', 'EMAIL_ADDRESS'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[ORDER_DATE]}|{data[E_T_D]}|{data[VENDOR_ORD_NO]}|{data[SHIP_TO_NAME]}|{data[SHIP_TO_ADDRESS_1_1]}|{data[SHIP_TO_ADDRESS_1_2]}|{data[AREA]}|{data[STATE]}|{data[POSTCODE]}|{data[COUNTRY]}|{data[ORDER_TYPE]}|{data[CARRIER_CODE]}|{data[PHONE_NO]}|{data[EMAIL_ADDRESS]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="OR1"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'ACTION_INDICATOR': {'Processing': ['data[ci]="A"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CUST_ORDER_NUMBER': {'Processing': ["data[ci]={var}['id']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'ORDER_DATE': {'Processing': ['data[ci]=str(datetime.strptime({var}[\'date\'],\'%Y-%m-%dT%H:%M:%S.%fZ\').replace(tzinfo=from_zone).astimezone(to_zone).strftime("%Y%m%d"))'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'E_T_D': {'Processing': ['data[ci]=""'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'VENDOR_ORD_NO': {'Processing': ["data[ci]={var}['order_number']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'SHIP_TO_NAME': {'Processing': ["data[ci]={var}['customer_name']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'SHIP_TO_ADDRESS_1_1': {'Processing': ["data[ci]={var}['address']['line_1']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'SHIP_TO_ADDRESS_1_2': {'Processing': ['line2 = {var}[\'address\'][\'line_2\']\nline3 = {var}[\'address\'][\'line_3\']\nif bool(line2) and (line3):\n     data[ci]=" ".join([{var}[\'address\'][\'line_2\'],{var}[\'address\'][\'line_3\']])\nelif bool(line2):\n     data[ci]={var}[\'address\'][\'line_2\']\nelif bool(line3):\n     data[ci]={var}[\'address\'][\'line_3\']\nelse:\n     data[ci]=""'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'AREA': {'Processing': ["address_error = checkAddressForError({var})\nif 'City Error' in address_error.keys():\n     data[ci] = 'Error'\n     error['OR']= 'Error in Address'\n     error['send_to_CD'] = False\n     error['address_error'] = address_error\n     error['City data received']={var}['address']['city']\nelse:\n     data[ci]={var}['address']['city']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'STATE': {'Processing': ["address_error = checkAddressForError({var})\nif 'Aust State Error' in address_error.keys() :\n     data[ci] = 'Error'\n     error['OR']= 'Error in Address'\n     error['send_to_CD'] = False\n     error['address_error'] = address_error\n     error['State data received']={var}['address']['state']\nelse:\n     data[ci]={var}['address']['state'].upper()"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'POSTCODE': {'Processing': ["address_error = checkAddressForError({var})\nif 'Aust Postcode Error' in address_error.keys():\n    data[ci] = 'Error'\n    error['OR']= 'Error in Address'\n    error['send_to_CD'] = False\n    error['address_error'] = address_error\n    error['Postcode data received'] ={var}['address']['postcode']\nelse:\n     data[ci]={var}['address']['postcode']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'COUNTRY': {'Processing': ["if {var}['address']['country'] in cc_codes_pd['Alpha-2 code'].to_list() :\n     data[ci]=cc_codes_pd.index[cc_codes_pd['Alpha-2 code'] == {var}['address']['country']].to_list()[0]\nelse:\n     data[ci]= {var}['address']['country']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'ORDER_TYPE': {'Processing': ["data[ci]={var}['channel']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CARRIER_CODE': {'Processing': ["method = {var}['shipping_method']\nif 'DHL' in method:\n     data[ci]='EM001'\nelif 'Standard' in method:\n     if 'signature' in {var}['customer_note'].lower():\n          data[ci]='CD004'\n     else:\n          data[ci]='CD003'\nelif 'Express' in method:\n     data[ci] = 'CD020'\nelif len(method) == 0:\n     data[ci] = 'CD001'\nelse:\n     data[ci] = 'Error'\n     error['OR']= 'Error in Carrier Coding'\n     error['send_to_CD'] = False\n"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'PHONE_NO': {'Processing': ["data[ci]={var}['contact_phone']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'EMAIL_ADDRESS': {'Processing': ["data[ci]={var}['contact_email']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}}}, 'OR2': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'CUST_ORDER_NUMBER', 'PRODUCT', 'QUANTITY_ORDERED', 'LINE_NUMBER', 'BATCH NUMBER', 'STOCK STATUS'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[PRODUCT]}|{data[QUANTITY_ORDERED]}|{data[LINE_NUMBER]}|{data[BATCH NUMBER]}|{data[STOCK STATUS]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci]="OR2"\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'ACTION_INDICATOR': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci]="A"\nelse:\n     data[ci] = None\n     blank_line[0] = True\n\n\n'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'CUST_ORDER_NUMBER': {'Processing': ["if getQtyOrdered({var},{index1},{index2}):\n     data[ci]={var}['id']\nelse:\n     data[ci] = None\n     blank_line[0] = True\n"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'PRODUCT': {'Processing': ["if getQtyOrdered({var},{index1},{index2}):\n     data[ci]={var}['line_items'][{index1}]['line_quantities'][{index2}]['upc_number']\n     if (not data[ci]) or (not isinstance(data[ci],str)):\n          error['OR_product'] = 'No upc number'\n          error['send_to_CD'] = False\nelse:\n     data[ci] = None\n     blank_line[0] = True"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'QUANTITY_ORDERED': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci] = getQtyOrdered({var},{index1},{index2})\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'LINE_NUMBER': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n    data[ci]={line_count}\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'BATCH NUMBER': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n   data[ci]=""\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'STOCK STATUS': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n   data[ci]=""\nelse:\n     data[ci] = None\n     blank_line[0] = True\n'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}}}, 'OR4': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'CUST_ORDER_NUMBER', 'LINE_NUMBER', 'ORDER_NOTE'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[LINE_NUMBER]}|{data[ORDER_NOTE]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="OR4"'], 'Loops': [1.0], 'Loop_Len1': ["loops_dict[1]=getNotesLength([{var}['customer_note'],{var}['shipping_instructions']])"], 'Loop_Len2': [nan]}, 'ACTION_INDICATOR': {'Processing': ['data[ci]="A"'], 'Loops': [1.0], 'Loop_Len1': ["loops_dict[1]=getNotesLength([{var}['customer_note'],{var}['shipping_instructions']])"], 'Loop_Len2': [nan]}, 'CUST_ORDER_NUMBER': {'Processing': ["data[ci]={var}['id']"], 'Loops': [1.0], 'Loop_Len1': ["loops_dict[1]=getNotesLength([{var}['customer_note'],{var}['shipping_instructions']])"], 'Loop_Len2': [nan]}, 'LINE_NUMBER': {'Processing': ['data[ci]={line_count}'], 'Loops': [1.0], 'Loop_Len1': ["loops_dict[1]=getNotesLength([{var}['customer_note'],{var}['shipping_instructions']])"], 'Loop_Len2': [nan]}, 'ORDER_NOTE': {'Processing': ["if {line_count} == 1 : \n     note = {var}['customer_note']\n     if bool(note):\n          if 'do not fulfill' in {var}['customer_note'].lower():\n               error['DNF'] = 'Do Not Fulfill in Shipping Instructions'  #changed from error['OR'] in Aug 2025 so that can exclude from emails to customer reps\n               error['send_to_CD'] = False\n               data[ci] = 'Customer Note: ' + note\n     else:\n          if 'do not fulfill' in {var}['shipping_instructions'].lower():\n               error['DNF'] = 'Do Not Fulfill in Shipping Instructions' #changed from error['OR'] in Aug 2025 so that can exclude from emails to customer reps\n               error['send_to_CD'] = False\n          data[ci] = 'Shipping Instructions: ' + {var}['shipping_instructions']\nelif {line_count} == 2:\n     note = {var}['shipping_instructions']\n     if bool(note):\n          if 'do not fulfill' in {var}['shipping_instructions'].lower():\n               error['DNF'] = 'Do Not Fulfill in Shipping Instructions' #changed from error['OR'] in Aug 2025 so that can exclude from emails to customer reps\n               error['send_to_CD'] = False\n          data[ci] =  'Shipping Instructions: ' + note\n     else:\n          data[ci] = 'Shipping Instructions: N/A'"], 'Loops': [1.0], 'Loop_Len1': ["getNotesLength([{var}['customer_note'],{var}['shipping_instructions']])"], 'Loop_Len2': [nan]}}}}, 'PC': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {}}, 'OS1': {'Col List': ['RECORD_INDICATOR', 'CUST_ORDER_NUMBER', 'IFAC_CUSTOMER_NO', 'ETD', 'ORDER_DATE', 'SHIP_TO_NAME', 'SHIP_TO_ADDRESS_1_1', 'SHIP_TO_ADDRESS_1_2', 'AREA', 'STATE', 'POSTCODE', 'DELIVERY_DESC1', 'VENDOR_ORD_NO', 'SERVICE_LEVEL', 'ASN', 'INVOICE_NUMBER', 'TOTAL ITEMS', 'FREIGHT_CHARGE', 'CONSIGNMENT_NUMBER'], 'template': '{data[RECORD_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[IFAC_CUSTOMER_NO]}|{data[ETD]}|{data[ORDER_DATE]}|{data[SHIP_TO_NAME]}|{data[SHIP_TO_ADDRESS_1_1]}|{data[SHIP_TO_ADDRESS_1_2]}|{data[AREA]}|{data[STATE]}|{data[POSTCODE]}|{data[DELIVERY_DESC1]}|{data[VENDOR_ORD_NO]}|{data[SERVICE_LEVEL]}|{data[ASN]}|{data[INVOICE_NUMBER]}|{data[TOTAL ITEMS]}|{data[FREIGHT_CHARGE]}|{data[CONSIGNMENT_NUMBER]}', 'mapping': {}}, 'OS2': {'Col List': ['RECORD_INDICATOR', 'PRODUCT', 'QUANTITY_ORDERED', 'QUANTITY_SHIPPED', 'VARIANCE', 'PACK_ID', 'LINE_NUMBER'], 'template': '{data[RECORD_INDICATOR]}|{data[PRODUCT]}|{data[QUANTITY_ORDERED]}|{data[QUANTITY_SHIPPED]}|{data[VARIANCE]}|{data[PACK_ID]}|{data[LINE_NUMBER]}', 'mapping': {}}}, 'SA': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {}}, 'SA': {'Col List': ['CONST', 'DATE_RECEIVED', 'PRODUCT', 'QUANTITY', 'REASON_CODE', 'SA_COMMENT', 'CONSIGNMENT NO.', 'TRANSACTION_TYPE', 'ORDER_NO', 'STOCK_STATUS'], 'template': '{data[CONST]}|{data[DATE_RECEIVED]}|{data[PRODUCT]}|{data[QUANTITY]}|{data[REASON_CODE]}|{data[SA_COMMENT]}|{data[CONSIGNMENT NO.]}|{data[TRANSACTION_TYPE]}|{data[ORDER_NO]}|{data[STOCK_STATUS]}', 'mapping': {}}}, 'PT': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="HD"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CLIENT': {'Processing': ['data[ci]="EM"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'STREAM_ID': {'Processing': ['data[ci]="PT"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}}}, 'PT1': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'CUST_ORDER_NUMBER', 'CONTAINER_NUMBER', 'ARRIVAL_DATE', 'CONTAINER_TYPE', 'TOTAL_CARTONS'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[CONTAINER_NUMBER]}|{data[ARRIVAL_DATE]}|{data[CONTAINER_TYPE]}|{data[TOTAL_CARTONS]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['data[ci]="PT1"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'ACTION_INDICATOR': {'Processing': ['data[ci]="A"'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CUST_ORDER_NUMBER': {'Processing': ["data[ci]=str({var}['production_order_number']).zfill(4)+{var}['delivery_name']"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CONTAINER_NUMBER': {'Processing': ['data[ci]=""'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'ARRIVAL_DATE': {'Processing': ["if {var}['in_warehouse_date']:\n     data[ci]={var}['in_warehouse_date'][0:10].replace('-','')\nelse:\n     data[ci] = ''\n"], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'CONTAINER_TYPE': {'Processing': ['data[ci]=""'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}, 'TOTAL_CARTONS': {'Processing': ['data[ci]=""'], 'Loops': [0.0], 'Loop_Len1': [nan], 'Loop_Len2': [nan]}}}, 'PT2': {'Col List': ['RECORD_INDICATOR', 'ACTION_INDICATOR', 'CUST_ORDER_NUMBER', 'PRODUCT', 'QUANTITY_ORDERED', 'LINE_NUMBER', 'BATCH NUMBER', 'CARTON PACK_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[ACTION_INDICATOR]}|{data[CUST_ORDER_NUMBER]}|{data[PRODUCT]}|{data[QUANTITY_ORDERED]}|{data[LINE_NUMBER]}|{data[BATCH NUMBER]}|{data[CARTON PACK_ID]}', 'mapping': {'RECORD_INDICATOR': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci]="PT2"\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'ACTION_INDICATOR': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci]="A"\nelse:\n     data[ci] = None\n     blank_line[0] = True\n\n\n'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'CUST_ORDER_NUMBER': {'Processing': ["if getQtyOrdered({var},{index1},{index2}):\n     data[ci]=str({var}['production_order_number']).zfill(4)+{var}['delivery_name']\nelse:\n     data[ci] = None\n     blank_line[0] = True\n"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'PRODUCT': {'Processing': ["if getQtyOrdered({var},{index1},{index2}):\n     data[ci]={var}['line_items'][{index1}]['line_quantities'][{index2}]['upc_number']\n     if (not data[ci]) or (not isinstance(data[ci],str)):\n          error['PT_product'] = 'No upc number'\n          error['send_to_CD'] = False\nelse:\n     data[ci] = None\n     blank_line[0] = True"], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'QUANTITY_ORDERED': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n     data[ci] = getQtyOrdered({var},{index1},{index2})\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'LINE_NUMBER': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n    data[ci]={line_count}\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'BATCH NUMBER': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n   data[ci]=""\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}, 'CARTON PACK_ID': {'Processing': ['if getQtyOrdered({var},{index1},{index2}):\n   data[ci]=""\nelse:\n     data[ci] = None\n     blank_line[0] = True'], 'Loops': [2.0], 'Loop_Len1': ["loops_dict[1] = len({var}['line_items'])"], 'Loop_Len2': ["loops_dict[2] = len({var}['line_items'][{index1}]['line_quantities'])"]}}}}, 'TP': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {}}, 'TP': {'Col List': ['RECORD_INDICATOR', 'PURCHASE_ORD_NUMBER', 'LINE_NUMBER', 'PRODUCT', 'TOTAL_QUANTITY_REC'], 'template': '{data[RECORD_INDICATOR]}|{data[PURCHASE_ORD_NUMBER]}|{data[LINE_NUMBER]}|{data[PRODUCT]}|{data[TOTAL_QUANTITY_REC]}', 'mapping': {}}}, 'MO': {'HD': {'Col List': ['RECORD_INDICATOR', 'CLIENT', 'STREAM_ID'], 'template': '{data[RECORD_INDICATOR]}|{data[CLIENT]}|{data[STREAM_ID]}', 'mapping': {}}, 'MO': {'Col List': ['CONST', 'ORDER_NO', 'ACKNOWLEDGEMENT_FLAG'], 'template': '{data[CONST]}|{data[ORDER_NO]}|{data[ACKNOWLEDGEMENT_FLAG]}', 'mapping': {}}}}
