-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] accounbt_bank_statement_import_file_hook
- Loading branch information
1 parent
1fa1500
commit 42bc964
Showing
9 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from .hooks import post_load_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 ForgeFlow, S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
{ | ||
"name": "Account Bank Statement Import File Hook", | ||
"version": "13.0.1.0.0", | ||
# see https://odoo-community.org/page/development-status | ||
"development_status": "Production/Stable", | ||
"category": "Invoicing Management", | ||
"website": "https://github.com/OCA/bank-statement-import", | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"license": "LGPL-3", | ||
"depends": ["account_bank_statement_import"], | ||
"post_load": "post_load_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2023 ForgeFlow, S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
import base64 | ||
|
||
from odoo import _ | ||
from odoo.exceptions import UserError | ||
|
||
from odoo.addons.account_bank_statement_import.account_bank_statement_import import ( | ||
AccountBankStatementImport, | ||
) | ||
|
||
|
||
def post_load_hook(): | ||
def import_file_new(self): | ||
""" Process the file chosen in the wizard, create bank | ||
statement(s) and go to reconciliation. """ | ||
if not hasattr(self, "_post_process_statements"): | ||
return self.import_file_original() | ||
self.ensure_one() | ||
statement_line_ids_all = [] | ||
notifications_all = [] | ||
# Let the appropriate implementation module parse the file and | ||
# return the required data | ||
# The active_id is passed in context in case an implementation | ||
# module requires information about the wizard state (see QIF) | ||
for data_file in self.attachment_ids: | ||
currency_code, account_number, stmts_vals = self.with_context( | ||
active_id=self.ids[0] | ||
)._parse_file(base64.b64decode(data_file.datas)) | ||
# Check raw data | ||
self._check_parsed_data(stmts_vals, account_number) | ||
# Try to find the currency and journal in odoo | ||
currency, journal = self._find_additional_data( | ||
currency_code, account_number | ||
) | ||
# If no journal found, ask the user about creating one | ||
if not journal: | ||
# The active_id is passed in context so the wizard can call | ||
# import_file again once the journal is created | ||
return self.with_context( | ||
active_id=self.ids[0] | ||
)._journal_creation_wizard(currency, account_number) | ||
if ( | ||
not journal.default_debit_account_id | ||
or not journal.default_credit_account_id | ||
): | ||
raise UserError( | ||
_( | ||
"You have to set a Default Debit Account and a Default " | ||
"Credit Account for the journal: %s" | ||
) | ||
% (journal.name,) | ||
) | ||
# Prepare statement data to be used for bank statements creation | ||
stmts_vals = self._complete_stmts_vals(stmts_vals, journal, account_number) | ||
# Create the bank statements | ||
statement_line_ids, notifications = self._create_bank_statements(stmts_vals) | ||
statement_line_ids_all.extend(statement_line_ids) | ||
notifications_all.extend(notifications) | ||
# START HOOK | ||
# Link attachment in bank statement chatter | ||
self._post_process_statements(data_file, statement_line_ids_all) | ||
# END HOOK | ||
# Now that the import worked out, set it as the bank_statements_source | ||
# of the journal | ||
if journal.bank_statements_source != "file_import": | ||
# Use sudo() because only 'account.group_account_manager' | ||
# has write access on 'account.journal', but 'account.group_account_user' | ||
# must be able to import bank statement files | ||
journal.sudo().bank_statements_source = "file_import" | ||
# Finally dispatch to reconciliation interface | ||
return { | ||
"type": "ir.actions.client", | ||
"tag": "bank_statement_reconciliation_view", | ||
"context": { | ||
"statement_line_ids": statement_line_ids_all, | ||
"company_ids": self.env.user.company_ids.ids, | ||
"notifications": notifications_all, | ||
}, | ||
} | ||
|
||
if not hasattr(AccountBankStatementImport, "import_file_original"): | ||
AccountBankStatementImport.import_file_original = ( | ||
AccountBankStatementImport.import_file | ||
) | ||
AccountBankStatementImport.import_file = import_file_new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_bank_statement_import |
12 changes: 12 additions & 0 deletions
12
account_bank_statement_import_file_hook/models/account_bank_statement_import.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 ForgeFlow, S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class AccountBankStatementImport(models.TransientModel): | ||
_inherit = "account.bank.statement.import" | ||
|
||
def _post_process_statements(self, data_file, statement_line_ids): | ||
"""To be inherited""" | ||
return False |
2 changes: 2 additions & 0 deletions
2
account_bank_statement_import_file_hook/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Jaume Bernaus <jaume.bernaus@forgeflow.com> | ||
* Jordi Ballester <jordi.ballester@forgeflow.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Module to add a hook to the import_file method of bank statement import. |
1 change: 1 addition & 0 deletions
1
...count_bank_statement_import_file_hook/odoo/addons/account_bank_statement_import_file_hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_bank_statement_import_file_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |