diff --git a/beesdoo_coda/__init__.py b/beesdoo_coda/__init__.py new file mode 100644 index 0000000..afcfb68 --- /dev/null +++ b/beesdoo_coda/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import wizard \ No newline at end of file diff --git a/beesdoo_coda/__openerp__.py b/beesdoo_coda/__openerp__.py new file mode 100644 index 0000000..788dad9 --- /dev/null +++ b/beesdoo_coda/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Beescoop Coda Import module", + + 'summary': """ + Import coda Wizard based on https://github.com/acsone/pycoda + """, + + 'description': """ + """, + + 'author': "Beescoop - Cellule IT", + 'website': "https://github.com/beescoop/Obeesdoo", + + 'category': 'Accounting & Finance', + 'version': '0.1', + + 'depends': ['account_bank_statement_import'], + + 'data': [ + ], +} diff --git a/beesdoo_coda/wizard/__init__.py b/beesdoo_coda/wizard/__init__.py new file mode 100644 index 0000000..13813f3 --- /dev/null +++ b/beesdoo_coda/wizard/__init__.py @@ -0,0 +1,6 @@ +''' +Created on 19 mai 2016 + +@author: mythrys +''' +import import_coda \ No newline at end of file diff --git a/beesdoo_coda/wizard/import_coda.py b/beesdoo_coda/wizard/import_coda.py new file mode 100644 index 0000000..bc9c88a --- /dev/null +++ b/beesdoo_coda/wizard/import_coda.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +''' +Created on 16 mai 2016 + +@author: Thibault Francois (thibault@françois.be) +''' + +from coda.parser import Parser +from openerp import models, _ + +class CodaBankStatementImport(models.TransientModel): + _inherit = 'account.bank.statement.import' + + def _generate_note(self, move): + notes = [] + if move.counterparty_name: + notes.append("%s: %s" % (_('Counter Party Name'), move.counterparty_name)) + if move.counterparty_address: + notes.append("%s: %s" % (_('Counter Party Address'), move.counterparty_address)) + if move.counterparty_number: + notes.append("%s: %s" % (_('Counter Party Account'), move.counterparty_number)) + if move.communication: + notes.append("%s: %s" % (_('Communication'), move.communication)) + return '\n'.join(notes) + + def _get_move_value(self, move, statement, sequence): + move_data = { + 'name': move.communication, #ok + 'note': self._generate_note(move), + 'date': move.entry_date, #ok + 'amount': move.transaction_amount if move.transaction_amount_sign == '0' else - move.transaction_amount, #ok + 'account_number': move.counterparty_number, #ok + 'partner_name': move.counterparty_name, #ok + 'ref': move.ref, + 'sequence': sequence, #ok + 'unique_import_id' : statement.coda_seq_number + '-' + statement.creation_date + '-' + move.ref + } + return move_data + + def _get_statement_data(self, statement): + statement_data = { + 'name' : statement.paper_seq_number, + 'date' : statement.creation_date, + 'balance_start': statement.old_balance, #ok + 'balance_end_real' : statement.new_balance, #ok + 'coda_note' : '', + 'transactions' : [] + } + return statement_data + + def _parse_file(self, data_file): + parser = Parser() + try: + statements = parser.parse(data_file) + except ValueError: + return super(CodaBankStatementImport, self)._parse_file(data_file) + currency_code = False + account_number = False + + stmts_vals = [] + for statement in statements: + account_number = statement.acc_number + currency_code = statement.currency + statement_data = self._get_statement_data(statement) + stmts_vals.append(statement_data) + for move in statement.movements: + statement_data['transactions'].append(self._get_move_value(move, statement, len(statement_data['transactions']) + 1)) + + return currency_code, account_number, stmts_vals