Skip to content

Commit

Permalink
[FIX] check budget precommit with actual
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Apr 25, 2024
1 parent c2474f1 commit bb7ab27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
9 changes: 8 additions & 1 deletion base_tier_validation_check_budget/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ def validate_tier(self):
lines = getattr(self, "_docline_rel", None)
line_type = getattr(self, "_docline_type", None)
if self.check_budget and lines and line_type:
doclines = self[lines].sudo()
# Special case advance clearing
if getattr(self, "advance", False):
line_type = "advance"
# --
if self._name == "account.move" and self.move_type in (
"in_invoice",
"in_refund",
):
doclines = self["invoice_line_ids"].sudo()
self.env["budget.period"].check_budget_precommit(
self[lines].sudo(), doc_type=line_type
doclines, doc_type=line_type
)
return super().validate_tier()
4 changes: 4 additions & 0 deletions budget_control/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ def _get_included_tax(self):
if self._name == "account.move.line":
return self.env.company.budget_include_tax_account
return self.env["account.tax"]

def uncommit_purchase_budget(self):
"""This function for hooks"""
return
8 changes: 8 additions & 0 deletions budget_control/models/budget_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ def check_budget_precommit(self, doclines, doc_type="account"):
if not doclines:
return
doclines = doclines.sudo()
# Allow precommit budget with related origin document (PO)
if doc_type == "account":
budget_moves_uncommit = doclines.with_context(
force_commit=True
).uncommit_purchase_budget()
# Commit budget
budget_moves = []
vals_date_commit = []
Expand All @@ -231,6 +236,9 @@ def check_budget_precommit(self, doclines, doc_type="account"):
doclines.filtered(lambda l: l.id in vals_date_commit).write(
{"date_commit": False}
)
# Remove uncommit budget
if budget_moves_uncommit:
budget_moves_uncommit.unlink()

@api.model
def check_over_returned_budget(self, docline, reverse=False):
Expand Down
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

0 comments on commit bb7ab27

Please sign in to comment.