From b47fe34c9907f71ac159a862bed8313f394527e8 Mon Sep 17 00:00:00 2001 From: Saran440 Date: Thu, 25 Apr 2024 14:49:27 +0700 Subject: [PATCH] [FIX] budget_control_purchase: add precommit check budget function 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 --- .../models/account_move_line.py | 4 ++-- budget_control_purchase/models/budget_period.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/budget_control_purchase/models/account_move_line.py b/budget_control_purchase/models/account_move_line.py index 81ce3084..e9cc7839 100644 --- a/budget_control_purchase/models/account_move_line.py +++ b/budget_control_purchase/models/account_move_line.py @@ -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() diff --git a/budget_control_purchase/models/budget_period.py b/budget_control_purchase/models/budget_period.py index ff710114..97ba7800 100644 --- a/budget_control_purchase/models/budget_period.py +++ b/budget_control_purchase/models/budget_period.py @@ -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