Skip to content

Commit

Permalink
Merge pull request #466 from ecosoft-odoo/15.0-fix-budget_control-per…
Browse files Browse the repository at this point in the history
…formance-search

[PERF] budget_control: search carry_forward duplicate
  • Loading branch information
Saran440 authored Oct 8, 2024
2 parents 4205f49 + d4ca1f2 commit 3cf4ce9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions budget_control/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def _do_update_initial_commit(self, reverse=False):
analytic = Analytic.browse(val["analytic_account_id"])
analytic.initial_commit -= val["initial_commit"]
return
forward_duplicate = self.env["budget.commit.forward"].search(
# Use search_count to check for duplicates
forward_duplicate_count = self.env["budget.commit.forward"].search_count(
[
("to_budget_period_id", "=", self.to_budget_period_id.id),
("state", "=", "done"),
Expand All @@ -249,7 +250,7 @@ def _do_update_initial_commit(self, reverse=False):
for val in forward_vals:
analytic = Analytic.browse(val["analytic_account_id"])
# Check first forward commit in the year, it should overwrite initial commit
if not forward_duplicate:
if forward_duplicate_count == 0:
analytic.initial_commit = val["initial_commit"]
else:
analytic.initial_commit += val["initial_commit"]
Expand All @@ -266,6 +267,12 @@ def action_budget_commit_forward(self):
self._do_update_initial_commit()
self._recompute_budget_move()

def _action_cancel(self):
self.filtered(lambda l: l.state == "done")._do_forward_commit(reverse=True)
self.write({"state": "cancel"})
self._do_update_initial_commit(reverse=True)
self._recompute_budget_move()

def action_cancel(self):
"""Do not allow cancel document is past period."""
forwards = self.env["budget.commit.forward"].search([("state", "=", "done")])
Expand All @@ -278,10 +285,7 @@ def action_cancel(self):
raise UserError(
_("Unable to cancel this document as it belongs to a past period.")
)
self.filtered(lambda l: l.state == "done")._do_forward_commit(reverse=True)
self.write({"state": "cancel"})
self._do_update_initial_commit(reverse=True)
self._recompute_budget_move()
self._action_cancel()

def action_draft(self):
self.filtered(lambda l: l.state == "done")._do_forward_commit(reverse=True)
Expand Down

0 comments on commit 3cf4ce9

Please sign in to comment.