def run(self): if not self.ta_info["topartner"] or not self.ta_info["frompartner"]: raise botslib.OutMessageError( _(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'), ta_info=self.ta_info ) self._openoutenvelope(self.ta_info["editype"], self.ta_info["envelope"]) self.ta_info.update(self.out.ta_info) # need to know the functionalgroup code: defmessage = grammar.grammarread(self.ta_info["editype"], self.ta_info["messagetype"]) self.ta_info["functionalgroup"] = defmessage.syntax["functionalgroup"] botslib.tryrunscript(self.userscript, self.scriptname, "ta_infocontent", ta_info=self.ta_info) # prepare data for envelope isa09date = time.strftime("%y%m%d") # test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator']) # mapping overrules. if self.ta_info["testindicator"] and self.ta_info["testindicator"] != "0": #'0' is default value (in db) testindicator = self.ta_info["testindicator"] else: testindicator = self.ta_info["ISA15"] # ~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator if botsglobal.ini.getboolean("settings", "interchangecontrolperpartner", False): self.ta_info["reference"] = str(botslib.unique("isacounter_" + self.ta_info["topartner"])) else: self.ta_info["reference"] = str(botslib.unique("isacounter_" + self.ta_info["frompartner"])) # ISA06 and GS02 can be different; eg ISA06 is a service provider. # ISA06 and GS02 can be in the syntax.... isa06sender = self.ta_info.get("ISA06", self.ta_info["frompartner"]) isa06sender = isa06sender.ljust(15) # add spaces; is fixed length gs02sender = self.ta_info.get("GS02", self.ta_info["frompartner"]) # also for ISA08 and GS03 isa08receiver = self.ta_info.get("ISA08", self.ta_info["topartner"]) isa08receiver = isa08receiver.ljust(15) # add spaces; is fixed length gs03receiver = self.ta_info.get("GS03", self.ta_info["topartner"]) # build the envelope segments (that is, the tree from which the segments will be generated) self.out.put( { "BOTSID": "ISA", "ISA01": self.ta_info["ISA01"], "ISA02": self.ta_info["ISA02"], "ISA03": self.ta_info["ISA03"], "ISA04": self.ta_info["ISA04"], "ISA05": self.ta_info["ISA05"], "ISA06": isa06sender, "ISA07": self.ta_info["ISA07"], "ISA08": isa08receiver, "ISA09": isa09date, "ISA10": time.strftime("%H%M"), "ISA11": self.ta_info["ISA11"], # if ISA version > 00403, replaced by reprtion separator "ISA12": self.ta_info["version"], "ISA13": self.ta_info["reference"], "ISA14": self.ta_info["ISA14"], "ISA15": testindicator, }, strip=False, ) # MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length self.out.put({"BOTSID": "ISA"}, {"BOTSID": "IEA", "IEA01": "1", "IEA02": self.ta_info["reference"]}) gs08messagetype = self.ta_info["messagetype"][3:] if gs08messagetype[:6] < "004010": gs04date = time.strftime("%y%m%d") else: gs04date = time.strftime("%Y%m%d") self.out.put( {"BOTSID": "ISA"}, { "BOTSID": "GS", "GS01": self.ta_info["functionalgroup"], "GS02": gs02sender, "GS03": gs03receiver, "GS04": gs04date, "GS05": time.strftime("%H%M"), "GS06": self.ta_info["reference"], "GS07": self.ta_info["GS07"], "GS08": gs08messagetype, }, ) self.out.put( {"BOTSID": "ISA"}, {"BOTSID": "GS"}, {"BOTSID": "GE", "GE01": self.ta_info["nrmessages"], "GE02": self.ta_info["reference"]}, ) # dummy segment; is not used # user exit botslib.tryrunscript(self.userscript, self.scriptname, "envelopecontent", ta_info=self.ta_info, out=self.out) # convert the tree into segments; here only the UNB is written (first segment) self.out.checkmessage(self.out.root, self.out.defmessage) self.out.tree2records(self.out.root) # start doing the actual writing: tofile = botslib.opendata(self.ta_info["filename"], "wb", self.ta_info["charset"]) isa_string = self.out.record2string(self.out.records[0]) if self.ta_info["version"] < "00403": isa_string = ( isa_string[:103] + self.ta_info["field_sep"] + self.ta_info["sfield_sep"] + isa_string[103:] ) # hack for strange characters at end of ISA; hardcoded else: isa_string = ( isa_string[:82] + self.ta_info["reserve"] + isa_string[83:103] + self.ta_info["field_sep"] + self.ta_info["sfield_sep"] + isa_string[103:] ) # hack for strange characters at end of ISA; hardcoded tofile.write(isa_string) # write ISA tofile.write(self.out.record2string(self.out.records[1])) # write GS self.writefilelist(tofile) tofile.write(self.out.record2string(self.out.records[-2])) # write GE tofile.write(self.out.record2string(self.out.records[-1])) # write IEA tofile.close() if self.ta_info["functionalgroup"] != "FA" and botslib.checkconfirmrules( "ask-x12-997", idroute=self.ta_info["idroute"], idchannel=self.ta_info["tochannel"], topartner=self.ta_info["topartner"], frompartner=self.ta_info["frompartner"], editype=self.ta_info["editype"], messagetype=self.ta_info["messagetype"], ): self.ta_info["confirmtype"] = u"ask-x12-997" self.ta_info["confirmasked"] = True
def run(self): if not self.ta_info["topartner"] or not self.ta_info["frompartner"]: raise botslib.OutMessageError( _(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'), ta_info=self.ta_info ) self._openoutenvelope(self.ta_info["editype"], self.ta_info["envelope"]) self.ta_info.update(self.out.ta_info) botslib.tryrunscript(self.userscript, self.scriptname, "ta_infocontent", ta_info=self.ta_info) # version dependent enveloping write_una = False if self.ta_info["version"] < "4": date = time.strftime("%y%m%d") reserve = " " if self.ta_info["charset"] != "UNOA": write_una = True else: date = time.strftime("%Y%m%d") reserve = self.ta_info["reserve"] if self.ta_info["charset"] not in ["UNOA", "UNOB"]: write_una = True # UNB counter is per sender or receiver if botsglobal.ini.getboolean("settings", "interchangecontrolperpartner", False): self.ta_info["reference"] = str(botslib.unique("unbcounter_" + self.ta_info["topartner"])) else: self.ta_info["reference"] = str(botslib.unique("unbcounter_" + self.ta_info["frompartner"])) # testindicator is more complex: if ( self.ta_info["testindicator"] and self.ta_info["testindicator"] != "0" ): # first check value from ta; do not use default testindicator = "1" elif self.ta_info["UNB.0035"] != "0": # than check values from grammar testindicator = "1" else: testindicator = "" # build the envelope segments (that is, the tree from which the segments will be generated) self.out.put( { "BOTSID": "UNB", "S001.0001": self.ta_info["charset"], "S001.0002": self.ta_info["version"], "S002.0004": self.ta_info["frompartner"], "S003.0010": self.ta_info["topartner"], "S004.0017": date, "S004.0019": time.strftime("%H%M"), "0020": self.ta_info["reference"], } ) # the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account) for field in ( "S001.0080", "S001.0133", "S002.0007", "S002.0008", "S002.0042", "S003.0007", "S003.0014", "S003.0046", "S005.0022", "S005.0025", "0026", "0029", "0031", "0032", ): if self.ta_info["UNB." + field]: self.out.put({"BOTSID": "UNB", field: self.ta_info["UNB." + field]}) if testindicator: self.out.put({"BOTSID": "UNB", "0035": testindicator}) self.out.put( {"BOTSID": "UNB"}, {"BOTSID": "UNZ", "0036": self.ta_info["nrmessages"], "0020": self.ta_info["reference"]} ) # dummy segment; is not used # user exit botslib.tryrunscript(self.userscript, self.scriptname, "envelopecontent", ta_info=self.ta_info, out=self.out) # convert the tree into segments; here only the UNB is written (first segment) self.out.checkmessage(self.out.root, self.out.defmessage) self.out.tree2records(self.out.root) # start doing the actual writing: tofile = botslib.opendata(self.ta_info["filename"], "wb", self.ta_info["charset"]) if write_una or self.ta_info["forceUNA"]: tofile.write( "UNA" + self.ta_info["sfield_sep"] + self.ta_info["field_sep"] + self.ta_info["decimaal"] + self.ta_info["escape"] + reserve + self.ta_info["record_sep"] + self.ta_info["add_crlfafterrecord_sep"] ) tofile.write(self.out.record2string(self.out.records[0])) self.writefilelist(tofile) tofile.write(self.out.record2string(self.out.records[-1])) tofile.close() if self.ta_info["messagetype"][:6] != "CONTRL" and botslib.checkconfirmrules( "ask-edifact-CONTRL", idroute=self.ta_info["idroute"], idchannel=self.ta_info["tochannel"], topartner=self.ta_info["topartner"], frompartner=self.ta_info["frompartner"], editype=self.ta_info["editype"], messagetype=self.ta_info["messagetype"], ): self.ta_info["confirmtype"] = u"ask-edifact-CONTRL" self.ta_info["confirmasked"] = True
def run(self): self._openoutenvelope(self.ta_info['editype'],self.ta_info['envelope']) self.ta_info.update(self.out.ta_info) #need to know the functionalgroup code: defmessage = grammar.grammarread(self.ta_info['editype'],self.ta_info['messagetype']) self.ta_info['functionalgroup'] = defmessage.syntax['functionalgroup'] botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info) #prepare data for envelope ISA09date = time.strftime('%y%m%d') #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator']) #mapping overrules. if self.ta_info['testindicator'] and self.ta_info['testindicator']!='0': #'0' is default value (in db) testindicator = self.ta_info['testindicator'] else: testindicator = self.ta_info['ISA15'] #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False): self.ta_info['reference'] = str(botslib.unique('isacounter_' + self.ta_info['topartner'])) else: self.ta_info['reference'] = str(botslib.unique('isacounter_' + self.ta_info['frompartner'])) #ISA06 and GS02 can be different; eg ISA06 is a service provider. #ISA06 and GS02 can be in the syntax.... ISA06 = self.ta_info.get('ISA06',self.ta_info['frompartner']) GS02 = self.ta_info.get('GS02',self.ta_info['frompartner']) #also for ISA08 and GS03 ISA08 = self.ta_info.get('ISA08',self.ta_info['topartner']) GS03 = self.ta_info.get('GS03',self.ta_info['topartner']) #build the envelope segments (that is, the tree from which the segments will be generated) self.out.put({'BOTSID':'ISA', 'ISA01':self.ta_info['ISA01'], 'ISA02':self.ta_info['ISA02'], 'ISA03':self.ta_info['ISA03'], 'ISA04':self.ta_info['ISA04'], 'ISA05':self.ta_info['ISA05'], 'ISA06':ISA06, 'ISA07':self.ta_info['ISA07'], 'ISA08':ISA08, 'ISA09':ISA09date, 'ISA10':time.strftime('%H%M'), 'ISA11':self.ta_info['ISA11'], #if ISA version > 00403, replaced by reprtion separator 'ISA12':self.ta_info['version'], 'ISA13':self.ta_info['reference'], 'ISA14':self.ta_info['ISA14'], 'ISA15':testindicator}) self.out.put({'BOTSID':'ISA'},{'BOTSID':'IEA','IEA01':'1','IEA02':self.ta_info['reference']}) GS08 = self.ta_info['messagetype'][3:] if GS08[:6]<'004010': GS04date = time.strftime('%y%m%d') else: GS04date = time.strftime('%Y%m%d') self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS', 'GS01':self.ta_info['functionalgroup'], 'GS02':GS02, 'GS03':GS03, 'GS04':GS04date, 'GS05':time.strftime('%H%M'), 'GS06':self.ta_info['reference'], 'GS07':self.ta_info['GS07'], 'GS08':GS08}) self.out.put({'BOTSID':'ISA'},{'BOTSID':'GS'},{'BOTSID':'GE','GE01':self.ta_info['nrmessages'],'GE02':self.ta_info['reference']}) #dummy segment; is not used #user exit botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out) #convert the tree into segments; here only the UNB is written (first segment) self.out.normalisetree(self.out.root) self.out.tree2records(self.out.root) #start doing the actual writing: tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset']) ISAstring = self.out._record2string(self.out.records[0]) if self.ta_info['version']<'00403': ISAstring = ISAstring[:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + ISAstring[103:] #hack for strange characters at end of ISA; hardcoded else: ISAstring = ISAstring[:82] +self.ta_info['reserve'] + ISAstring[83:103] + self.ta_info['field_sep']+ self.ta_info['sfield_sep'] + ISAstring[103:] #hack for strange characters at end of ISA; hardcoded tofile.write(ISAstring) #write ISA tofile.write(self.out._record2string(self.out.records[1])) #write GS self.writefilelist(tofile) tofile.write(self.out._record2string(self.out.records[-2])) #write GE tofile.write(self.out._record2string(self.out.records[-1])) #write IEA tofile.close() if self.ta_info['functionalgroup']!='FA' and botslib.checkconfirmrules('ask-x12-997',idroute=self.ta_info['idroute'],idchannel=self.ta_info['tochannel'], topartner=self.ta_info['topartner'],frompartner=self.ta_info['frompartner'], editype=self.ta_info['editype'],messagetype=self.ta_info['messagetype']): self.ta_info['confirmtype'] = u'ask-x12-997' self.ta_info['confirmasked'] = True
def run(self): if not self.ta_info['topartner'] or not self.ta_info['frompartner']: raise botslib.OutMessageError(_( u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".' ), ta_info=self.ta_info) self._openoutenvelope(self.ta_info['editype'], self.ta_info['envelope']) self.ta_info.update(self.out.ta_info) #need to know the functionalgroup code: defmessage = grammar.grammarread(self.ta_info['editype'], self.ta_info['messagetype']) self.ta_info['functionalgroup'] = defmessage.syntax['functionalgroup'] botslib.tryrunscript(self.userscript, self.scriptname, 'ta_infocontent', ta_info=self.ta_info) #prepare data for envelope isa09date = time.strftime('%y%m%d') #test indicator can either be from configuration (self.ta_info['ISA15']) or by mapping (self.ta_info['testindicator']) #mapping overrules. if self.ta_info['testindicator'] and self.ta_info[ 'testindicator'] != '0': #'0' is default value (in db) testindicator = self.ta_info['testindicator'] else: testindicator = self.ta_info['ISA15'] #~ print self.ta_info['messagetype'], 'grammar:',self.ta_info['ISA15'],'ta:',self.ta_info['testindicator'],'out:',testindicator if botsglobal.ini.getboolean('settings', 'interchangecontrolperpartner', False): self.ta_info['reference'] = str( botslib.unique('isacounter_' + self.ta_info['topartner'])) else: self.ta_info['reference'] = str( botslib.unique('isacounter_' + self.ta_info['frompartner'])) #ISA06 and GS02 can be different; eg ISA06 is a service provider. #ISA06 and GS02 can be in the syntax.... isa06sender = self.ta_info.get('ISA06', self.ta_info['frompartner']) isa06sender = isa06sender.ljust(15) #add spaces; is fixed length gs02sender = self.ta_info.get('GS02', self.ta_info['frompartner']) #also for ISA08 and GS03 isa08receiver = self.ta_info.get('ISA08', self.ta_info['topartner']) isa08receiver = isa08receiver.ljust(15) #add spaces; is fixed length gs03receiver = self.ta_info.get('GS03', self.ta_info['topartner']) #build the envelope segments (that is, the tree from which the segments will be generated) self.out.put( { 'BOTSID': 'ISA', 'ISA01': self.ta_info['ISA01'], 'ISA02': self.ta_info['ISA02'], 'ISA03': self.ta_info['ISA03'], 'ISA04': self.ta_info['ISA04'], 'ISA05': self.ta_info['ISA05'], 'ISA06': isa06sender, 'ISA07': self.ta_info['ISA07'], 'ISA08': isa08receiver, 'ISA09': isa09date, 'ISA10': time.strftime('%H%M'), 'ISA11': self.ta_info[ 'ISA11'], #if ISA version > 00403, replaced by reprtion separator 'ISA12': self.ta_info['version'], 'ISA13': self.ta_info['reference'], 'ISA14': self.ta_info['ISA14'], 'ISA15': testindicator }, strip=False ) #MIND: strip=False: ISA fields shoudl not be stripped as it is soemwhat like fixed-length self.out.put({'BOTSID': 'ISA'}, { 'BOTSID': 'IEA', 'IEA01': '1', 'IEA02': self.ta_info['reference'] }) gs08messagetype = self.ta_info['messagetype'][3:] if gs08messagetype[:6] < '004010': gs04date = time.strftime('%y%m%d') else: gs04date = time.strftime('%Y%m%d') self.out.put({'BOTSID': 'ISA'}, { 'BOTSID': 'GS', 'GS01': self.ta_info['functionalgroup'], 'GS02': gs02sender, 'GS03': gs03receiver, 'GS04': gs04date, 'GS05': time.strftime('%H%M'), 'GS06': self.ta_info['reference'], 'GS07': self.ta_info['GS07'], 'GS08': gs08messagetype }) self.out.put({'BOTSID': 'ISA'}, {'BOTSID': 'GS'}, { 'BOTSID': 'GE', 'GE01': self.ta_info['nrmessages'], 'GE02': self.ta_info['reference'] }) #dummy segment; is not used #user exit botslib.tryrunscript(self.userscript, self.scriptname, 'envelopecontent', ta_info=self.ta_info, out=self.out) #convert the tree into segments; here only the UNB is written (first segment) self.out.checkmessage(self.out.root, self.out.defmessage) self.out.tree2records(self.out.root) #start doing the actual writing: tofile = botslib.opendata(self.ta_info['filename'], 'wb', self.ta_info['charset']) isa_string = self.out.record2string(self.out.records[0]) if self.ta_info['version'] < '00403': isa_string = isa_string[:103] + self.ta_info[ 'field_sep'] + self.ta_info['sfield_sep'] + isa_string[ 103:] #hack for strange characters at end of ISA; hardcoded else: isa_string = isa_string[:82] + self.ta_info[ 'reserve'] + isa_string[83:103] + self.ta_info[ 'field_sep'] + self.ta_info['sfield_sep'] + isa_string[ 103:] #hack for strange characters at end of ISA; hardcoded tofile.write(isa_string) #write ISA tofile.write(self.out.record2string(self.out.records[1])) #write GS self.writefilelist(tofile) tofile.write(self.out.record2string(self.out.records[-2])) #write GE tofile.write(self.out.record2string(self.out.records[-1])) #write IEA tofile.close() if self.ta_info[ 'functionalgroup'] != 'FA' and botslib.checkconfirmrules( 'ask-x12-997', idroute=self.ta_info['idroute'], idchannel=self.ta_info['tochannel'], topartner=self.ta_info['topartner'], frompartner=self.ta_info['frompartner'], editype=self.ta_info['editype'], messagetype=self.ta_info['messagetype']): self.ta_info['confirmtype'] = u'ask-x12-997' self.ta_info['confirmasked'] = True
def run(self): if not self.ta_info['topartner'] or not self.ta_info['frompartner']: raise botslib.OutMessageError(_( u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".' ), ta_info=self.ta_info) self._openoutenvelope(self.ta_info['editype'], self.ta_info['envelope']) self.ta_info.update(self.out.ta_info) botslib.tryrunscript(self.userscript, self.scriptname, 'ta_infocontent', ta_info=self.ta_info) #version dependent enveloping write_una = False if self.ta_info['version'] < '4': date = time.strftime('%y%m%d') reserve = ' ' if self.ta_info['charset'] != 'UNOA': write_una = True else: date = time.strftime('%Y%m%d') reserve = self.ta_info['reserve'] if self.ta_info['charset'] not in ['UNOA', 'UNOB']: write_una = True #UNB counter is per sender or receiver if botsglobal.ini.getboolean('settings', 'interchangecontrolperpartner', False): self.ta_info['reference'] = str( botslib.unique('unbcounter_' + self.ta_info['topartner'])) else: self.ta_info['reference'] = str( botslib.unique('unbcounter_' + self.ta_info['frompartner'])) #testindicator is more complex: if self.ta_info['testindicator'] and self.ta_info[ 'testindicator'] != '0': #first check value from ta; do not use default testindicator = '1' elif self.ta_info['UNB.0035'] != '0': #than check values from grammar testindicator = '1' else: testindicator = '' #build the envelope segments (that is, the tree from which the segments will be generated) self.out.put({ 'BOTSID': 'UNB', 'S001.0001': self.ta_info['charset'], 'S001.0002': self.ta_info['version'], 'S002.0004': self.ta_info['frompartner'], 'S003.0010': self.ta_info['topartner'], 'S004.0017': date, 'S004.0019': time.strftime('%H%M'), '0020': self.ta_info['reference'] }) #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account) for field in ('S001.0080', 'S001.0133', 'S002.0007', 'S002.0008', 'S002.0042', 'S003.0007', 'S003.0014', 'S003.0046', 'S005.0022', 'S005.0025', '0026', '0029', '0031', '0032'): if self.ta_info['UNB.' + field]: self.out.put({ 'BOTSID': 'UNB', field: self.ta_info['UNB.' + field] }) if testindicator: self.out.put({'BOTSID': 'UNB', '0035': testindicator}) self.out.put({'BOTSID': 'UNB'}, { 'BOTSID': 'UNZ', '0036': self.ta_info['nrmessages'], '0020': self.ta_info['reference'] }) #dummy segment; is not used #user exit botslib.tryrunscript(self.userscript, self.scriptname, 'envelopecontent', ta_info=self.ta_info, out=self.out) #convert the tree into segments; here only the UNB is written (first segment) self.out.checkmessage(self.out.root, self.out.defmessage) self.out.tree2records(self.out.root) #start doing the actual writing: tofile = botslib.opendata(self.ta_info['filename'], 'wb', self.ta_info['charset']) if write_una or self.ta_info['forceUNA']: tofile.write('UNA' + self.ta_info['sfield_sep'] + self.ta_info['field_sep'] + self.ta_info['decimaal'] + self.ta_info['escape'] + reserve + self.ta_info['record_sep'] + self.ta_info['add_crlfafterrecord_sep']) tofile.write(self.out.record2string(self.out.records[0])) self.writefilelist(tofile) tofile.write(self.out.record2string(self.out.records[-1])) tofile.close() if self.ta_info[ 'messagetype'][:6] != 'CONTRL' and botslib.checkconfirmrules( 'ask-edifact-CONTRL', idroute=self.ta_info['idroute'], idchannel=self.ta_info['tochannel'], topartner=self.ta_info['topartner'], frompartner=self.ta_info['frompartner'], editype=self.ta_info['editype'], messagetype=self.ta_info['messagetype']): self.ta_info['confirmtype'] = u'ask-edifact-CONTRL' self.ta_info['confirmasked'] = True
def run(self): if not self.ta_info['topartner'] or not self.ta_info['frompartner']: raise botslib.OutMessageError(_(u'In enveloping "frompartner" or "topartner" unknown: "$ta_info".'),ta_info=self.ta_info) self._openoutenvelope(self.ta_info['editype'],self.ta_info['envelope']) self.ta_info.update(self.out.ta_info) botslib.tryrunscript(self.userscript,self.scriptname,'ta_infocontent',ta_info=self.ta_info) #version dependent enveloping writeUNA = False if self.ta_info['version']<'4': date = time.strftime('%y%m%d') reserve = ' ' if self.ta_info['charset'] != 'UNOA': writeUNA = True else: date = time.strftime('%Y%m%d') reserve = self.ta_info['reserve'] if self.ta_info['charset'] not in ['UNOA','UNOB']: writeUNA = True #UNB counter is per sender or receiver if botsglobal.ini.getboolean('settings','interchangecontrolperpartner',False): self.ta_info['reference'] = str(botslib.unique('unbcounter_' + self.ta_info['topartner'])) else: self.ta_info['reference'] = str(botslib.unique('unbcounter_' + self.ta_info['frompartner'])) #testindicator is more complex: if self.ta_info['testindicator'] and self.ta_info['testindicator']!='0': #first check value from ta; do not use default testindicator = '1' elif self.ta_info['UNB.0035'] != '0': #than check values from grammar testindicator = '1' else: testindicator = '' #build the envelope segments (that is, the tree from which the segments will be generated) self.out.put({'BOTSID':'UNB', 'S001.0001':self.ta_info['charset'], 'S001.0002':self.ta_info['version'], 'S002.0004':self.ta_info['frompartner'], 'S003.0010':self.ta_info['topartner'], 'S004.0017':date, 'S004.0019':time.strftime('%H%M'), '0020':self.ta_info['reference']}) #the following fields are conditional; do not write these when empty string (separator compression does take empty strings into account) if self.ta_info['UNB.S002.0007']: self.out.put({'BOTSID':'UNB','S002.0007': self.ta_info['UNB.S002.0007']}) if self.ta_info['UNB.S003.0007']: self.out.put({'BOTSID':'UNB','S003.0007': self.ta_info['UNB.S003.0007']}) if self.ta_info['UNB.0026']: self.out.put({'BOTSID':'UNB','0026': self.ta_info['UNB.0026']}) if testindicator: self.out.put({'BOTSID':'UNB','0035': testindicator}) self.out.put({'BOTSID':'UNB'},{'BOTSID':'UNZ','0036':self.ta_info['nrmessages'],'0020':self.ta_info['reference']}) #dummy segment; is not used #user exit botslib.tryrunscript(self.userscript,self.scriptname,'envelopecontent',ta_info=self.ta_info,out=self.out) #convert the tree into segments; here only the UNB is written (first segment) self.out.normalisetree(self.out.root) self.out.tree2records(self.out.root) #start doing the actual writing: tofile = botslib.opendata(self.ta_info['filename'],'wb',self.ta_info['charset']) if writeUNA or self.ta_info['forceUNA']: tofile.write('UNA'+self.ta_info['sfield_sep']+self.ta_info['field_sep']+self.ta_info['decimaal']+self.ta_info['escape']+ reserve +self.ta_info['record_sep']+self.ta_info['add_crlfafterrecord_sep']) tofile.write(self.out._record2string(self.out.records[0])) self.writefilelist(tofile) tofile.write(self.out._record2string(self.out.records[-1])) tofile.close() if self.ta_info['messagetype'][:6]!='CONTRL' and botslib.checkconfirmrules('ask-edifact-CONTRL',idroute=self.ta_info['idroute'],idchannel=self.ta_info['tochannel'], topartner=self.ta_info['topartner'],frompartner=self.ta_info['frompartner'], editype=self.ta_info['editype'],messagetype=self.ta_info['messagetype']): self.ta_info['confirmtype'] = u'ask-edifact-CONTRL' self.ta_info['confirmasked'] = True