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

[17.0][FIX] account_statement_base: impossible to change start/end balance #727

Merged
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
19 changes: 19 additions & 0 deletions account_statement_base/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@
class AccountBankStatement(models.Model):
_inherit = "account.bank.statement"

# TODO: Delete if merged https://github.com/odoo/odoo/pull/182497
def _compute_date_index(self):
"""The super() method does not take into account lines that do not have
internal_index set yet, and causes sorted() to fail, we need to re-define
the method in these cases to avoid the error.
"""
_self = self
for stmt in self:
if any(not line.internal_index for line in stmt.line_ids):
_self -= stmt
sorted_lines = stmt.line_ids.filtered("internal_index").sorted(

Check warning on line 17 in account_statement_base/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_statement_base/models/account_bank_statement.py#L16-L17

Added lines #L16 - L17 were not covered by tests
"internal_index"
)
stmt.first_line_index = sorted_lines[:1].internal_index

Check warning on line 20 in account_statement_base/models/account_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_statement_base/models/account_bank_statement.py#L20

Added line #L20 was not covered by tests
stmt.date = sorted_lines.filtered(lambda line: line.state == "posted")[
-1:
].date
return super(AccountBankStatement, _self)._compute_date_index()

def action_open_statement_lines(self):
self.ensure_one()
if not self:
Expand Down
7 changes: 7 additions & 0 deletions account_statement_base/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
class AccountBankStatementLine(models.Model):
_inherit = "account.bank.statement.line"

# TODO: Delete if merged https://github.com/odoo/odoo/pull/182497
def _compute_running_balance(self):
# We need to set value to all records because super() does not do it using sql.
for item in self:
item.running_balance = item.running_balance
return super()._compute_running_balance()

Check warning on line 15 in account_statement_base/models/account_bank_statement_line.py

View check run for this annotation

Codecov / codecov/patch

account_statement_base/models/account_bank_statement_line.py#L14-L15

Added lines #L14 - L15 were not covered by tests

def action_open_journal_entry(self):
self.ensure_one()
if not self:
Expand Down
Loading