Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipepaloschi committed Aug 7, 2018
1 parent 9ff2da5 commit 320014c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 50 deletions.
22 changes: 12 additions & 10 deletions br_payment_cnab/serialize/cnab240.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ def _string_to_num(self, toTransform, default=None):
else:
raise

def format_date(self, date):
if not date:
def format_date(self, date_value):
if not date_value:
return ''
if not isinstance(date, datetime):
date = datetime.strptime(date[0:10], "%Y-%m-%d")
return date.strftime("%d%m%Y")
if not isinstance(date_value, (date, datetime)):
date_value = datetime.strptime(date_value[0:10], "%Y-%m-%d")
return date_value.strftime("%d%m%Y")

def _get_header_arq(self):
payment = self._order.payment_mode_id
Expand All @@ -61,7 +61,7 @@ def _get_header_arq(self):
'cedente_conta': self._string_to_num(bank.acc_number),
'cedente_conta_dv': bank.acc_number_dig,
'cedente_nome': self._order.company_id.name,
'data_geracao_arquivo': self.format_date(date.today()),
'data_geracao_arquivo': int(self.format_date(date.today())),
'hora_geracao_arquivo': self._hour_now(),
'numero_sequencial_arquivo': self._order.file_number,
}
Expand All @@ -85,7 +85,7 @@ def _get_segmento(self, line, lot_sequency, num_lot):
"favorecido_nome": line.partner_id.name,
"favorecido_doc_numero": line.partner_id.cnpj_cpf,
"numero_documento_cliente": line.nosso_numero,
"data_pagamento": line.date_maturity,
"data_pagamento": self.format_date(line.date_maturity),
"valor_pagamento": line.value,
"data_real_pagamento": self.format_date(
self._order.data_emissao_cnab),
Expand Down Expand Up @@ -124,14 +124,14 @@ def _get_segmento(self, line, lot_sequency, num_lot):
"nome_concessionaria": information_id.agency_name or '',
"data_vencimento": self.format_date(line.date_maturity),
# GPS
"contribuinte_nome": self._order.company_id.name,
"contribuinte_nome": self._order.company_id.name,
"valor_total_pagamento": self._string_to_monetary(
line.value_final),
"codigo_receita_tributo": information_id.codigo_receita,
"codigo_receita_tributo": information_id.codigo_receita or '',
"tipo_identificacao_contribuinte": 1,
"identificacao_contribuinte": self._string_to_num(
self._order.company_id.cnpj_cpf),
"codigo_identificacao_tributo": information_id.tax_identification,
"codigo_identificacao_tributo": information_id.tax_identification or '',
"mes_ano_competencia": self.get_mes_ano_competencia(line),
"valor_previsto_inss": self._string_to_monetary(line.value),
# DARF
Expand Down Expand Up @@ -252,5 +252,7 @@ def _sum_lot_values(self, lot):
return total

