diff --git a/mis_builder_budget/models/mis_budget_item.py b/mis_builder_budget/models/mis_budget_item.py index 9a7d63b50..2749742d6 100644 --- a/mis_builder_budget/models/mis_budget_item.py +++ b/mis_builder_budget/models/mis_budget_item.py @@ -19,10 +19,28 @@ class MisBudgetItem(models.Model): ) ) + company_id = fields.Many2one( + comodel_name="res.company", + compute="_compute_company_id", + store=True, + readonly=False, + ) + budget_company_id = fields.Many2one(related="budget_id.company_id") + + @api.depends("budget_id.company_id") + def _compute_company_id(self): + for rec in self: + rec.company_id = rec.budget_id.company_id + def _prepare_overlap_domain(self): """Prepare a domain to check for overlapping budget items.""" domain = super()._prepare_overlap_domain() - domain.extend([("kpi_expression_id", "=", self.kpi_expression_id.id)]) + domain.extend( + [ + ("kpi_expression_id", "=", self.kpi_expression_id.id), + ("company_id", "=", self.company_id.id), + ] + ) return domain @api.constrains( @@ -31,6 +49,7 @@ def _prepare_overlap_domain(self): "date_to", "budget_id", "kpi_expression_id", + "company_id", ) def _check_dates(self): super()._check_dates() diff --git a/mis_builder_budget/models/mis_report_instance_period.py b/mis_builder_budget/models/mis_report_instance_period.py index 333a3a255..3880ff83f 100644 --- a/mis_builder_budget/models/mis_report_instance_period.py +++ b/mis_builder_budget/models/mis_report_instance_period.py @@ -2,6 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.osv.expression import AND SRC_MIS_BUDGET = "mis_budget" SRC_MIS_BUDGET_BY_ACCOUNT = "mis_budget_by_account" @@ -69,4 +70,17 @@ def _get_additional_budget_item_filter(self): compatible with mis.budget.item.""" self.ensure_one() filters = self._get_additional_move_line_filter() + + query_companies = self.report_instance_id.query_company_ids + filters = AND( + [ + filters, + [ + "|", + ("company_id", "in", query_companies.ids), + ("company_id", "=", False), + ], + ] + ) + return filters diff --git a/mis_builder_budget/tests/test_mis_budget.py b/mis_builder_budget/tests/test_mis_budget.py index 87be3331d..cefad4027 100644 --- a/mis_builder_budget/tests/test_mis_budget.py +++ b/mis_builder_budget/tests/test_mis_budget.py @@ -132,6 +132,9 @@ def test_drilldown(self): ("date_to", ">=", datetime.date(2017, 1, 1)), ("kpi_expression_id", "=", self.expr1.id), ("budget_id", "=", self.budget.id), + "|", + ("company_id", "in", [self.env.company.id]), + ("company_id", "=", False), ], ) diff --git a/mis_builder_budget/views/mis_budget_item.xml b/mis_builder_budget/views/mis_budget_item.xml index e694d2a1c..d547593c1 100644 --- a/mis_builder_budget/views/mis_budget_item.xml +++ b/mis_builder_budget/views/mis_budget_item.xml @@ -22,11 +22,16 @@ + +