Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrigido informaçoes que faltavam #11

Open
wants to merge 18 commits into
base: cnab
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions account_bank_statement_import_cnab/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Bank Statement Parse CNAB
=========================

Module to import FEBRABAN-CNAB Format bank statement files.

Based on the Banking addons framework.

Known issues / Roadmap
======================

* None

TODO

- Importar o arquivo conforme banco selecionando no diário
- Colocar Saldo Inicial e Final
1 change: 1 addition & 0 deletions account_bank_statement_import_cnab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_bank_statement_import
34 changes: 34 additions & 0 deletions account_bank_statement_import_cnab/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ATS <http://atsti.com.br>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'CNAB Format Bank Statements Import',
'version': '8.0.0.0.0',
'license': 'AGPL-3',
'author': 'Carlos Silveira',
'website': '',
'category': 'Banking addons',
'depends': [
'account_bank_statement_import',
],
'demo': [
'demo/demo_data.xml',
],
'installable': True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ATS <http://atsti.com.br>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
import tempfile
import codecs
from openerp import api, models, fields
from .cnab import CnabParser as Parser


_logger = logging.getLogger(__name__)


class AccountBankStatementImport(models.TransientModel):
"""Add process_camt method to account.bank.statement.import."""
_inherit = 'account.bank.statement.import'

@api.multi
def import_file(self):
""" Process the file chosen in the wizard, create bank statement(s) and
go to reconciliation."""
file_path = tempfile.gettempdir()+'/file.ret'
data = self.data_file
f = open(file_path,'wb')
f.write(data.decode('base64'))
f.close()
data_file = codecs.open(file_path, encoding='ascii')
statement_ids, notifications = self.with_context(
active_id=self.id)._import_file(data_file)
action = self.env.ref(
'account.action_bank_reconcile_bank_statements')
return {
'name': action.name,
'tag': action.tag,
'context': {
'statement_ids': statement_ids,
'notifications': notifications
},
'type': 'ir.actions.client',
}

def _parse_file(self, cr, uid, data_file, context=None):
"""Parse a CNAB file."""
parser = Parser()
try:
_logger.debug("Try parsing with camt.")
return parser.parse(data_file)
except ValueError:
# Not a camt file, returning super will call next candidate:
_logger.debug("Statement file was not a camt file.",
exc_info=True)
return super(AccountBankStatementImport, self)._parse_file(
cr, uid, data_file, context=context)
55 changes: 55 additions & 0 deletions account_bank_statement_import_cnab/cnab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2015 ATS<http://atsti.com.br>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import re
from datetime import datetime
from lxml import etree
from openerp.addons.account_bank_statement_import.parserlib import (
BankStatement)
import cnab240
from cnab240.bancos import itau
from cnab240.tipos import Arquivo
import codecs



class CnabParser(object):
"""Parser for cnab bank statement import files."""

def parse(self, data):
"""Launch the parsing itself."""
arquivo = Arquivo(itau, arquivo=data)
res = []
for lote in arquivo.lotes:
trans = []
for evento in lote.eventos:
trans.append({
'name': evento.numero_documento,
'date': datetime.strptime(str(evento.data_ocorrencia), '%d%m%Y'),
'amount': evento.valor_titulo,
'unique_import_id': str(evento.nosso_numero),
})
res.append({
'name': str(lote.header.controlecob_data_gravacao) + str(lote.header.controlecob_numero),
'currency_code': 'BRL',
'account_number': str(lote.header.cedente_conta),
'date': datetime.strptime(str(lote.header.controlecob_data_gravacao), '%d%m%Y'),
'transactions': trans, #nosso numero
})
return res
26 changes: 26 additions & 0 deletions account_bank_statement_import_cnab/demo/demo_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="cnab_bank_journal" model="account.journal">
<field name="name">BANCO ITAU S.A.</field>
<field name="code">ITAU</field>
<field name="type">bank</field>
<field name="sequence_id" ref="account.sequence_bank_journal"/>
<field name="default_debit_account_id" ref="account.bnk"/>
<field name="default_credit_account_id" ref="account.bnk"/>
<field name="user_id" ref="base.user_root"/>
</record>

