Skip to content

Commit

Permalink
[IMP] mis_builder_budget: allow to specify a company on budget by kpi
Browse files Browse the repository at this point in the history
  • Loading branch information
AnizR committed Aug 28, 2024
1 parent 3aa42b4 commit 4d87e96
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
21 changes: 20 additions & 1 deletion mis_builder_budget/models/mis_budget_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions mis_builder_budget/models/mis_report_instance_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions mis_builder_budget/tests/test_mis_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
)

Expand Down
5 changes: 5 additions & 0 deletions mis_builder_budget/views/mis_budget_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
<field name="report_id" invisible="1" />
<field name="budget_date_from" invisible="1" />
<field name="budget_date_to" invisible="1" />
<field name="budget_company_id" invisible="1" />
<field name="kpi_expression_id" />
<field name="date_range_id" />
<field name="date_from" />
<field name="date_to" />
<field name="amount" />
<field
name="company_id"
attrs="{'readonly':[('budget_company_id','!=',False)]}"
/>
</tree>
</field>
</record>
Expand Down

0 comments on commit 4d87e96

Please sign in to comment.