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 committed Aug 2, 2023
1 parent a65ff06 commit 7360326
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(
_("The following problem occurred during import.\n\n %s") % str(e)
)
) from e
return lines, {}

@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:
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 = {
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
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
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"

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 7360326

Please sign in to comment.