From 1b5d30e042edcb25bf1d9ea32274a0deda9237f4 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sat, 12 Dec 2020 18:21:14 +0100 Subject: [PATCH] [FIX+IMP] account_bank_statement_import_online_ponto: Adjustments for better use * FIX: Returned dates are in UTC, so they were classified incorrectly in the bad statement. * FIX: Information in ref was the most important one, being the other mostly '/' * IMP: Preserve all possible information from the source, including counterpart information. * IMP: Fill Odoo statement line fields for account number and partner name for better support. --- .../__manifest__.py | 2 +- ...unt_bank_statement_import_online_ponto.pot | 14 +++--- .../online_bank_statement_provider_ponto.py | 47 +++++++++---------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/account_bank_statement_import_online_ponto/__manifest__.py b/account_bank_statement_import_online_ponto/__manifest__.py index a709649e..489501e9 100644 --- a/account_bank_statement_import_online_ponto/__manifest__.py +++ b/account_bank_statement_import_online_ponto/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Online Bank Statements: MyPonto.com", - "version": "12.0.1.0.0", + "version": "12.0.1.1.0", "category": "Account", "website": "https://github.com/OCA/bank-statement-import", "author": "Florent de Labarre, Odoo Community Association (OCA)", diff --git a/account_bank_statement_import_online_ponto/i18n/account_bank_statement_import_online_ponto.pot b/account_bank_statement_import_online_ponto/i18n/account_bank_statement_import_online_ponto.pot index 4755596b..41a62533 100644 --- a/account_bank_statement_import_online_ponto/i18n/account_bank_statement_import_online_ponto.pot +++ b/account_bank_statement_import_online_ponto/i18n/account_bank_statement_import_online_ponto.pot @@ -14,8 +14,8 @@ msgstr "" "Plural-Forms: \n" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:88 -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:104 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:81 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:97 #, python-format msgid "%s \n" "\n" @@ -23,7 +23,7 @@ msgid "%s \n" msgstr "" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:123 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:116 #, python-format msgid "Error during Create Synchronisation %s \n" "\n" @@ -31,7 +31,7 @@ msgid "Error during Create Synchronisation %s \n" msgstr "" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:178 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:171 #, python-format msgid "Error during get transaction.\n" "\n" @@ -51,19 +51,19 @@ msgid "Online Bank Statement Provider" msgstr "" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:65 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:58 #, python-format msgid "Please fill login and key." msgstr "" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:81 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:74 #, python-format msgid "Ponto : no token" msgstr "" #. module: account_bank_statement_import_online_ponto -#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:197 +#: code:addons/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py:195 #, python-format msgid "Ponto : wrong configuration, unknow account %s" msgstr "" diff --git a/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py b/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py index 469c2cd5..f0a30de7 100644 --- a/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py +++ b/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py @@ -6,6 +6,7 @@ import json import base64 import time import re +import pytz from datetime import datetime from odoo import api, fields, models, _ @@ -41,14 +42,6 @@ class OnlineBankStatementProviderPonto(models.Model): ) return self._ponto_obtain_statement_data(date_since, date_until) - def _get_statement_date(self, date_since, date_until): - self.ensure_one() - if self.service != 'ponto': - return super()._get_statement_date( - date_since, - date_until, - ) - return date_since.date() ######### # ponto # @@ -182,47 +175,53 @@ class OnlineBankStatementProviderPonto(models.Model): return transaction_lines def _ponto_date_from_string(self, date_str): - return datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ') + """Dates in Ponto are expressed in UTC, so we need to convert them + to supplied tz for proper classification. + """ + dt = datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%fZ') + dt = dt.replace(tzinfo=pytz.utc).astimezone( + pytz.timezone(self.tz or 'utc') + ) + return dt.replace(tzinfo=None) def _ponto_obtain_statement_data(self, date_since, date_until): self.ensure_one() - account_ids = self._ponto_get_account_ids() journal = self.journal_id - iban = self.account_number account_id = account_ids.get(iban) if not account_id: raise UserError( _('Ponto : wrong configuration, unknow account %s') % journal.bank_account_id.acc_number) - self._ponto_synchronisation(account_id) - - transaction_lines = self._ponto_get_transaction(account_id, - date_since, - date_until) - + transaction_lines = self._ponto_get_transaction( + account_id, date_since, date_until) new_transactions = [] sequence = 0 for transaction in transaction_lines: sequence += 1 attributes = transaction.get('attributes', {}) - ref = '%s %s' % ( - attributes.get('description'), - attributes.get('counterpartName')) + ref_list = [attributes.get(x) for x in { + "description", + "counterpartName", + "counterpartReference", + } if attributes.get(x)] + ref = " ".join(ref_list) date = self._ponto_date_from_string(attributes.get('executionDate')) - vals_line = { 'sequence': sequence, 'date': date, - 'name': re.sub(' +', ' ', ref) or '/', - 'ref': attributes.get('remittanceInformation', ''), + 'ref': re.sub(' +', ' ', ref) or '/', + 'name': attributes.get('remittanceInformation', ref), 'unique_import_id': transaction['id'], 'amount': attributes['amount'], } + if attributes.get("counterpartReference"): + vals_line["account_number"] = attributes["counterpartReference"] + if attributes.get("counterpartName"): + vals_line["partner_name"] = attributes["counterpartName"] new_transactions.append(vals_line) - if new_transactions: return new_transactions, {} return