diff --git a/budget_allocation/models/base_budget_move.py b/budget_allocation/models/base_budget_move.py index 1037077a..a46771b9 100644 --- a/budget_allocation/models/base_budget_move.py +++ b/budget_allocation/models/base_budget_move.py @@ -65,7 +65,8 @@ def _get_query_dict(self, docline): ) ) ) - return self.env.cr.dictfetchall() + dict_data = self.env.cr.dictfetchall() + return dict_data @api.model def check_budget_allocation_limit(self, doclines): diff --git a/budget_control_contract/models/__init__.py b/budget_control_contract/models/__init__.py index acda0285..255b8ef3 100644 --- a/budget_control_contract/models/__init__.py +++ b/budget_control_contract/models/__init__.py @@ -1,6 +1,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import base_budget_move from . import account_budget_move from . import contract_budget_move from . import budget_period diff --git a/budget_control_contract/models/account_move_line.py b/budget_control_contract/models/account_move_line.py index c3ad49c4..01c04b00 100644 --- a/budget_control_contract/models/account_move_line.py +++ b/budget_control_contract/models/account_move_line.py @@ -8,6 +8,7 @@ class AccountMoveLine(models.Model): def uncommit_contract_budget(self): """For vendor bill in valid state, do uncommit for related contract.""" + ForwardLine = self.env["budget.commit.forward.line"] for ml in self: inv_state = ml.move_id.state move_type = ml.move_id.move_type @@ -31,9 +32,31 @@ def uncommit_contract_budget(self): contract_line = contract_line.with_context( return_amount_commit=ml.amount_commit ) + # Check case forward commit, + # it should uncommit with forward commit or old analytic + analytic_account = False + if contract_line.fwd_analytic_account_id: + # Case actual use analytic same as CT Commit, + # it will uncommit with CT analytic + if contract_line.analytic_account_id == ml.analytic_account_id: + analytic_account = contract_line.analytic_account_id + else: + # Case actual commit is use analytic not same as PO Commit + domain_fwd_line = self._get_domain_fwd_line(contract_line) + fwd_lines = ForwardLine.search(domain_fwd_line) + for fwd_line in fwd_lines: + if ( + fwd_line.forward_id.to_budget_period_id.bm_date_from + <= ml.date_commit + <= fwd_line.forward_id.to_budget_period_id.bm_date_to + ): + analytic_account = fwd_line.to_analytic_account_id + break + # Confirm vendor bill, do uncommit budget contract_line.commit_budget( reverse=rev, move_line_id=ml.id, + analytic_account_id=analytic_account, quantity=qty, date=ml.date_commit, ) diff --git a/budget_control_contract/models/base_budget_move.py b/budget_control_contract/models/base_budget_move.py deleted file mode 100644 index 093b70ac..00000000 --- a/budget_control_contract/models/base_budget_move.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2022 Ecosoft Co., Ltd. (http://ecosoft.co.th) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). - -from odoo import models - - -class BudgetDoclineMixin(models.AbstractModel): - _inherit = "budget.docline.mixin" - - def _update_budget_commitment(self, budget_vals, reverse=False): - """Update date is not range in analytic account""" - self.ensure_one() - budget_vals = super()._update_budget_commitment(budget_vals, reverse) - if self._budget_model() == "contract.budget.move": - if ( - self.analytic_account_id.bm_date_from - and budget_vals["date"] <= self.analytic_account_id.bm_date_from - ) or ( - self.analytic_account_id.bm_date_to - and budget_vals["date"] >= self.analytic_account_id.bm_date_to - ): - budget_vals["date"] = self.analytic_account_id.bm_date_from - return budget_vals