Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_statement_import_online: add option to enable or disable statement creation. #754

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

company_id = fields.Many2one(related="journal_id.company_id", store=True)
active = fields.Boolean(default=True)
create_statement = fields.Boolean(
default=True,
help="Create statements for the downloaded transactions automatically or not.",
)
name = fields.Char(compute="_compute_name", store=True)
journal_id = fields.Many2one(
comodel_name="account.journal",
Expand Down Expand Up @@ -76,11 +80,12 @@
)
statement_creation_mode = fields.Selection(
selection=[
("daily", "Daily statements"),
("weekly", "Weekly statements"),
("monthly", "Monthly statements"),
("daily", "Day"),
("weekly", "Week"),
("monthly", "Month"),
],
default="daily",
string="Transactions interval to obtain",
required=True,
)
api_base = fields.Char()
Expand Down Expand Up @@ -298,6 +303,8 @@
"""Final creation of statement if new, else write."""
AccountBankStatement = self.env["account.bank.statement"]
is_scheduled = self.env.context.get("scheduled")
if not self.create_statement:
return self._online_create_statement_lines(statement_values)
if is_scheduled:
AccountBankStatement = AccountBankStatement.with_context(
tracking_disable=True,
Expand All @@ -319,6 +326,17 @@
statement.write(statement_values)
return statement

def _online_create_statement_lines(self, statement_values):
AccountBankStatementLine = self.env["account.bank.statement.line"]
carlos-lopez-tecnativa marked this conversation as resolved.
Show resolved Hide resolved
is_scheduled = self.env.context.get("scheduled")
if is_scheduled:
AccountBankStatementLine = AccountBankStatementLine.with_context(

Check warning on line 333 in account_statement_import_online/models/online_bank_statement_provider.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online/models/online_bank_statement_provider.py#L333

Added line #L333 was not covered by tests
tracking_disable=True,
)
lines = [line[2] for line in statement_values.get("line_ids", [])]
AccountBankStatementLine.create(lines)
return self.env["account.bank.statement"] # Return empty statement

def _get_statement_filtered_lines(
self,
unfiltered_lines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,15 @@ def test_dont_create_empty_statements(self):
self.assertEqual(statements[1].balance_end, 200)
self.assertEqual(len(statements[1].line_ids), 1)

def test_dont_create_statement(self):
self.provider.statement_creation_mode = "monthly"
self.provider.create_statement = False
date_since = datetime(2024, 12, 1)
date_until = datetime(2024, 12, 31, 23, 59, 59)
self.provider.with_context(step={"days": 1})._pull(date_since, date_until)
self._getExpectedStatements(0)
self._getExpectedLines(31)

def test_unlink_provider(self):
"""Unlink provider should clear fields on journal."""
self.provider.unlink()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
</group>
<group name="configuration" string="Configuration">
<field name="statement_creation_mode" />
<field name="create_statement" />
<field name="tz" />
</group>
</group>
Expand Down
Loading