mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
@@ -23,6 +23,7 @@
|
|||||||
"wizards/online_bank_statement_pull_wizard.xml",
|
"wizards/online_bank_statement_pull_wizard.xml",
|
||||||
"views/actions.xml",
|
"views/actions.xml",
|
||||||
"views/account_journal.xml",
|
"views/account_journal.xml",
|
||||||
|
"views/account_bank_statement_line.xml",
|
||||||
"views/online_bank_statement_provider.xml",
|
"views/online_bank_statement_provider.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from . import account_journal
|
from . import account_journal
|
||||||
|
from . import account_bank_statement_line
|
||||||
from . import online_bank_statement_provider
|
from . import online_bank_statement_provider
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Copyright 2021 Therp BV <https://therp.nl>.
|
||||||
|
# @author: Ronald Portier <ronald@therp.nl>.
|
||||||
|
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
|
||||||
|
"""Add raw data to statement line, to solve import issues."""
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class AccountBankStatementLine(models.Model):
|
||||||
|
"""Add raw data to statement line, to solve import issues."""
|
||||||
|
|
||||||
|
_inherit = "account.bank.statement.line"
|
||||||
|
|
||||||
|
online_raw_data = fields.Text(
|
||||||
|
help="The complete data retrieved online for this transaction",
|
||||||
|
readonly=True,
|
||||||
|
copy=False,
|
||||||
|
)
|
||||||
@@ -292,13 +292,11 @@ class OnlineBankStatementProvider(models.Model):
|
|||||||
continue
|
continue
|
||||||
bank_account_number = line_values.get("account_number")
|
bank_account_number = line_values.get("account_number")
|
||||||
if bank_account_number:
|
if bank_account_number:
|
||||||
line_values.update(
|
sanitized_account_number = self._sanitize_bank_account_number(
|
||||||
{
|
bank_account_number
|
||||||
"account_number": (
|
|
||||||
self._sanitize_bank_account_number(bank_account_number)
|
|
||||||
),
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
line_values["account_number"] = sanitized_account_number
|
||||||
|
self._update_partner_from_account_number(line_values)
|
||||||
if not line_values.get("payment_ref"):
|
if not line_values.get("payment_ref"):
|
||||||
line_values["payment_ref"] = line_values.get("ref")
|
line_values["payment_ref"] = line_values.get("ref")
|
||||||
filtered_lines.append(line_values)
|
filtered_lines.append(line_values)
|
||||||
@@ -365,6 +363,22 @@ class OnlineBankStatementProvider(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
return sanitize_account_number(bank_account_number)
|
return sanitize_account_number(bank_account_number)
|
||||||
|
|
||||||
|
def _update_partner_from_account_number(self, line_values):
|
||||||
|
"""Lookup partner using account number."""
|
||||||
|
self.ensure_one()
|
||||||
|
partner_bank = self.env["res.partner.bank"].search(
|
||||||
|
[
|
||||||
|
("acc_number", "=", line_values["account_number"]),
|
||||||
|
"|",
|
||||||
|
("company_id", "=", False),
|
||||||
|
("company_id", "=", self.company_id.id),
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
if partner_bank:
|
||||||
|
line_values["partner_bank_id"] = partner_bank.id
|
||||||
|
line_values["partner_id"] = partner_bank.partner_id.id
|
||||||
|
|
||||||
def _get_next_run_period(self):
|
def _get_next_run_period(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if self.interval_type == "minutes":
|
if self.interval_type == "minutes":
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_bank_statement_line_form" model="ir.ui.view">
|
||||||
|
<field name="model">account.bank.statement.line</field>
|
||||||
|
<field
|
||||||
|
name="inherit_id"
|
||||||
|
ref="account_statement_import.view_bank_statement_line_form"
|
||||||
|
/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="move_id" position="after">
|
||||||
|
<field name="partner_name" />
|
||||||
|
</field>
|
||||||
|
<xpath expr="//sheet" position="inside">
|
||||||
|
<group colspan="4" col="1">
|
||||||
|
<separator string="Raw Data" />
|
||||||
|
<field
|
||||||
|
name="online_raw_data"
|
||||||
|
nolabel="1"
|
||||||
|
groups="base.group_no_one"
|
||||||
|
/>
|
||||||
|
</group>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -156,34 +156,32 @@ class OnlineBankStatementProviderPonto(models.Model):
|
|||||||
response = requests.get(
|
response = requests.get(
|
||||||
page_url, params=params, headers=self._ponto_header()
|
page_url, params=params, headers=self._ponto_header()
|
||||||
)
|
)
|
||||||
if response.status_code == 200:
|
if response.status_code != 200:
|
||||||
if params.get("before"):
|
|
||||||
params.pop("before")
|
|
||||||
data = json.loads(response.text)
|
|
||||||
links = data.get("links", {})
|
|
||||||
if page_next:
|
|
||||||
page_url = links.get("next", False)
|
|
||||||
else:
|
|
||||||
page_url = links.get("prev", False)
|
|
||||||
transactions = data.get("data", [])
|
|
||||||
if transactions:
|
|
||||||
current_transactions = []
|
|
||||||
for transaction in transactions:
|
|
||||||
date = self._ponto_date_from_string(
|
|
||||||
transaction.get("attributes", {}).get("executionDate")
|
|
||||||
)
|
|
||||||
if date_since <= date < date_until:
|
|
||||||
current_transactions.append(transaction)
|
|
||||||
|
|
||||||
if current_transactions:
|
|
||||||
if not page_next or (page_next and not latest_identifier):
|
|
||||||
latest_identifier = current_transactions[0].get("id")
|
|
||||||
transaction_lines.extend(current_transactions)
|
|
||||||
else:
|
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_("Error during get transaction.\n\n%s \n\n %s")
|
_("Error during get transaction.\n\n%s \n\n %s")
|
||||||
% (response.status_code, response.text)
|
% (response.status_code, response.text)
|
||||||
)
|
)
|
||||||
|
if params.get("before"):
|
||||||
|
params.pop("before")
|
||||||
|
data = json.loads(response.text)
|
||||||
|
links = data.get("links", {})
|
||||||
|
if page_next:
|
||||||
|
page_url = links.get("next", False)
|
||||||
|
else:
|
||||||
|
page_url = links.get("prev", False)
|
||||||
|
transactions = data.get("data", [])
|
||||||
|
if transactions:
|
||||||
|
current_transactions = []
|
||||||
|
for transaction in transactions:
|
||||||
|
date = self._ponto_date_from_string(
|
||||||
|
transaction.get("attributes", {}).get("executionDate")
|
||||||
|
)
|
||||||
|
if date_since <= date < date_until:
|
||||||
|
current_transactions.append(transaction)
|
||||||
|
if current_transactions:
|
||||||
|
if not page_next or (page_next and not latest_identifier):
|
||||||
|
latest_identifier = current_transactions[0].get("id")
|
||||||
|
transaction_lines.extend(current_transactions)
|
||||||
if latest_identifier:
|
if latest_identifier:
|
||||||
self.ponto_last_identifier = latest_identifier
|
self.ponto_last_identifier = latest_identifier
|
||||||
return transaction_lines
|
return transaction_lines
|
||||||
@@ -197,6 +195,7 @@ class OnlineBankStatementProviderPonto(models.Model):
|
|||||||
return dt.replace(tzinfo=None)
|
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):
|
||||||
|
"""Translate information from Ponto to Odoo bank statement lines."""
|
||||||
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
|
||||||
@@ -215,27 +214,33 @@ class OnlineBankStatementProviderPonto(models.Model):
|
|||||||
sequence = 0
|
sequence = 0
|
||||||
for transaction in transaction_lines:
|
for transaction in transaction_lines:
|
||||||
sequence += 1
|
sequence += 1
|
||||||
attributes = transaction.get("attributes", {})
|
vals_line = self._ponto_get_transaction_vals(transaction, sequence)
|
||||||
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,
|
|
||||||
"ref": re.sub(" +", " ", ref) or "/",
|
|
||||||
"payment_ref": 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)
|
new_transactions.append(vals_line)
|
||||||
if new_transactions:
|
if new_transactions:
|
||||||
return new_transactions, {}
|
return new_transactions, {}
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _ponto_get_transaction_vals(self, transaction, sequence):
|
||||||
|
"""Translate information from Ponto to statement line vals."""
|
||||||
|
attributes = transaction.get("attributes", {})
|
||||||
|
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,
|
||||||
|
"ref": re.sub(" +", " ", ref) or "/",
|
||||||
|
"payment_ref": attributes.get("remittanceInformation", ref),
|
||||||
|
"unique_import_id": transaction["id"],
|
||||||
|
"amount": attributes["amount"],
|
||||||
|
"online_raw_data": transaction,
|
||||||
|
}
|
||||||
|
if attributes.get("counterpartReference"):
|
||||||
|
vals_line["account_number"] = attributes["counterpartReference"]
|
||||||
|
if attributes.get("counterpartName"):
|
||||||
|
vals_line["partner_name"] = attributes["counterpartName"]
|
||||||
|
return vals_line
|
||||||
|
|||||||
Reference in New Issue
Block a user