<record id="cnab_company_bank" model="res.partner.bank">
<field name="owner_name">Your Company</field>
<field name="acc_number">90885</field>
<field name="partner_id" ref="base.partner_root"></field>
<field name="company_id" ref="base.main_company"></field>
<field name="journal_id" ref="cnab_bank_journal"></field>
<field name="state">bank</field>
<field name="bank" ref="base.res_bank_1"/>
</record>
</data>

</openerp>
24 changes: 24 additions & 0 deletions account_bank_statement_import_cnab/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-10-04 11:43+0200\n"
"Last-Translator: Rudolf Schnapka <[email protected]>\n"
"Language-Team: French (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/fr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 1.8.3\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Kontoauszug importieren"
23 changes: 23 additions & 0 deletions account_bank_statement_import_cnab/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-07-24 07:41+0000\n"
"Last-Translator: <>\n"
"Language-Team: Spanish (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/es/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: es\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Importar extracto bancario"
23 changes: 23 additions & 0 deletions account_bank_statement_import_cnab/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-07-24 07:41+0000\n"
"Last-Translator: <>\n"
"Language-Team: French (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/fr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: fr\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Importer Relevé Bancaire"
23 changes: 23 additions & 0 deletions account_bank_statement_import_cnab/i18n/lt_LT.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-07-24 07:41+0000\n"
"Last-Translator: <>\n"
"Language-Team: Lithuanian (Lithuania) (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/lt_LT/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: lt_LT\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Importuoti banko išrašą"
24 changes: 24 additions & 0 deletions account_bank_statement_import_cnab/i18n/nl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
# Erwin van der Ploeg <[email protected]>, 2015
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-07-31 06:44+0000\n"
"Last-Translator: Erwin van der Ploeg <[email protected]>\n"
"Language-Team: Dutch (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/nl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: nl\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Importeer bankafschrift"
23 changes: 23 additions & 0 deletions account_bank_statement_import_cnab/i18n/pt_BR.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-10-09 09:23+0000\n"
"PO-Revision-Date: 2015-10-09 00:26+0000\n"
"Last-Translator: danimaribeiro <[email protected]>\n"
"Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/pt_BR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: pt_BR\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Importar Extrato Bancário"
23 changes: 23 additions & 0 deletions account_bank_statement_import_cnab/i18n/sl.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_bank_statement_import_camt
#
# Translators:
msgid ""
msgstr ""
"Project-Id-Version: bank-statement-import (8.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-07-24 21:51+0000\n"
"PO-Revision-Date: 2015-07-25 12:19+0000\n"
"Last-Translator: Matjaž Mozetič <[email protected]>\n"
"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-bank-statement-import-8-0/language/sl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: sl\n"
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"

#. module: account_bank_statement_import_camt
#: model:ir.model,name:account_bank_statement_import_camt.model_account_bank_statement_import
msgid "Import Bank Statement"
msgstr "Uvoz bančnega izpiska"
6 changes: 6 additions & 0 deletions account_bank_statement_import_cnab/test_files/B413105AYY.RET
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
34100000 212393194000111 00435 000000090885 5JAHUW COMERCIAL LTDA BANCO ITAU S.A. 213102015025237000018040
34100011T0100030 2012393194000111 00445 000000090885 5JAHUW COMERCIAL LTDA 000000181310201514102015
3410001300001T 0200445000000009099505109000000137 006426 05112015000000000008777000000314300 000000000000000000ATS SOLUCOES 000000000000000000000000000000000
3410001300002U 020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001310201500000000000000000000000000000000000 00000000000000000000000
34100015 00008000013400000000005064391000000000000000000000000000000000000000000000000000000000000000000000MT14/10S
34199999 000001000082
Loading