Пример #1
0
    def gen_boleto(self, cr, uid, ids, boleto_ids, context=None):
        boleto_obj = self.pool.get('boleto.boleto')
        fbuffer = StringIO()
        boleto_pdf = BoletoPDF(fbuffer)
        for bol in boleto_obj.browse(cr, uid, boleto_ids, context=context):

            if bol.banco == 'bb':
                boleto = BoletoBB(7, 2)
            elif bol.banco == 'bradesco':
                boleto = BoletoBradesco()
            elif bol.banco == 'caixa':
                boleto = BoletoCaixa()
            elif bol.banco == 'real':
                boleto = BoletoReal()
            elif bol.banco == 'sicredi':
                boleto = BoletoSicredi(5,1)
            elif bol.banco == 'itau':
                boleto = BoletoItau()
            boleto.cedente = bol.cedente.partner_id.legal_name
            boleto.cedente_documento = bol.cedente.partner_id.cnpj_cpf
            boleto.cedente_uf = bol.cedente.partner_id.state_id.code
            boleto.cedente_logradouro = bol.cedente.partner_id.street
            boleto.cedente_cidade = bol.cedente.partner_id.l10n_br_city_id.name
            boleto.cedente_bairro = bol.cedente.partner_id.district
            boleto.cedente_cep = bol.cedente.partner_id.zip
            boleto.carteira = bol.carteira
            boleto.agencia_cedente = bol.agencia_cedente
            boleto.conta_cedente = bol.conta_cedente
            boleto.data_vencimento = datetime.date(datetime.strptime(bol.data_vencimento, '%Y-%m-%d'))
            boleto.data_documento = datetime.date(datetime.strptime(bol.data_documento, '%Y-%m-%d'))
            boleto.data_processamento = date.today()
            boleto.valor_documento = bol.valor
            boleto.nosso_numero = bol.numero_documento
            boleto.numero_documento = bol.numero_documento
            boleto.convenio = bol.convenio
            # se documento de origem contrato buscar datas
            #data_ini = bol.data_vencimento[8:11] + '/' + bol.data_vencimento[5:7] + '/' + bol.data_vencimento[0:4]
            #data_fim = datetime.strftime(boleto.data_vencimento+relativedelta(months=+1),'%Y-%m-%d')
            #data_final = data_fim[8:11] + '/' + data_fim[5:7] + '/' + data_fim[0:4]
            #instrucao = bol.instrucoes %(str(bol.valor*0.02), str(bol.valor*0.1), str(data_ini), str(data_final))
            #boleto.instrucoes = instrucao.split('\n') if instrucao else ""
            boleto.instrucoes = bol.instrucao.split('\n') if bol.instrucao else ""
            boleto.sacado = [
                "%s" % (bol.sacado.legal_name or bol.sacado.name),
                "CNPJ/CPF: %s" % (bol.sacado.cnpj_cpf),
                "%s, %s - %s - %s - Cep. %s" % (bol.sacado.street, bol.sacado.number, bol.sacado.district, bol.sacado.l10n_br_city_id.name + '-' + bol.sacado.state_id.code, bol.sacado.zip),
                ]
            boleto_pdf.drawBoleto(boleto)
            boleto_pdf.nextPage()

        boleto_pdf.save()
        boleto_file = fbuffer.getvalue().encode("base64")
        fbuffer.close()
        return boleto_file
Пример #2
0
    def gen_boleto(self, cr, uid, ids, boleto_ids, context=None):
        boleto_obj = self.pool.get('boleto.boleto')
        fbuffer = StringIO()
        boleto_pdf = BoletoPDF(fbuffer)

        for bol in boleto_obj.browse(cr, uid, boleto_ids, context=context):

            if bol.banco == 'bb':
                boleto = BoletoBB(7, 2)
            elif bol.banco == 'bradesco':
                boleto = BoletoBradesco()
            elif bol.banco == 'caixa':
                boleto = BoletoCaixa()
            elif bol.banco == 'real':
                boleto = BoletoReal()
            elif bol.banco == 'sicredi':
                boleto = BoletoSicredi(5,1)

            boleto.cedente = bol.cedente.name
            boleto.cedente_documento = bol.cedente.cnpj_cpf
            boleto.cedente_uf = bol.cedente.state_id.name
            boleto.cedente_logradouro = bol.sacado.street
            boleto.carteira = bol.carteira
            boleto.agencia_cedente = bol.agencia_cedente
            boleto.conta_cedente = bol.conta_cedente
            boleto.data_vencimento = datetime.date(datetime.strptime(bol.data_vencimento, '%Y-%m-%d'))
            boleto.data_documento = datetime.date(datetime.strptime(bol.data_documento, '%Y-%m-%d'))
            boleto.data_processamento = date.today()
            boleto.valor_documento = bol.valor
            boleto.nosso_numero = bol.numero_documento
            boleto.numero_documento = bol.numero_documento
            boleto.convenio = bol.convenio
            boleto.instrucoes = bol.instrucoes.split('\n') if bol.instrucoes else ""
            boleto.sacado = [
                "%s" % (bol.sacado.legal_name or bol.sacado.name),
                "CNPJ/CPF: %s" % (bol.sacado.cnpj_cpf),
                "%s, %s - %s - %s - Cep. %s" % (bol.sacado.street, bol.sacado.number, bol.sacado.district, bol.sacado.city, bol.sacado.zip),
                ]
            boleto_pdf.drawBoleto(boleto)
            boleto_pdf.nextPage()

        boleto_pdf.save()
        boleto_file = fbuffer.getvalue().encode("base64")
        fbuffer.close()
        return boleto_file
