From 6efd9d53388e3337144ed587faa26a83380651d8 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sun, 9 Oct 2016 16:04:16 +0200 Subject: [PATCH 1/6] [ADD] crelan import module --- beesdoo_crelan_csv/__init__.py | 2 + beesdoo_crelan_csv/__openerp__.py | 22 ++++ beesdoo_crelan_csv/wizard/__init__.py | 6 + .../wizard/import_crelan_csv.py | 120 ++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 beesdoo_crelan_csv/__init__.py create mode 100644 beesdoo_crelan_csv/__openerp__.py create mode 100644 beesdoo_crelan_csv/wizard/__init__.py create mode 100644 beesdoo_crelan_csv/wizard/import_crelan_csv.py diff --git a/beesdoo_crelan_csv/__init__.py b/beesdoo_crelan_csv/__init__.py new file mode 100644 index 0000000..56c29d9 --- /dev/null +++ b/beesdoo_crelan_csv/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import wizard diff --git a/beesdoo_crelan_csv/__openerp__.py b/beesdoo_crelan_csv/__openerp__.py new file mode 100644 index 0000000..3a252a3 --- /dev/null +++ b/beesdoo_crelan_csv/__openerp__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +{ + 'name': "Beescoop Coda Import module", + + 'summary': """ + Import Crelan CSV Wizard + """, + + '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_crelan_csv/wizard/__init__.py b/beesdoo_crelan_csv/wizard/__init__.py new file mode 100644 index 0000000..bd91c43 --- /dev/null +++ b/beesdoo_crelan_csv/wizard/__init__.py @@ -0,0 +1,6 @@ +''' +Created on 09 octobre 2016 + +@author: Thibault Francois +''' +import import_crelan_csv \ No newline at end of file diff --git a/beesdoo_crelan_csv/wizard/import_crelan_csv.py b/beesdoo_crelan_csv/wizard/import_crelan_csv.py new file mode 100644 index 0000000..e89bfca --- /dev/null +++ b/beesdoo_crelan_csv/wizard/import_crelan_csv.py @@ -0,0 +1,120 @@ +# -*- coding: utf-8 -*- +''' +Created on 09 Octobre 2016 + +@author: Thibault Francois (thibault@françois.be) +''' + +from StringIO import StringIO +import csv +import datetime +from openerp import models, _ + +ACCOUNT = "Compte donneur d'ordre" +CURRENCY = "Devise" +DATE = "Date" +AMOUNT = "Montant" +COUNTERPART_NUMBER = "Compte contrepartie" +COUNTERPART_NAME = "Contrepartie" +COMMUNICATION = "Communication" +TRANSACTION_TYPE = "Type d'op\xc3\xa9ration" + +class CodaBankStatementImport(models.TransientModel): + _inherit = 'account.bank.statement.import' + + _date_format = "%d/%m/%Y" + + _decimal_sep = "." + _csv_delimiter = ";" + _csv_quote = '"' + + _header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'op\xc3\xa9ration", 'Communication', "Compte donneur d'ordre"] + + + def _generate_note(self, move): + notes = [] + notes.append("%s: %s" % (_('Counter Party Name'), move[COUNTERPART_NAME])) + notes.append("%s: %s" % (_('Counter Party Account'), move[COUNTERPART_NUMBER])) + notes.append("%s: %s" % (_('Communication'), move[COMMUNICATION])) + return '\n'.join(notes) + + def _get_move_value(self, move, sequence): + move_data = { + 'name': move[TRANSACTION_TYPE] + ": " + move[COMMUNICATION], + 'note': self._generate_note(move), + 'date': self._to_iso_date(move[DATE]), + 'amount': float(move[AMOUNT]), + 'account_number': move[COUNTERPART_NUMBER], #ok + 'partner_name': move[COUNTERPART_NAME], #ok + 'ref': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME], + 'sequence': sequence, #ok + 'unique_import_id' : move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME] + } + return move_data + + def _get_statement_data(self, balance_start, balance_end, begin_date, end_date): + statement_data = { + 'name' : _("Bank Statement from %s to %s") % (begin_date, end_date), + 'date' : self._to_iso_date(end_date), + 'balance_start': balance_start, #ok + 'balance_end_real' : balance_end, #ok + 'transactions' : [] + } + return statement_data + + def _get_acc_number(self, acc_number): + #Check if we match the exact acc_number or the end of an acc number + journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) + if not journal or len(journal) > 1: #if not found or ambiguious + return acc_number + + return journal.bank_acc_number + + def _get_acc_balance(self, acc_number): + if not self.init_balance == None: + return self.init_balance + print "compute balance" + + journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) + if not journal or len(journal) > 1: #if not found or ambiguious + self.init_balance = 0.0 + else: + self.init_balance = float(journal.get_journal_dashboard_datas()['last_balance'][:-1].strip().replace(',', '')) + + return self.init_balance + + def _to_iso_date(self, orig_date): + date_obj = datetime.datetime.strptime(orig_date, self._date_format) + return date_obj.strftime('%Y-%m-%d') + + def _parse_file(self, data_file): + + try: + csv_file = StringIO(data_file) + data = csv.DictReader(csv_file, delimiter=self._csv_delimiter, quotechar=self._csv_quote) + if not data.fieldnames == self._header: + raise ValueError() + except ValueError: + return super(CodaBankStatementImport, self)._parse_file(data_file) + + currency_code = False + account_number = False + self.init_balance = None + begin_date = False + end_date = False + + transactions = [] + i = 1 + sum_transaction = 0 + for statement in data: + begin_date = begin_date or statement[DATE] + end_date = statement[DATE] + account_number = statement[ACCOUNT] + balance = self._get_acc_balance(account_number) + currency_code = statement[CURRENCY] + transactions.append(self._get_move_value(statement, i)) + sum_transaction += float(statement[AMOUNT]) + i += 1 + stmt = self._get_statement_data(balance, balance+ sum_transaction, begin_date, end_date) + stmt['transactions'] = transactions + return currency_code, self._get_acc_number(account_number), [stmt] From 39e2f0972523e0165a3c04f1c33200d4a6a97c71 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sun, 13 Nov 2016 16:27:07 +0100 Subject: [PATCH 2/6] [ADD] translation file for each individual module --- beesdoo_crelan_csv/__openerp__.py | 2 +- beesdoo_crelan_csv/i18n/fr_BE.po | 46 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 beesdoo_crelan_csv/i18n/fr_BE.po diff --git a/beesdoo_crelan_csv/__openerp__.py b/beesdoo_crelan_csv/__openerp__.py index 3a252a3..b8dd7b0 100644 --- a/beesdoo_crelan_csv/__openerp__.py +++ b/beesdoo_crelan_csv/__openerp__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- { - 'name': "Beescoop Coda Import module", + 'name': "Beescoop Crelan Import module", 'summary': """ Import Crelan CSV Wizard diff --git a/beesdoo_crelan_csv/i18n/fr_BE.po b/beesdoo_crelan_csv/i18n/fr_BE.po new file mode 100644 index 0000000..7a7e59b --- /dev/null +++ b/beesdoo_crelan_csv/i18n/fr_BE.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * beesdoo_crelan_csv +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-13 15:19+0000\n" +"PO-Revision-Date: 2016-11-13 15:19+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: beesdoo_crelan_csv +#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:57 +#, python-format +msgid "Bank Statement from %s to %s" +msgstr "Bank Statement from %s to %s" + +#. module: beesdoo_crelan_csv +#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:38 +#, python-format +msgid "Communication" +msgstr "Communication" + +#. module: beesdoo_crelan_csv +#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:37 +#, python-format +msgid "Counter Party Account" +msgstr "Counter Party Account" + +#. module: beesdoo_crelan_csv +#: code:addons/beesdoo_crelan_csv/wizard/import_crelan_csv.py:36 +#, python-format +msgid "Counter Party Name" +msgstr "Counter Party Name" + +#. module: beesdoo_crelan_csv +#: model:ir.model,name:beesdoo_crelan_csv.model_account_bank_statement_import +msgid "Import Bank Statement" +msgstr "Import d'un relevé bancaire" + From db8505cc5eae7dd3a8aac8e637a5a182a2c67ffe Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 24 Nov 2016 19:35:19 +0100 Subject: [PATCH 3/6] [FIX] conflict name of crelan import with coda import --- .../wizard/import_crelan_csv.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/beesdoo_crelan_csv/wizard/import_crelan_csv.py b/beesdoo_crelan_csv/wizard/import_crelan_csv.py index e89bfca..9f306ab 100644 --- a/beesdoo_crelan_csv/wizard/import_crelan_csv.py +++ b/beesdoo_crelan_csv/wizard/import_crelan_csv.py @@ -31,17 +31,17 @@ class CodaBankStatementImport(models.TransientModel): _header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'op\xc3\xa9ration", 'Communication', "Compte donneur d'ordre"] - def _generate_note(self, move): + def _generate_note_crelan(self, move): notes = [] notes.append("%s: %s" % (_('Counter Party Name'), move[COUNTERPART_NAME])) notes.append("%s: %s" % (_('Counter Party Account'), move[COUNTERPART_NUMBER])) notes.append("%s: %s" % (_('Communication'), move[COMMUNICATION])) return '\n'.join(notes) - def _get_move_value(self, move, sequence): + def _get_move_value_crelan(self, move, sequence): move_data = { 'name': move[TRANSACTION_TYPE] + ": " + move[COMMUNICATION], - 'note': self._generate_note(move), + 'note': self._generate_note_crelan(move), 'date': self._to_iso_date(move[DATE]), 'amount': float(move[AMOUNT]), 'account_number': move[COUNTERPART_NUMBER], #ok @@ -52,7 +52,7 @@ class CodaBankStatementImport(models.TransientModel): } return move_data - def _get_statement_data(self, balance_start, balance_end, begin_date, end_date): + def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date): statement_data = { 'name' : _("Bank Statement from %s to %s") % (begin_date, end_date), 'date' : self._to_iso_date(end_date), @@ -62,7 +62,7 @@ class CodaBankStatementImport(models.TransientModel): } return statement_data - def _get_acc_number(self, acc_number): + def _get_acc_number_crelan(self, acc_number): #Check if we match the exact acc_number or the end of an acc number journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) if not journal or len(journal) > 1: #if not found or ambiguious @@ -70,7 +70,7 @@ class CodaBankStatementImport(models.TransientModel): return journal.bank_acc_number - def _get_acc_balance(self, acc_number): + def _get_acc_balance_crelan(self, acc_number): if not self.init_balance == None: return self.init_balance print "compute balance" @@ -110,11 +110,11 @@ class CodaBankStatementImport(models.TransientModel): begin_date = begin_date or statement[DATE] end_date = statement[DATE] account_number = statement[ACCOUNT] - balance = self._get_acc_balance(account_number) + balance = self._get_acc_balance_crelan(account_number) currency_code = statement[CURRENCY] - transactions.append(self._get_move_value(statement, i)) + transactions.append(self._get_move_value_crelan(statement, i)) sum_transaction += float(statement[AMOUNT]) i += 1 - stmt = self._get_statement_data(balance, balance+ sum_transaction, begin_date, end_date) + stmt = self._get_statement_data_crelan(balance, balance+ sum_transaction, begin_date, end_date) stmt['transactions'] = transactions - return currency_code, self._get_acc_number(account_number), [stmt] + return currency_code, self._get_acc_number_crelan(account_number), [stmt] From 98348d4f922c8bb10852a582f5259fbbe16c4f6b Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sun, 19 Mar 2017 13:39:51 +0100 Subject: [PATCH 4/6] [FIX] Crelan, add md5 hash of the communication in order to avoid collision --- beesdoo_crelan_csv/wizard/import_crelan_csv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beesdoo_crelan_csv/wizard/import_crelan_csv.py b/beesdoo_crelan_csv/wizard/import_crelan_csv.py index 9f306ab..f56fde1 100644 --- a/beesdoo_crelan_csv/wizard/import_crelan_csv.py +++ b/beesdoo_crelan_csv/wizard/import_crelan_csv.py @@ -8,6 +8,7 @@ Created on 09 Octobre 2016 from StringIO import StringIO import csv import datetime +import md5 from openerp import models, _ ACCOUNT = "Compte donneur d'ordre" @@ -48,7 +49,7 @@ class CodaBankStatementImport(models.TransientModel): 'partner_name': move[COUNTERPART_NAME], #ok 'ref': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME], 'sequence': sequence, #ok - 'unique_import_id' : move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME] + 'unique_import_id' : move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME] + '-' + md5.new(move[COMMUNICATION]).hexdigest() } return move_data From c1bfb3593170188f488b2fbfaeee5e257dda13b7 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Sun, 7 May 2017 23:41:21 +0200 Subject: [PATCH 5/6] [FIX] Import crelan use user lang to convert str balance to float --- beesdoo_crelan_csv/wizard/import_crelan_csv.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beesdoo_crelan_csv/wizard/import_crelan_csv.py b/beesdoo_crelan_csv/wizard/import_crelan_csv.py index f56fde1..4fdaf47 100644 --- a/beesdoo_crelan_csv/wizard/import_crelan_csv.py +++ b/beesdoo_crelan_csv/wizard/import_crelan_csv.py @@ -74,14 +74,15 @@ class CodaBankStatementImport(models.TransientModel): def _get_acc_balance_crelan(self, acc_number): if not self.init_balance == None: return self.init_balance - print "compute balance" journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) if not journal or len(journal) > 1: #if not found or ambiguious self.init_balance = 0.0 else: - self.init_balance = float(journal.get_journal_dashboard_datas()['last_balance'][:-1].strip().replace(',', '')) - + lang = self._context.get('lang', 'en_US') + l = self.env['res.lang'].search([('code', '=', lang)]) + balance = journal.get_journal_dashboard_datas()['last_balance'][:-1] + self.init_balance = float(balance.strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.')) return self.init_balance def _to_iso_date(self, orig_date): From 5deabce60d5f9f4f1cd7f23f086e9c1080e60b29 Mon Sep 17 00:00:00 2001 From: Manuel Claeys Bouuaert Date: Fri, 15 May 2020 11:52:33 +0200 Subject: [PATCH 6/6] [MIG] pos_require_product_quantity: v9 to v12 --- beesdoo_crelan_csv/__init__.py | 4 +- .../{__openerp__.py => __manifest__.py} | 11 ++-- beesdoo_crelan_csv/models/__init__.py | 1 + beesdoo_crelan_csv/models/account_journal.py | 10 ++++ beesdoo_crelan_csv/wizard/__init__.py | 7 +-- .../wizard/import_crelan_csv.py | 52 +++++++++---------- 6 files changed, 44 insertions(+), 41 deletions(-) rename beesdoo_crelan_csv/{__openerp__.py => __manifest__.py} (61%) create mode 100644 beesdoo_crelan_csv/models/__init__.py create mode 100644 beesdoo_crelan_csv/models/account_journal.py diff --git a/beesdoo_crelan_csv/__init__.py b/beesdoo_crelan_csv/__init__.py index 56c29d9..9b42961 100644 --- a/beesdoo_crelan_csv/__init__.py +++ b/beesdoo_crelan_csv/__init__.py @@ -1,2 +1,2 @@ -# -*- coding: utf-8 -*- -import wizard +from . import models +from . import wizard diff --git a/beesdoo_crelan_csv/__openerp__.py b/beesdoo_crelan_csv/__manifest__.py similarity index 61% rename from beesdoo_crelan_csv/__openerp__.py rename to beesdoo_crelan_csv/__manifest__.py index b8dd7b0..647f2c8 100644 --- a/beesdoo_crelan_csv/__openerp__.py +++ b/beesdoo_crelan_csv/__manifest__.py @@ -1,4 +1,7 @@ -# -*- coding: utf-8 -*- +# Copyright 2016 - 2020 BEES coop SCRLfs +# - Thibault Francois (thibault@françois.be) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + { 'name': "Beescoop Crelan Import module", @@ -13,10 +16,8 @@ 'website': "https://github.com/beescoop/Obeesdoo", 'category': 'Accounting & Finance', - 'version': '0.1', + 'version': '12.0.1.0.0', 'depends': ['account_bank_statement_import'], - - 'data': [ - ], + 'installable': True, } diff --git a/beesdoo_crelan_csv/models/__init__.py b/beesdoo_crelan_csv/models/__init__.py new file mode 100644 index 0000000..2388e11 --- /dev/null +++ b/beesdoo_crelan_csv/models/__init__.py @@ -0,0 +1 @@ +from . import account_journal diff --git a/beesdoo_crelan_csv/models/account_journal.py b/beesdoo_crelan_csv/models/account_journal.py new file mode 100644 index 0000000..98517c8 --- /dev/null +++ b/beesdoo_crelan_csv/models/account_journal.py @@ -0,0 +1,10 @@ +from odoo import models + + +class AccountJournal(models.Model): + _inherit = "account.journal" + + def _get_bank_statements_available_import_formats(self): + formats_list = super()._get_bank_statements_available_import_formats() + formats_list.append('Crelan') + return formats_list diff --git a/beesdoo_crelan_csv/wizard/__init__.py b/beesdoo_crelan_csv/wizard/__init__.py index bd91c43..c9834f4 100644 --- a/beesdoo_crelan_csv/wizard/__init__.py +++ b/beesdoo_crelan_csv/wizard/__init__.py @@ -1,6 +1 @@ -''' -Created on 09 octobre 2016 - -@author: Thibault Francois -''' -import import_crelan_csv \ No newline at end of file +from . import import_crelan_csv diff --git a/beesdoo_crelan_csv/wizard/import_crelan_csv.py b/beesdoo_crelan_csv/wizard/import_crelan_csv.py index 4fdaf47..bd5d2d9 100644 --- a/beesdoo_crelan_csv/wizard/import_crelan_csv.py +++ b/beesdoo_crelan_csv/wizard/import_crelan_csv.py @@ -1,15 +1,8 @@ -# -*- coding: utf-8 -*- -''' -Created on 09 Octobre 2016 - -@author: Thibault Francois (thibault@françois.be) -''' - -from StringIO import StringIO +from io import StringIO import csv import datetime -import md5 -from openerp import models, _ +import hashlib +from odoo import models, _ ACCOUNT = "Compte donneur d'ordre" CURRENCY = "Devise" @@ -18,7 +11,7 @@ AMOUNT = "Montant" COUNTERPART_NUMBER = "Compte contrepartie" COUNTERPART_NAME = "Contrepartie" COMMUNICATION = "Communication" -TRANSACTION_TYPE = "Type d'op\xc3\xa9ration" +TRANSACTION_TYPE = "Type d'opération" class CodaBankStatementImport(models.TransientModel): _inherit = 'account.bank.statement.import' @@ -29,7 +22,8 @@ class CodaBankStatementImport(models.TransientModel): _csv_delimiter = ";" _csv_quote = '"' - _header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'op\xc3\xa9ration", 'Communication', "Compte donneur d'ordre"] + _header = ['Date', 'Montant', 'Devise', 'Contrepartie', 'Compte contrepartie', "Type d'opération", + 'Communication', "Compte donneur d'ordre"] def _generate_note_crelan(self, move): @@ -45,28 +39,29 @@ class CodaBankStatementImport(models.TransientModel): 'note': self._generate_note_crelan(move), 'date': self._to_iso_date(move[DATE]), 'amount': float(move[AMOUNT]), - 'account_number': move[COUNTERPART_NUMBER], #ok - 'partner_name': move[COUNTERPART_NAME], #ok + 'account_number': move[COUNTERPART_NUMBER], # Ok + 'partner_name': move[COUNTERPART_NAME], # Ok 'ref': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME], - 'sequence': sequence, #ok - 'unique_import_id' : move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + move[COUNTERPART_NAME] + '-' + md5.new(move[COMMUNICATION]).hexdigest() + 'sequence': sequence, # Ok + 'unique_import_id': move[DATE] + '-' + move[AMOUNT] + '-' + move[COUNTERPART_NUMBER] + '-' + + move[COUNTERPART_NAME] + '-' + hashlib.new('md5', move[COMMUNICATION].encode()).hexdigest() } return move_data def _get_statement_data_crelan(self, balance_start, balance_end, begin_date, end_date): statement_data = { - 'name' : _("Bank Statement from %s to %s") % (begin_date, end_date), - 'date' : self._to_iso_date(end_date), - 'balance_start': balance_start, #ok - 'balance_end_real' : balance_end, #ok + 'name': _("Bank Statement from %s to %s") % (begin_date, end_date), + 'date': self._to_iso_date(end_date), + 'balance_start': balance_start, # Ok + 'balance_end_real' : balance_end, # Ok 'transactions' : [] } return statement_data def _get_acc_number_crelan(self, acc_number): - #Check if we match the exact acc_number or the end of an acc number + # Check if we match the exact acc_number or the end of an acc number journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) - if not journal or len(journal) > 1: #if not found or ambiguious + if not journal or len(journal) > 1: # If not found or ambiguious return acc_number return journal.bank_acc_number @@ -76,13 +71,14 @@ class CodaBankStatementImport(models.TransientModel): return self.init_balance journal = self.env['account.journal'].search([('bank_acc_number', '=like', '%' + acc_number)]) - if not journal or len(journal) > 1: #if not found or ambiguious + currency = journal.currency_id or journal.company_id.currency_id + if not journal or len(journal) > 1: # If not found or ambiguious self.init_balance = 0.0 else: lang = self._context.get('lang', 'en_US') l = self.env['res.lang'].search([('code', '=', lang)]) balance = journal.get_journal_dashboard_datas()['last_balance'][:-1] - self.init_balance = float(balance.strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.')) + self.init_balance = float(balance.replace(currency.symbol, '').strip().replace(l.thousands_sep, '').replace(l.decimal_point, '.')) return self.init_balance def _to_iso_date(self, orig_date): @@ -92,7 +88,7 @@ class CodaBankStatementImport(models.TransientModel): def _parse_file(self, data_file): try: - csv_file = StringIO(data_file) + csv_file = StringIO(data_file.decode()) data = csv.DictReader(csv_file, delimiter=self._csv_delimiter, quotechar=self._csv_quote) if not data.fieldnames == self._header: raise ValueError() @@ -107,16 +103,16 @@ class CodaBankStatementImport(models.TransientModel): transactions = [] i = 1 - sum_transaction = 0 + sum_transaction = 0 for statement in data: begin_date = begin_date or statement[DATE] end_date = statement[DATE] - account_number = statement[ACCOUNT] + account_number = statement[ACCOUNT] balance = self._get_acc_balance_crelan(account_number) currency_code = statement[CURRENCY] transactions.append(self._get_move_value_crelan(statement, i)) sum_transaction += float(statement[AMOUNT]) i += 1 - stmt = self._get_statement_data_crelan(balance, balance+ sum_transaction, begin_date, end_date) + stmt = self._get_statement_data_crelan(balance, balance + sum_transaction, begin_date, end_date) stmt['transactions'] = transactions return currency_code, self._get_acc_number_crelan(account_number), [stmt]