@@ -319,113 +319,3 @@ def incluir_pagamento(self, **kwargs):
319319 lote_pag .adicionar_evento (evento )
320320 # Incrementar numero de registros no trailer do arquivo
321321 self .trailer .totais_quantidade_registros += len (evento )
322-
323-
324- class ArquivoCobranca400 (object ):
325-
326- def __init__ (self , banco , ** kwargs ):
327- """Arquivo Cnab400."""
328-
329- self ._lotes = []
330- self .banco = banco
331- arquivo = kwargs .get ('arquivo' )
332- if isinstance (arquivo , (IOBase , codecs .StreamReaderWriter )):
333- return self .carregar_retorno (arquivo )
334-
335- self .header = self .banco .registros .HeaderArquivo (** kwargs )
336- self .trailer = self .banco .registros .TrailerArquivo (** kwargs )
337-
338- if self .header .arquivo_data_de_geracao is None :
339- now = datetime .now ()
340- self .header .arquivo_data_de_geracao = int (now .strftime ("%d%m%Y" ))
341-
342- def carregar_retorno (self , arquivo ):
343-
344- lote_aberto = None
345- evento_aberto = None
346-
347- for linha in arquivo :
348- tipo_registro = linha [0 ]
349-
350- if tipo_registro == '0' :
351- self .header = self .banco .registros .HeaderArquivo ()
352- self .header .carregar (linha )
353- lote_aberto = Lote (self .banco )
354- self ._lotes .append (lote_aberto )
355-
356- elif tipo_registro == '1' :
357- tipo_segmento = linha [0 ]
358- # codigo_evento = linha[15:17]
359-
360- if tipo_segmento == '1' :
361- trans_tipo1 = self .banco .registros .TransacaoTipo1 ()
362- trans_tipo1 .carregar (linha )
363-
364- evento_aberto = Evento (self .banco , 1 )
365- lote_aberto ._eventos .append (evento_aberto )
366- evento_aberto ._segmentos .append (trans_tipo1 )
367-
368- evento_aberto = None
369-
370- elif tipo_registro == '9' :
371- self .trailer = self .banco .registros .TrailerArquivo ()
372- self .trailer .carregar (linha )
373-
374- @property
375- def lotes (self ):
376- return self ._lotes
377-
378- def incluir_cobranca (self , ** kwargs ):
379- # 1 eh o codigo de cobranca
380- codigo_evento = 1
381- evento = Evento (self .banco , codigo_evento )
382-
383- trans_tp1 = self .banco .registros .TransacaoTipo1 (** kwargs )
384- evento .adicionar_segmento (trans_tp1 )
385-
386- lote_cobranca = self .encontrar_lote (codigo_evento )
387-
388- if lote_cobranca is None :
389- header = None
390- trailer = None
391- lote_cobranca = Lote (self .banco , header , trailer )
392- self .adicionar_lote (lote_cobranca )
393-
394- lote_cobranca .adicionar_evento (evento )
395-
396- def encontrar_lote (self , codigo_servico ):
397- for lote in self .lotes :
398- # if lote.header.codigo_servico == codigo_servico:
399- # return lote
400- return lote
401-
402- def adicionar_lote (self , lote ):
403- if not isinstance (lote , Lote ):
404- raise TypeError ('Objeto deve ser instancia de "Lote"' )
405-
406- self ._lotes .append (lote )
407- lote .codigo = len (self ._lotes )
408-
409- if self .trailer != None :
410- if hasattr (self .trailer , 'totais_quantidade_lotes' ):
411- # Incrementar numero de lotes no trailer do arquivo
412- self .trailer .totais_quantidade_lotes += 1
413-
414- if hasattr (self .trailer , 'totais_quantidade_registros' ):
415- # Incrementar numero de registros no trailer do arquivo
416- self .trailer .totais_quantidade_registros += len (lote )
417-
418- def escrever (self , file_ ):
419- file_ .write (str (self ).encode ('ascii' ))
420-
421- def __str__ (self ):
422- if not self ._lotes :
423- raise errors .ArquivoVazioError ()
424-
425- result = []
426- result .append (str (self .header ))
427- result .extend (str (lote ) for lote in self ._lotes )
428- result .append (str (self .trailer ))
429- # Adicionar elemento vazio para arquivo terminar com \r\n
430- result .append ('' )
431- return '\r \n ' .join (result )
0 commit comments