Пример #3
0
    def gen_boleto(self, cr, uid, ids, boleto_ids, context=None):
        boleto_obj = self.pool.get('boleto.boleto')
        fbuffer = StringIO()
        boleto_pdf = BoletoPDF(fbuffer)
        #inv_obj = self.pool.get('account.invoice')
        #active_ids = context.get('active_ids', [])
        #for invoice in inv_obj.browse(cr, uid, active_ids, context=context):
        #inv_obj = self.pool.get('account.invoice')
        #for invoice in inv_obj.browse(cr, uid, ids, context=context):
            #contrato_obj = self.pool.get('account.analytic.account')
            #contrato_line = contrato_obj.search(cr, uid, [('code','=',invoice.origin)], context=context)
            #for contrato in contrato_line:
            #    data_contrato = contrato.date
            #    data_vencimento = contrato
        for bol in boleto_obj.browse(cr, uid, boleto_ids, context=context):

            if bol.banco == 'bb':
                boleto = BoletoBB(7, 2)
            elif bol.banco == 'bradesco':
                boleto = BoletoBradesco()
            elif bol.banco == 'caixa':
                boleto = BoletoCaixa()
            elif bol.banco == 'real':
                boleto = BoletoReal()
            elif bol.banco == 'sicredi':
                boleto = BoletoSicredi(5,1)
            elif bol.banco == 'itau':
                boleto = BoletoItau()
            boleto.cedente = bol.cedente.partner_id.legal_name
            boleto.cedente_documento = bol.cedente.partner_id.cnpj_cpf
            boleto.cedente_uf = bol.cedente.partner_id.state_id.code
            boleto.cedente_logradouro = bol.cedente.partner_id.street
            boleto.cedente_cidade = bol.cedente.partner_id.l10n_br_city_id.name
            boleto.cedente_bairro = bol.cedente.partner_id.district
            boleto.cedente_cep = bol.cedente.partner_id.zip
            boleto.carteira = bol.carteira
            boleto.agencia_cedente = bol.agencia_cedente
            boleto.conta_cedente = bol.conta_cedente
            boleto.data_vencimento = datetime.date(datetime.strptime(bol.data_vencimento, '%Y-%m-%d'))
            boleto.data_documento = datetime.date(datetime.strptime(bol.data_documento, '%Y-%m-%d'))
            boleto.data_processamento = date.today()
            boleto.valor_documento = bol.valor
            boleto.nosso_numero = bol.numero_documento
            boleto.numero_documento = bol.numero_documento
            boleto.convenio = bol.convenio
            # se documento de origem contrato buscar datas
            data_ini = bol.data_vencimento[8:11] + '/' + bol.data_vencimento[5:7] + '/' + bol.data_vencimento[0:4]
            data_fim = datetime.strftime(boleto.data_vencimento+relativedelta(months=+1),'%Y-%m-%d')
            data_final = data_fim[8:11] + '/' + data_fim[5:7] + '/' + data_fim[0:4]
            instrucao = bol.instrucoes %(str(bol.valor*0.02), str(bol.valor*0.1), str(data_ini), str(data_final))
            boleto.instrucoes = instrucao.split('\n') if instrucao else ""
            boleto.sacado = [
                "%s" % (bol.sacado.legal_name or bol.sacado.name),
                "CNPJ/CPF: %s" % (bol.sacado.cnpj_cpf),
                "%s, %s - %s - %s - Cep. %s" % (bol.sacado.street, bol.sacado.number, bol.sacado.district, bol.sacado.l10n_br_city_id.name + '-' + bol.sacado.state_id.code, bol.sacado.zip),
                ]
            boleto_pdf.drawBoleto(boleto)
            boleto_pdf.nextPage()

        boleto_pdf.save()
        boleto_file = fbuffer.getvalue().encode("base64")
        fbuffer.close()
        return boleto_file
