[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.
This commit is contained in:
Pedro M. Baeza
2020-12-12 18:21:14 +01:00
committed by João Marques
parent 8e111d0e97
commit 1b5d30e042
3 changed files with 31 additions and 32 deletions

View File

@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{ {
"name": "Online Bank Statements: MyPonto.com", "name": "Online Bank Statements: MyPonto.com",
"version": "12.0.1.0.0", "version": "12.0.1.1.0",
"category": "Account", "category": "Account",
"website": "https://github.com/OCA/bank-statement-import", "website": "https://github.com/OCA/bank-statement-import",
"author": "Florent de Labarre, Odoo Community Association (OCA)", "author": "Florent de Labarre, Odoo Community Association (OCA)",

View File

@@ -14,8 +14,8 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: account_bank_statement_import_online_ponto #. 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:81
#: 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:97
#, python-format #, python-format
msgid "%s \n" msgid "%s \n"
"\n" "\n"
@@ -23,7 +23,7 @@ msgid "%s \n"
msgstr "" msgstr ""
#. module: account_bank_statement_import_online_ponto #. 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 #, python-format
msgid "Error during Create Synchronisation %s \n" msgid "Error during Create Synchronisation %s \n"
"\n" "\n"
@@ -31,7 +31,7 @@ msgid "Error during Create Synchronisation %s \n"
msgstr "" msgstr ""
#. module: account_bank_statement_import_online_ponto #. 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 #, python-format
msgid "Error during get transaction.\n" msgid "Error during get transaction.\n"
"\n" "\n"
@@ -51,19 +51,19 @@ msgid "Online Bank Statement Provider"
msgstr "" msgstr ""
#. module: account_bank_statement_import_online_ponto #. 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 #, python-format
msgid "Please fill login and key." msgid "Please fill login and key."
msgstr "" msgstr ""
#. module: account_bank_statement_import_online_ponto #. 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 #, python-format
msgid "Ponto : no token" msgid "Ponto : no token"
msgstr "" msgstr ""
#. module: account_bank_statement_import_online_ponto #. 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 #, python-format
msgid "Ponto : wrong configuration, unknow account %s" msgid "Ponto : wrong configuration, unknow account %s"
msgstr "" msgstr ""

View File

@@ -6,6 +6,7 @@ import json
import base64 import base64
import time import time
import re import re
import pytz
from datetime import datetime from datetime import datetime
from odoo import api, fields, models, _ from odoo import api, fields, models, _
@@ -41,14 +42,6 @@ class OnlineBankStatementProviderPonto(models.Model):
) )
return self._ponto_obtain_statement_data(date_since, date_until) 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 # # ponto #
@@ -182,47 +175,53 @@ class OnlineBankStatementProviderPonto(models.Model):
return transaction_lines return transaction_lines
def _ponto_date_from_string(self, date_str): 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): def _ponto_obtain_statement_data(self, date_since, date_until):
self.ensure_one() self.ensure_one()
account_ids = self._ponto_get_account_ids() account_ids = self._ponto_get_account_ids()
journal = self.journal_id journal = self.journal_id
iban = self.account_number iban = self.account_number
account_id = account_ids.get(iban) account_id = account_ids.get(iban)
if not account_id: if not account_id:
raise UserError( raise UserError(
_('Ponto : wrong configuration, unknow account %s') _('Ponto : wrong configuration, unknow account %s')
% journal.bank_account_id.acc_number) % journal.bank_account_id.acc_number)
self._ponto_synchronisation(account_id) self._ponto_synchronisation(account_id)
transaction_lines = self._ponto_get_transaction(
transaction_lines = self._ponto_get_transaction(account_id, account_id, date_since, date_until)
date_since,
date_until)
new_transactions = [] new_transactions = []
sequence = 0 sequence = 0
for transaction in transaction_lines: for transaction in transaction_lines:
sequence += 1 sequence += 1
attributes = transaction.get('attributes', {}) attributes = transaction.get('attributes', {})
ref = '%s %s' % ( ref_list = [attributes.get(x) for x in {
attributes.get('description'), "description",
attributes.get('counterpartName')) "counterpartName",
"counterpartReference",
} if attributes.get(x)]
ref = " ".join(ref_list)
date = self._ponto_date_from_string(attributes.get('executionDate')) date = self._ponto_date_from_string(attributes.get('executionDate'))
vals_line = { vals_line = {
'sequence': sequence, 'sequence': sequence,
'date': date, 'date': date,
'name': re.sub(' +', ' ', ref) or '/', 'ref': re.sub(' +', ' ', ref) or '/',
'ref': attributes.get('remittanceInformation', ''), 'name': attributes.get('remittanceInformation', ref),
'unique_import_id': transaction['id'], 'unique_import_id': transaction['id'],
'amount': attributes['amount'], '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) new_transactions.append(vals_line)
if new_transactions: if new_transactions:
return new_transactions, {} return new_transactions, {}
return return