Skip to content

Commit

Permalink
[MIG] account_statement_import_online: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PauBForgeFlow authored and ChrisOForgeFlow committed Oct 31, 2023
1 parent 1b6a178 commit 39aef0a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 43 deletions.
4 changes: 2 additions & 2 deletions account_statement_import_online_ofx/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _obtain_statement_data(self, date_since, date_until):
except Exception as e:
raise UserError(

Check warning on line 98 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L96-L98

Added lines #L96 - L98 were not covered by tests
_("The following problem occurred during import.\n\n %s") % str(e)
)
) from e
return lines, {}

Check warning on line 101 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L101

Added line #L101 was not covered by tests

@api.model
Expand All @@ -118,14 +118,17 @@ def _prepare_ofx_transaction_line(self, transaction):
def import_ofx_institutions(self):
OfxInstitution = self.env["ofx.institution"]
try:

Check warning on line 120 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L119-L120

Added lines #L119 - L120 were not covered by tests
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

Check warning on line 124 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L124

Added line #L124 was not covered by tests
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

Check warning on line 130 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L129-L130

Added lines #L129 - L130 were not covered by tests

for ofxhome_id, name in institute_list.items():
institute = OfxInstitution.search([("ofxhome_id", "=", ofxhome_id)])
vals = {

Check warning on line 134 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L133-L134

Added lines #L133 - L134 were not covered by tests
Expand All @@ -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

Check warning on line 151 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L151

Added line #L151 was not covered by tests
if not unfiltered_lines:
unfiltered_lines = []

Check warning on line 153 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L153

Added line #L153 was not covered by tests
if not statement_values:
statement_values = {}
statement_values["name"] = self.make_statement_name(statement_date_since)
filtered_lines = self._get_statement_filtered_lines(

Check warning on line 157 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L155-L157

Added lines #L155 - L157 were not covered by tests
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

Check warning on line 164 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L164

Added line #L164 was not covered by tests
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()

Check warning on line 171 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L169-L171

Added lines #L169 - L171 were not covered by tests
if not statement.line_ids:
statement.unlink()

Check warning on line 173 in account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/models/online_bank_statement_provider_ofx.py#L173

Added line #L173 was not covered by tests
return res
Expand Down
16 changes: 9 additions & 7 deletions account_statement_import_online_ofx/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 25 in account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_ofx/wizards/online_bank_statement_pull_wizard.py#L22-L25

Added lines #L22 - L25 were not covered by tests

def action_pull(self):
return super(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ref="account_statement_import_online.online_bank_statement_pull_wizard_form"
/>
<field name="arch" type="xml">
<field name="provider_ids" position="after">
<field name="date_since" position="before">
<field name="is_ofx_provider" invisible="1" />
<field
name="ofx_institution_ids"
Expand Down

0 comments on commit 39aef0a

Please sign in to comment.