From 7360326c78ca1ccf1ff39513b171cfdfb176eaa6 Mon Sep 17 00:00:00 2001 From: PauBForgeFlow Date: Wed, 2 Aug 2023 10:29:59 +0200 Subject: [PATCH] [MIG] account_statement_import_online: Migration to 16.0 --- .../__manifest__.py | 4 +- .../online_bank_statement_provider_ofx.py | 37 ++++++++++++------- .../readme/CONFIGURE.rst | 16 ++++---- ...est_account_statement_import_online_ofx.py | 16 +++----- .../online_bank_statement_pull_wizard.py | 16 ++++---- .../online_bank_statement_pull_wizard.xml | 2 +- 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/account_statement_import_online_ofx/__manifest__.py b/account_statement_import_online_ofx/__manifest__.py index b81154df1b..de2cba619a 100644 --- a/account_statement_import_online_ofx/__manifest__.py +++ b/account_statement_import_online_ofx/__manifest__.py @@ -3,13 +3,13 @@ { "name": "Online Bank Statements: OFX", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "author": "ForgeFlow, Odoo Community Association (OCA)", "website": "https://github.com/OCA/bank-statement-import", "license": "AGPL-3", "category": "Accounting", "summary": "Online bank statements for OFX", - "depends": ["account_statement_import_online"], + "depends": ["account_statement_import_online", "hr"], "external_dependencies": {"python": ["ofxtools", "ofxparse"]}, "data": [ "security/ir.model.access.csv", diff --git a/account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py b/account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py index 0c5d7ea6e6..5be103dc93 100644 --- a/account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py +++ b/account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py @@ -97,7 +97,7 @@ def _obtain_statement_data(self, date_since, date_until): except Exception as e: raise UserError( _("The following problem occurred during import.\n\n %s") % str(e) - ) + ) from e return lines, {} @api.model @@ -118,14 +118,17 @@ def _prepare_ofx_transaction_line(self, transaction): def import_ofx_institutions(self): OfxInstitution = self.env["ofx.institution"] try: - with requests.get("http://www.ofxhome.com/api.php?all=yes") as f: + with requests.get( + "http://www.ofxhome.com/api.php?all=yes", timeout=30 + ) as f: response = f.text institute_list = { fi.get("id").strip(): fi.get("name").strip() for fi in ET.fromstring(response) } except Exception as e: - raise UserError(_(e)) + raise UserError(_(e)) from e + for ofxhome_id, name in institute_list.items(): institute = OfxInstitution.search([("ofxhome_id", "=", ofxhome_id)]) vals = { @@ -145,19 +148,27 @@ def _create_or_update_statement( data, statement_date_since, statement_date_until ) if self.service == "OFX": - AccountBankStatement = self.env["account.bank.statement"] - statement_date = self._get_statement_date( + unfiltered_lines, statement_values = data + if not unfiltered_lines: + unfiltered_lines = [] + if not statement_values: + statement_values = {} + statement_values["name"] = self.make_statement_name(statement_date_since) + filtered_lines = self._get_statement_filtered_lines( + unfiltered_lines, + statement_values, statement_date_since, statement_date_until, ) - statement = AccountBankStatement.search( - [ - ("journal_id", "=", self.journal_id.id), - ("state", "=", "open"), - ("date", "=", statement_date), - ], - limit=1, - ) + if not filtered_lines: + return + if filtered_lines: + statement_values.update( + {"line_ids": [[0, False, line] for line in filtered_lines]} + ) + self._update_statement_balances(statement_values) + statement = self._statement_create_or_write(statement_values) + self._journal_set_statement_source() if not statement.line_ids: statement.unlink() return res diff --git a/account_statement_import_online_ofx/readme/CONFIGURE.rst b/account_statement_import_online_ofx/readme/CONFIGURE.rst index d5439af21e..562e6f2219 100644 --- a/account_statement_import_online_ofx/readme/CONFIGURE.rst +++ b/account_statement_import_online_ofx/readme/CONFIGURE.rst @@ -1,9 +1,11 @@ To configure online bank statements provider: -#. Go to *Invoicing > Configuration > Journals* -#. Open bank journal to configure and edit it -#. Set *Bank Feeds* to *Online* -#. Select *OFX* as online bank statements provider in - *Online Bank Statements (OCA)* section -#. Save the bank journal -#. Click on provider and configure provider-specific settings. +#. Go to *Invoicing > Configuration > Online Bank Statement Providers* +#. Create a provider and configure provider-specific settings. + +If you want to allow empty bank statements to be created every time the +information is pulled, you can check the option "Allow empty statements" +at the provider configuration level. + +**NOTE**: To access these features, user needs to belong to +*Show Full Accounting Features* group. diff --git a/account_statement_import_online_ofx/tests/test_account_statement_import_online_ofx.py b/account_statement_import_online_ofx/tests/test_account_statement_import_online_ofx.py index 655a647331..c0c2dcf52e 100644 --- a/account_statement_import_online_ofx/tests/test_account_statement_import_online_ofx.py +++ b/account_statement_import_online_ofx/tests/test_account_statement_import_online_ofx.py @@ -34,17 +34,11 @@ def setUp(self): ) def test_import_online_ofx(self): - # Create bank journal - journal = self.AccountJournal.create( - { - "name": "Bank", - "type": "bank", - "code": "BANK", - "bank_statements_source": "online", - "online_bank_statement_provider": "OFX", - } - ) - provider = journal.online_bank_statement_provider_id + + provider_model = self.env["online.bank.statement.provider"] + active_id = self.env.context.get("active_id") + provider = provider_model.browse(active_id) + # Create OFX institution line in OFX provider self.OfxInstitutionLine.create( { diff --git a/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py b/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py index 3d0b8a1899..af85425ebb 100644 --- a/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py +++ b/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py @@ -13,18 +13,16 @@ class OnlineBankStatementPullWizard(models.TransientModel): column1="wizard_id", column2="institution_line_id", relation="ofx_institution_line_pull_wizard_rel", - domain="[('provider_id','in',provider_ids)]", ) + is_ofx_provider = fields.Boolean() - @api.onchange("provider_ids") - def onchange_provider_ids(self): - for rec in self: - rec.is_ofx_provider = False - for provider in rec.provider_ids: - if provider.service == "OFX": - rec.is_ofx_provider = True - break + @api.onchange("date_since") + def _compute_is_ofx_provider(self): + provider_model = self.env["online.bank.statement.provider"] + active_id = self.env.context.get("active_id") + provider = provider_model.browse(active_id) + self.is_ofx_provider = provider.service == "OFX" def action_pull(self): return super( diff --git a/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.xml b/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.xml index ade08671fe..45a5483a90 100644 --- a/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.xml +++ b/account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.xml @@ -8,7 +8,7 @@ ref="account_statement_import_online.online_bank_statement_pull_wizard_form" /> - +