def get_mes_ano_competencia(self, line):
if not line.invoice_date:
return 0
date = datetime.strptime(line.invoice_date, "%Y-%m-%d")
return int('{}{}'.format(date.month, date.year))
89 changes: 49 additions & 40 deletions br_payment_cnab/tests/test_cnab_sicoob.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,54 +198,63 @@ def test_seg(self):
cnab = self.get_cnab_obj(ordem_cobranca)
seg_teste = cnab._get_segmento(ordem_cobranca.line_ids[1], 1, 1)
seg_ok = {
'valor_abatimento': Decimal('1.00'),
'favorecido_codigo_banco': 'BANCO COOPERATIVO\
DO BRASIL S.A. (SICOOB)',
'valor_mora': Decimal('1.00'),
'controle_lote': 1,
'sequencial_registro_lote': 1,
'tipo_movimento': 0,
'codigo_instrucao_movimento': 0,
'codigo_camara_compensacao': 18,
'favorecido_bairro': 'Centro',
'data_vencimento': int(time.strftime("%Y%m%d")),
'favorecido_emissao_aviso': 0,
'nome_concessionaria': '',
'valor_multa': Decimal('3.00'),
'valor_documento': Decimal('120.00'),
'valor_pagamento': Decimal('120.00'),
'codigo_moeda': '09',
'valor_desconto_abatimento': Decimal('3.00'),
'valor_real_pagamento': Decimal('121.00'),
'favorecido_codigo_banco':
'BANCO COOPERATIVO DO BRASIL S.A. (SICOOB)',
'favorecido_agencia': 1234,
'favorecido_agencia_dv': '0',
'favorecido_conta': 12345,
'favorecido_conta_dv': 0,
'favorecido_agencia_conta_dv': '',
'numero_documento_cliente': '20000000000000000000',
'codigo_instrucao_movimento': 0,
'hora_envio_ted': (int(time.strftime("%H%M%S")[0:4])),
'favorecido_nome': 'Parceiro',
'favorecido_doc_numero': 6621204930,
'data_real_pagamento': int(time.strftime("%Y%m%d")),
'valor_multa_juros': Decimal('4.00'),
'data_pagamento': int(time.strftime("%Y%m%d")),
'numero_documento_cliente': '2',
'data_pagamento': int(time.strftime("%d%m%Y")),
'valor_pagamento': Decimal('120.00'),
'data_real_pagamento': int(time.strftime("%d%m%Y")),
'valor_real_pagamento': Decimal('121.00'),
'mensagem2': '',
'finalidade_doc_ted': '01',
'codigo_historico_credito': '2644',
'tipo_movimento': 0,
'finalidade_ted': '11',
'favorecido_emissao_aviso': 0,
'favorecido_inscricao_tipo': 1,
'favorecido_inscricao_numero': 6621204930,
'favorecido_endereco_rua': 'Donicia',
'favorecido_endereco_numero': 45,
'favorecido_endereco_complemento': '',
'favorecido_bairro': 'Centro',
'favorecido_cidade': 'Florianópolis',
'favorecido_cep': 88032050,
'favorecido_uf': 'SC',
'valor_documento': Decimal('120.00'),
'valor_abatimento': Decimal('1.00'),
'valor_desconto': Decimal('2.00'),
'valor_mora': Decimal('1.00'),
'valor_multa': Decimal('3.00'),
'hora_envio_ted': (int(time.strftime("%H%M%S")[0:4])),
'codigo_historico_credito': '2644',
'cedente_nome': 'Trustcode',
'valor_nominal_titulo': Decimal('120.00'),
'valor_desconto_abatimento': Decimal('3.00'),
'valor_multa_juros': Decimal('4.00'),
'codigo_moeda': '09',
'codigo_de_barras': 0,
'cedente_nome': 'Trustcode',
'controle_lote': 1,
'sequencial_registro_lote': 1,
'favorecido_agencia': 1234,
'favorecido_conta': 12345,
'favorecido_agencia_dv': '0',
'favorecido_conta_dv': 0,
'favorecido_cep': 88032050,
'favorecido_cidade': 'Florianópolis',
'favorecido_endereco_complemento': '',
'favorecido_endereco_numero': 45,
'favorecido_endereco_rua': 'Donicia',
'favorecido_inscricao_numero': 6621204930,
'favorecido_inscricao_tipo': 1,
'favorecido_nome': 'Parceiro',
'favorecido_uf': 'SC',
'mensagem2': ''
}
'nome_concessionaria': '',
'data_vencimento': int(time.strftime("%d%m%Y")),
'contribuinte_nome': 'Trustcode',
'valor_total_pagamento': Decimal('121.00'),
'codigo_receita_tributo': '',
'tipo_identificacao_contribuinte': 1,
'identificacao_contribuinte': 92743275000133,
'codigo_identificacao_tributo': '',
'mes_ano_competencia': 0,
'valor_previsto_inss': Decimal('120.00'),
'periodo_apuracao': '',
'valor_principal': Decimal('120.00')}
self.assertEquals(seg_ok, seg_teste)

def sequency_lot(self):
Expand Down

0 comments on commit 320014c

Please sign in to comment.