Skip to content

Commit

Permalink
[FIX] account_financial_report: Remove inactive analytic account rela…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
sergiobstoj committed Oct 21, 2024
1 parent ac9f16d commit f6053f7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions account_financial_report/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def _compute_analytic_account_ids(self):
)
# Store them
self.analytic_account_ids = False
self._remove_lost_relations(tuple(self.ids))
for account_id, record_ids in batch_by_analytic_account.items():
if account_id not in existing_account_ids:
continue
Expand Down Expand Up @@ -67,3 +68,19 @@ def search_count(self, domain, limit=None):
if self.env.context.get("skip_search_count"):
return 0
return super().search_count(domain, limit=limit)

def _remove_lost_relations(self, account_move_line_ids):
# When some linked analytic account is active=False,
# the relation in account_analytic_account_account_move_line_rel
# is not removed. This method is used to remove the relation in those cases.
inactive_analytic_account_ids = tuple(
self.env["account.analytic.account"].search([("active", "=", False)]).ids
)
if inactive_analytic_account_ids:
self._cr.execute(

Check warning on line 80 in account_financial_report/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/models/account_move_line.py#L80

Added line #L80 was not covered by tests
"DELETE "
"FROM account_analytic_account_account_move_line_rel "
"WHERE account_move_line_id in %s "
"AND account_analytic_account_id in %s",
(account_move_line_ids, inactive_analytic_account_ids),
)

0 comments on commit f6053f7

Please sign in to comment.