Browse Source

[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.
12.0
Pedro M. Baeza 4 years ago
parent
commit
77076caef2
  1. 2
      account_bank_statement_import_online_ponto/__manifest__.py
  2. 47
      account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py

2
account_bank_statement_import_online_ponto/__manifest__.py

@ -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)",

47
account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py

@ -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(account_id,
date_since,
date_until)
transaction_lines = self._ponto_get_transaction(
account_id, 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' % (
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')) 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': attributes.get('remittanceInformation', ''),
'ref': re.sub(' +', ' ', ref) or '/',
'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
Loading…
Cancel
Save