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
Rocío Vega
parent
b1f165eace
commit
bd20798a1c
1
account_statement_import_base/README.rst
Normal file
1
account_statement_import_base/README.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Will be autogenerated from the readme subdir
|
||||||
1
account_statement_import_base/__init__.py
Normal file
1
account_statement_import_base/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
19
account_statement_import_base/__manifest__.py
Normal file
19
account_statement_import_base/__manifest__.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Base module for Bank Statement Import",
|
||||||
|
"category": "Accounting",
|
||||||
|
"version": "14.0.1.0.0",
|
||||||
|
"license": "LGPL-3",
|
||||||
|
"depends": ["account"],
|
||||||
|
"author": "Akretion, Odoo Community Association (OCA)",
|
||||||
|
"maintainers": ["alexis-via"],
|
||||||
|
"development_status": "Mature",
|
||||||
|
"website": "https://github.com/OCA/bank-statement-import",
|
||||||
|
"data": [
|
||||||
|
"views/account_bank_statement_line.xml",
|
||||||
|
],
|
||||||
|
"installable": True,
|
||||||
|
}
|
||||||
2
account_statement_import_base/models/__init__.py
Normal file
2
account_statement_import_base/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import account_bank_statement_line
|
||||||
|
from . import account_journal
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class AccountBankStatementLine(models.Model):
|
||||||
|
_inherit = "account.bank.statement.line"
|
||||||
|
|
||||||
|
# Ensure transactions can be imported only once
|
||||||
|
# if the import format provides unique transaction IDs
|
||||||
|
unique_import_id = fields.Char(string="Import ID", readonly=True, copy=False)
|
||||||
|
raw_data = fields.Text(readonly=True, copy=False)
|
||||||
|
|
||||||
|
_sql_constraints = [
|
||||||
|
(
|
||||||
|
"unique_import_id",
|
||||||
|
"unique(unique_import_id)",
|
||||||
|
"A bank account transaction can be imported only once!",
|
||||||
|
)
|
||||||
|
]
|
||||||
69
account_statement_import_base/models/account_journal.py
Normal file
69
account_statement_import_base/models/account_journal.py
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
||||||
|
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
from odoo.addons.base.models.res_bank import sanitize_account_number
|
||||||
|
|
||||||
|
|
||||||
|
class AccountJournal(models.Model):
|
||||||
|
_inherit = "account.journal"
|
||||||
|
|
||||||
|
def _statement_line_import_speeddict(self):
|
||||||
|
"""This method is designed to be inherited by reconciliation modules.
|
||||||
|
These modules can take advantage of this method to pre-fetch data
|
||||||
|
that will later be used for many statement lines (to avoid
|
||||||
|
searching data for each statement line).
|
||||||
|
The goal is to improve performances.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
speeddict = {"account_number": {}}
|
||||||
|
partner_banks = self.env["res.partner.bank"].search_read(
|
||||||
|
[("company_id", "in", (False, self.company_id.id))],
|
||||||
|
["acc_number", "partner_id"],
|
||||||
|
)
|
||||||
|
for partner_bank in partner_banks:
|
||||||
|
speeddict["account_number"][partner_bank["acc_number"]] = {
|
||||||
|
"partner_id": partner_bank["partner_id"][0],
|
||||||
|
"partner_bank_id": partner_bank["id"],
|
||||||
|
}
|
||||||
|
return speeddict
|
||||||
|
|
||||||
|
def _statement_line_import_update_hook(self, st_line_vals, speeddict):
|
||||||
|
"""This method is designed to be inherited by reconciliation modules.
|
||||||
|
In this method you can:
|
||||||
|
- update the partner of the line by writing st_line_vals['partner_id']
|
||||||
|
- set an automated counter-part via counterpart_account_id by writing
|
||||||
|
st_line_vals['counterpart_account_id']
|
||||||
|
- do anythink you want with the statement line
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
if st_line_vals.get("account_number"):
|
||||||
|
st_line_vals["account_number"] = self._sanitize_bank_account_number(
|
||||||
|
st_line_vals["account_number"]
|
||||||
|
)
|
||||||
|
if not st_line_vals.get("partner_id") and speeddict["account_number"].get(
|
||||||
|
st_line_vals["account_number"]
|
||||||
|
):
|
||||||
|
st_line_vals.update(
|
||||||
|
speeddict["account_number"][st_line_vals["account_number"]]
|
||||||
|
)
|
||||||
|
|
||||||
|
def _statement_line_import_update_unique_import_id(
|
||||||
|
self, st_line_vals, account_number
|
||||||
|
):
|
||||||
|
self.ensure_one()
|
||||||
|
if st_line_vals.get("unique_import_id"):
|
||||||
|
sanitized_acc_number = self._sanitize_bank_account_number(account_number)
|
||||||
|
st_line_vals["unique_import_id"] = (
|
||||||
|
(sanitized_acc_number and sanitized_acc_number + "-" or "")
|
||||||
|
+ str(self.id)
|
||||||
|
+ "-"
|
||||||
|
+ st_line_vals["unique_import_id"]
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _sanitize_bank_account_number(self, account_number):
|
||||||
|
"""Hook for extension"""
|
||||||
|
return sanitize_account_number(account_number)
|
||||||
1
account_statement_import_base/readme/CONTRIBUTORS.rst
Normal file
1
account_statement_import_base/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
4
account_statement_import_base/readme/DESCRIPTION.rst
Normal file
4
account_statement_import_base/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
This is a technical module designed to share code between 2 other modules:
|
||||||
|
|
||||||
|
* **account_statement_import** that allows to import bank statements from files,
|
||||||
|
* **account_statement_import_online** that allows to import bank statements from webservices/APIs.
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<!--
|
||||||
|
Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
Licence LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.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.view_bank_statement_line_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="statement_id" position="attributes">
|
||||||
|
<attribute
|
||||||
|
name="invisible"
|
||||||
|
>not context.get('statement_line_main_view')</attribute>
|
||||||
|
</field>
|
||||||
|
<xpath expr="//field[@name='company_id']/.." position="attributes">
|
||||||
|
<attribute name="col">2</attribute>
|
||||||
|
</xpath>
|
||||||
|
<field name="sequence" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</field>
|
||||||
|
<!--
|
||||||
|
I don't see anything interesting in the 'ref' field of the
|
||||||
|
move linked to the statement line
|
||||||
|
and the field move_id is displayed in the view.
|
||||||
|
But if you think it's useful to see this field,
|
||||||
|
don't hesitate to remove the 2 lines below
|
||||||
|
-->
|
||||||
|
<field name="ref" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</field>
|
||||||
|
<field name="narration" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</field>
|
||||||
|
<field name="transaction_type" position="after">
|
||||||
|
<field name="partner_bank_id" />
|
||||||
|
</field>
|
||||||
|
<sheet position="inside">
|
||||||
|
<notebook>
|
||||||
|
<page name="narration" string="Notes">
|
||||||
|
<field name="narration" nolabel="1" />
|
||||||
|
</page>
|
||||||
|
<page name="technical" string="Technical Information">
|
||||||
|
<group name="tech-fields">
|
||||||
|
<field name="unique_import_id" />
|
||||||
|
<field name="partner_name" />
|
||||||
|
<field name="account_number" />
|
||||||
|
<field name="is_reconciled" />
|
||||||
|
</group>
|
||||||
|
<group name="raw_data" string="Raw Data">
|
||||||
|
<field name="raw_data" nolabel="1" />
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
</sheet>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user