bots-edi / bots

Bots EDI Translator
GNU General Public License v3.0
136 stars 84 forks source link

Using queries in filename definition #40

Closed suederade closed 7 years ago

suederade commented 7 years ago

The docs say that you can do things like this in your filenames: {frompartner}_{messagetype}_{datetime:%Y%m%d}.{editype}

I would like to get the EDI doctype (850, 860, etc) from the file and add it to the filename.

I've added a query to my envelope structure:

structure = [
    {ID:'ISA',MIN:0,MAX:99999,    
        QUERIES:{
            'frompartner':  {'BOTSID':'ISA','ISA06':None},
            'topartner':    {'BOTSID':'ISA','ISA08':None},
            'testindicator':{'BOTSID':'ISA','ISA15':None},
            },
        LEVEL:
            [
            {ID:'TA1',MIN:0,MAX:99999},
            {ID:'GS',MIN:0,MAX:99999,
                QUERIES:{
                    'version':   {'BOTSID':'GS','GS08':None},
                    },
                LEVEL:
                    [
                    {ID:'ST',MIN:0,MAX:99999,
                        QUERIES:{
                            'reference': {'BOTSID':'ST','ST02':None},
# HERE ->                   'docnum': {'BOTSID':'ST','ST01':None},
                            },
                        SUBTRANSLATION:[
                            {'BOTSID':'ST','ST01':None},
                            ]},
                    {ID:'GE',MIN:1,MAX:1},
                    ]
                },
            {ID:'IEA',MIN:1,MAX:1}
            ]
        }
    ]

The problem is that I am getting this error:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/bots/preprocess.py", line 165, in getedi
    outgoing = Document(int(childrow['idta']), ta_from, os.path.basename(full_path), full_path.split('/')[-2], childrow[str('contenttype')])
IndexError: list index out of range

I am clearly adding this wrong to be able to get it into my filename. Is there a correct way of doing this?

djfurman commented 7 years ago

@stevenmwade make sure that you add a file extension as well. I'm looking into some other behavior that seems odd in the communication.py module from the abstract class that seems to control this.

Working with enveloping inside a mapping script can be strange too, you may want to consider attempting this inside a partner or route script.

Does the line above the trace here give which list the index binding is choking on?

suederade commented 7 years ago

@djfurman We actually ended up adding some extra stuff to the translation, saving to one of the rsrv columns, and then doing some things in an on_complete function.