Пример #4
0
    def gen_boleto(self, cr, uid, ids, boleto_ids, context=None):
        boleto_obj = self.pool.get("boleto.boleto")
        fbuffer = StringIO()
        boleto_pdf = BoletoPDF(fbuffer)
        for bol in boleto_obj.browse(cr, uid, boleto_ids, context=context):

            if bol.banco == "bb":
                boleto = BoletoBB(7, 2)
            elif bol.banco == "bradesco":
                boleto = BoletoBradesco()
            elif bol.banco == "caixa":
                boleto = BoletoCaixa()
            elif bol.banco == "real":
                boleto = BoletoReal()
            elif bol.banco == "sicredi":
                boleto = BoletoSicredi(5, 1)
            elif bol.banco == "itau":
                boleto = BoletoItau()
            boleto.cedente = bol.cedente.partner_id.legal_name
            boleto.cedente_documento = bol.cedente.partner_id.cnpj_cpf
            boleto.cedente_uf = bol.cedente.partner_id.state_id.code
            boleto.cedente_logradouro = bol.cedente.partner_id.street
            boleto.cedente_cidade = bol.cedente.partner_id.l10n_br_city_id.name
            boleto.cedente_bairro = bol.cedente.partner_id.district
            boleto.cedente_cep = bol.cedente.partner_id.zip
            boleto.carteira = bol.carteira
            boleto.agencia_cedente = bol.agencia_cedente
            boleto.conta_cedente = bol.conta_cedente
            boleto.data_vencimento = datetime.date(datetime.strptime(bol.data_vencimento, "%Y-%m-%d"))
            boleto.data_documento = datetime.date(datetime.strptime(bol.data_documento, "%Y-%m-%d"))
            boleto.data_processamento = date.today()
            boleto.valor_documento = bol.valor
            boleto.nosso_numero = bol.numero_documento
            boleto.numero_documento = bol.numero_documento
            boleto.convenio = bol.convenio
            # se documento de origem contrato buscar datas
            # data_ini = bol.data_vencimento[8:11] + '/' + bol.data_vencimento[5:7] + '/' + bol.data_vencimento[0:4]
            # data_fim = datetime.strftime(boleto.data_vencimento+relativedelta(months=+1),'%Y-%m-%d')
            # data_final = data_fim[8:11] + '/' + data_fim[5:7] + '/' + data_fim[0:4]
            # instrucao = bol.instrucoes %(str(bol.valor*0.02), str(bol.valor*0.1), str(data_ini), str(data_final))
            # boleto.instrucoes = instrucao.split('\n') if instrucao else ""
            boleto.instrucoes = bol.instrucao.split("\n") if bol.instrucao else ""
            boleto.sacado = [
                "%s" % (bol.sacado.legal_name or bol.sacado.name),
                "CNPJ/CPF: %s" % (bol.sacado.cnpj_cpf),
                "%s, %s - %s - %s - Cep. %s"
                % (
                    bol.sacado.street,
                    bol.sacado.number,
                    bol.sacado.district,
                    bol.sacado.l10n_br_city_id.name + "-" + bol.sacado.state_id.code,
                    bol.sacado.zip,
                ),
            ]
            boleto_pdf.drawBoleto(boleto)
            boleto_pdf.nextPage()

        boleto_pdf.save()
        boleto_file = fbuffer.getvalue().encode("base64")
        fbuffer.close()
        return boleto_file
Пример #5
0
    def generate_boleto(self, cr, user, invoice, conta, linha):
        
        _logger.info('Invoice: '+str(invoice.partner_id.cnpj_cpf))
