Skip to content

Commit

Permalink
[FIX] budget_control_purchase: add precommit check budget function
Browse files Browse the repository at this point in the history
Support for other module can check budget precommit in PO and Actual.
Standard will not check precommit because PO and Actual has next state draft is commit budget.
So, precommit budget is not need.

However, extensnion module like 'base_tier_validation_check_budget' can check budget in state draft.
we will improved base module budget for support precommit check budget
  • Loading branch information
Saran440 committed Aug 2, 2024
1 parent c3f88d1 commit b47fe34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions budget_control_purchase/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def uncommit_purchase_budget(self):
):
inv_state = ml.move_id.state
move_type = ml.move_id.move_type
# Cancel or draft, not commitment line
if inv_state != "posted":
# State Cancel or draft and not context force commit, not commitment line
if not self.env.context.get("force_commit") and inv_state != "posted":
self.env["purchase.budget.move"].search(
[("move_line_id", "=", ml.id)]
).unlink()
Expand Down
14 changes: 14 additions & 0 deletions budget_control_purchase/models/budget_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ def _get_eligible_budget_period(self, date=False, doc_type=False):
or (not l.control_budget and l.purchase)
)
return budget_period

@api.model
def check_budget_precommit(self, doclines, doc_type="account"):
"""This function add for the extension module can
call this function to precommit check budget"""
budget_moves = False
if doc_type == "purchase":
budget_moves = doclines.with_context(
force_commit=True
).uncommit_purchase_request_budget()
res = super().check_budget_precommit(doclines, doc_type=doc_type)
if budget_moves:
budget_moves.unlink()
return res

0 comments on commit b47fe34

Please sign in to comment.