mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
Add module account_statement_import_base
The 2 modules account_statement_import_online and account_statement_import depend on account_statement_import_base (and not on each other) and share common code, in particular a hook to update the statement line. So we can now have reconciliation modules that use this hook and therefore work both on file import and online import. More details on https://github.com/OCA/bank-statement-import/issues/481. Improve bank statement line form view and journal form view.
This commit is contained in:
committed by
Ronald Portier (Therp BV)
parent
d70a15df69
commit
da5cdcc9c8
@@ -4,7 +4,7 @@
|
||||
|
||||
{
|
||||
"name": "Online Bank Statements",
|
||||
"version": "14.0.2.1.1",
|
||||
"version": "14.0.3.0.0",
|
||||
"author": "CorporateHub, Odoo Community Association (OCA)",
|
||||
"maintainers": ["alexey-pelykh"],
|
||||
"website": "https://github.com/OCA/bank-statement-import",
|
||||
@@ -13,8 +13,7 @@
|
||||
"summary": "Online bank statements update",
|
||||
"external_dependencies": {"python": ["odoo_test_helper"]},
|
||||
"depends": [
|
||||
"account",
|
||||
"account_statement_import",
|
||||
"account_statement_import_base",
|
||||
"web_widget_dropdown_dynamic",
|
||||
],
|
||||
"data": [
|
||||
@@ -24,7 +23,6 @@
|
||||
"wizards/online_bank_statement_pull_wizard.xml",
|
||||
"views/actions.xml",
|
||||
"views/account_journal.xml",
|
||||
"views/account_bank_statement_line.xml",
|
||||
"views/online_bank_statement_provider.xml",
|
||||
],
|
||||
"installable": True,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import account_journal
|
||||
from . import account_bank_statement_line
|
||||
from . import online_bank_statement_provider
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# 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,
|
||||
)
|
||||
@@ -12,7 +12,6 @@ from pytz import timezone, utc
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
|
||||
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||
from odoo.addons.base.models.res_partner import _tz_get
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -259,6 +258,8 @@ class OnlineBankStatementProvider(models.Model):
|
||||
"""Get lines from line data, but only for the right date."""
|
||||
AccountBankStatementLine = self.env["account.bank.statement.line"]
|
||||
provider_tz = timezone(self.tz) if self.tz else utc
|
||||
journal = self.journal_id
|
||||
speeddict = journal._statement_line_import_speeddict()
|
||||
filtered_lines = []
|
||||
for line_values in lines_data:
|
||||
date = line_values["date"]
|
||||
@@ -282,23 +283,18 @@ class OnlineBankStatementProvider(models.Model):
|
||||
date = date.replace(tzinfo=utc)
|
||||
date = date.astimezone(provider_tz).replace(tzinfo=None)
|
||||
line_values["date"] = date
|
||||
journal._statement_line_import_update_unique_import_id(
|
||||
line_values, self.account_number
|
||||
)
|
||||
unique_import_id = line_values.get("unique_import_id")
|
||||
if unique_import_id:
|
||||
unique_import_id = self._generate_unique_import_id(unique_import_id)
|
||||
line_values.update({"unique_import_id": unique_import_id})
|
||||
if AccountBankStatementLine.sudo().search(
|
||||
[("unique_import_id", "=", unique_import_id)], limit=1
|
||||
):
|
||||
continue
|
||||
bank_account_number = line_values.get("account_number")
|
||||
if bank_account_number:
|
||||
sanitized_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"):
|
||||
line_values["payment_ref"] = line_values.get("ref")
|
||||
journal._statement_line_import_update_hook(line_values, speeddict)
|
||||
filtered_lines.append(line_values)
|
||||
return filtered_lines
|
||||
|
||||
@@ -349,36 +345,6 @@ class OnlineBankStatementProvider(models.Model):
|
||||
date_since = date_since.replace(tzinfo=utc).astimezone(tz)
|
||||
return date_since.date()
|
||||
|
||||
def _generate_unique_import_id(self, unique_import_id):
|
||||
self.ensure_one()
|
||||
return (
|
||||
(self.account_number and self.account_number + "-" or "")
|
||||
+ str(self.journal_id.id)
|
||||
+ "-"
|
||||
+ unique_import_id
|
||||
)
|
||||
|
||||
def _sanitize_bank_account_number(self, bank_account_number):
|
||||
"""Hook for extension"""
|
||||
self.ensure_one()
|
||||
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):
|
||||
self.ensure_one()
|
||||
if self.interval_type == "minutes":
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?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>
|
||||
@@ -11,7 +11,7 @@
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_form" />
|
||||
<field name="arch" type="xml">
|
||||
<page name="bank_account" position="inside">
|
||||
<xpath expr="//field[@name='bank_statements_source']/.." position="after">
|
||||
<group
|
||||
name="online_bank_statements"
|
||||
string="Online Bank Statements (OCA)"
|
||||
@@ -47,7 +47,7 @@
|
||||
class="oe_read_only"
|
||||
/>
|
||||
</group>
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath expr="/form/sheet" position="before">
|
||||
<header>
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user