#        if conta.bank.bic == "001":
        fbuffer = StringIO()
        boleto_pdf = BoletoPDF(fbuffer)

        boleto = BoletoBB(7, 2)

        try:
            juros_dia = float(linha[0]['ValorJurosDia'])
        except ValueError:
            juros_dia = 0
            
        try:
            val_multa = float(linha[0]['ValorMulta'])
        except ValueError:
            val_multa = 0
           
        _logger.info('Após vencimento, multa de R$ '+str(val_multa)+' e mora de R$ '+str(juros_dia))
        
        MsgProtesto = linha[0]['MsgProtesto']

        MsgSacador = False
        NomeSacador = False
        DocSacador =  False


        if linha[0]['IndMensagemSacAva'] == 'A':
            if linha[0]['DocSacador'] and linha[0]['NomeSacador']:
                MsgSacador = True
                NomeSacador = linha[0]['NomeSacador']
                DocSacador =  linha[0]['DocSacador'] 
        
        txtDemons = ""
        if linha[0]['txtDemonstra']:
            txtDemons = linha[0]['txtDemonstra']
            
        #boleto_obj = self.pool.get('boleto.boleto')
        
        boleto.cedente = str(user.company_id.partner_id.legal_name)
        boleto.cedente_logradouro = user.company_id.partner_id.street + ', ' + user.company_id.partner_id.number
        boleto.cedente_cidade = 'Curitiba' #user.company_id.partner_id.l10n_br_city.name
        boleto.cedente_uf = 'PR'
        boleto.cedente_bairro = 'Centro'
        boleto.cedente_cep = str(user.company_id.partner_id.zip)
        
        boleto.sacado_nome = (invoice.partner_id.legal_name or invoice.partner_id.name)
        boleto.sacado_documento = str(invoice.partner_id.cnpj_cpf)
        boleto.sacado_cidade = invoice.partner_id.l10n_br_city_id.name
        boleto.sacado_uf = invoice.partner_id.state_id.code
        boleto.sacado_endereco = "%s, %s" % (invoice.partner_id.street, invoice.partner_id.number)
        boleto.sacado_bairro = invoice.partner_id.district
        boleto.sacado_cep = invoice.partner_id.zip
        
        if MsgSacador is True:
            boleto.sacador_documento = DocSacador
            boleto.sacador_nome = NomeSacador

        boleto.cedente_documento = str(user.company_id.partner_id.cnpj_cpf)
        boleto.carteira = str(conta.cod_carteira)
        boleto.agencia_cedente = conta.bra_number
        boleto.conta_cedente = conta.acc_number
        boleto.data_vencimento = datetime.date(datetime.strptime(invoice.date_due, '%Y-%m-%d'))
        boleto.data_documento = datetime.date(datetime.strptime(invoice.date_invoice, '%Y-%m-%d'))
        boleto.data_processamento = date.today()
        boleto.valor_documento = str(invoice.amount_total)
        #boleto.valor = '100'
        boleto.nosso_numero = invoice.number
        boleto.numero_documento = str(invoice.number)
        boleto.convenio = str(conta.nro_convenio)
        
        Linha_Juros = ''
        if juros_dia > 0 and val_multa > 0:
            Linha_Juros = u'Após vencimento, multa de R$ %.2f e mora de R$ %.2f ao dia.\r\n' % (val_multa,juros_dia)
        
        if MsgProtesto:
            Linha_Juros = Linha_Juros + MsgProtesto + '\r\n'
        
        if txtDemons:
            Linha_Juros = Linha_Juros + txtDemons  + '\r\n'
            boleto.demonstrativo = txtDemons  + '\r\n'
       
        if conta.instrucoes:
            boleto.instrucoes = Linha_Juros + conta.instrucoes + '\r\n'
        else:
            boleto.instrucoes = Linha_Juros
        
        
        boleto.especie = 'R$'
        boleto.especie_documento = 'DM'
        boleto.aceite = 'N'
        boleto.quantidade = ''
        #boleto.nosso_numero = 1
        boleto.sacado = [
                         u"%s - %s" % (invoice.partner_id.cnpj_cpf,linha[0]['NomeSacado']),
                         u"%s - %s - %s - %s - Cep. %s" % (linha[0]['EnderecoSacado'], linha[0]['BairroSacado'], 
                                                           linha[0]['CidadeSacado'], linha[0]['UfCidadeSacado'], 
                                                           linha[0]['CepSacado']),
                         u'',]

#             boleto.sacado = [
#                 "%s" % (invoice.partner_id.legal_name or invoice.partner_id.name),
#                 "%s, %s - %s - %s - Cep. %s" % (invoice.partner_id.street, invoice.partner_id.number, invoice.partner_id.district, invoice.partner_id.city, invoice.partner_id.zip),
#                 ""
#                 ]
#         nosso_numero = str(boleto.format_nosso_numero())
#         linha[0]['NossoNumero'] = nosso_numero[:17]
#         _logger.info('NossoNumero: '+str(boleto.format_nosso_numero()))

        boleto_pdf.drawBoleto(boleto)
        boleto_pdf.nextPage()

        boleto_pdf.save()

        fbuffer.seek(0)
        conteudo = fbuffer.read()
        res = conteudo
        return res