diff --git a/account_move_budget/__manifest__.py b/account_move_budget/__manifest__.py
index 4a53be3bd05..115e62359b6 100644
--- a/account_move_budget/__manifest__.py
+++ b/account_move_budget/__manifest__.py
@@ -14,7 +14,9 @@
"depends": ["account", "date_range"],
"data": [
"security/ir.model.access.csv",
+ "security/account_move_budget.xml",
"views/account_move_budget_line_views.xml",
"views/account_move_budget_views.xml",
+ "views/res_partner_view.xml",
],
}
diff --git a/account_move_budget/models/__init__.py b/account_move_budget/models/__init__.py
index 0a26d5031c9..64aff521e96 100644
--- a/account_move_budget/models/__init__.py
+++ b/account_move_budget/models/__init__.py
@@ -1,2 +1,3 @@
from . import account_move_budget
from . import account_move_budget_line
+from . import res_partner
diff --git a/account_move_budget/models/res_partner.py b/account_move_budget/models/res_partner.py
new file mode 100644
index 00000000000..60a04df2e89
--- /dev/null
+++ b/account_move_budget/models/res_partner.py
@@ -0,0 +1,32 @@
+# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import fields, models
+
+
+class Partner(models.Model):
+ _inherit = "res.partner"
+
+ budget_count = fields.Integer(
+ "# Budgets", compute="_compute_budget_count", compute_sudo=False
+ )
+
+ def _get_budget_ids(self):
+ self.ensure_one()
+ budget_lines = self.env["account.move.budget.line"].search(
+ [("partner_id", "=", self.id)]
+ )
+ return budget_lines.mapped("budget_id.id")
+
+ def _compute_budget_count(self):
+ for partner in self:
+ partner.budget_count = len(partner._get_budget_ids())
+
+ def action_view_budget(self):
+ self.ensure_one()
+ budget_ids = self._get_budget_ids()
+ action = self.env["ir.actions.actions"]._for_xml_id(
+ "account_move_budget.account_move_budget_act_window"
+ )
+ action["domain"] = [("id", "in", budget_ids)]
+ return action
diff --git a/account_move_budget/security/account_move_budget.xml b/account_move_budget/security/account_move_budget.xml
new file mode 100644
index 00000000000..b35c8987c42
--- /dev/null
+++ b/account_move_budget/security/account_move_budget.xml
@@ -0,0 +1,21 @@
+
+
+
+ Account Move Budget Multi-Company
+
+ ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
+
+
+
+ Account Move Budget Line Multi-Company
+
+ ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]
+
+
diff --git a/account_move_budget/static/description/index.html b/account_move_budget/static/description/index.html
index 8ad9aea52ae..26e246f3947 100644
--- a/account_move_budget/static/description/index.html
+++ b/account_move_budget/static/description/index.html
@@ -1,4 +1,3 @@
-
diff --git a/account_move_budget/tests/test_account_move_budget.py b/account_move_budget/tests/test_account_move_budget.py
index 74b86615973..545529d0740 100644
--- a/account_move_budget/tests/test_account_move_budget.py
+++ b/account_move_budget/tests/test_account_move_budget.py
@@ -56,6 +56,46 @@ def setUpClass(cls):
}
)
+ cls.partner = cls.env["res.partner"].create(
+ {"name": "Test Partner", "company_id": cls.env.company.id}
+ )
+
+ cls.budget1 = cls.env["account.move.budget"].create(
+ {
+ "name": "Budget 1",
+ "company_id": cls.env.company.id,
+ "date_from": "2023-01-01",
+ "date_to": "2023-12-31",
+ }
+ )
+ cls.budget2 = cls.env["account.move.budget"].create(
+ {
+ "name": "Budget 2",
+ "company_id": False,
+ "date_from": "2024-01-01",
+ "date_to": "2024-12-31",
+ }
+ )
+
+ cls.budget_line1 = cls.env["account.move.budget.line"].create(
+ {
+ "partner_id": cls.partner.id,
+ "company_id": cls.env.company.id,
+ "budget_id": cls.budget1.id,
+ "date": "2023-01-01",
+ "account_id": cls.account.id,
+ }
+ )
+ cls.budget_line2 = cls.env["account.move.budget.line"].create(
+ {
+ "partner_id": cls.partner.id,
+ "company_id": False,
+ "budget_id": cls.budget2.id,
+ "date": "2024-01-01",
+ "account_id": cls.account.id,
+ }
+ )
+
def test_01_create_account_move_budget(self):
move_form = Form(self.env["account.move.budget"])
move_form.name = "Budget Test 01"
@@ -137,3 +177,19 @@ def test_06_raise_account_move_budget(self):
move_line_form.account_id = self.account
with self.assertRaises(ValidationError):
move_line_form.save()
+
+ def test_07_compute_budget_info(self):
+ self.partner._compute_budget_count()
+ self.assertEqual(self.partner.budget_count, 2)
+
+ budget_ids = self.partner._get_budget_ids()
+ expected_ids = {self.budget1.id, self.budget2.id}
+ self.assertEqual(set(budget_ids), expected_ids)
+
+ def test_08_action_view_budget(self):
+ action = self.partner.action_view_budget()
+
+ budget_ids = self.partner._get_budget_ids()
+ expected_domain = [("id", "in", budget_ids)]
+
+ self.assertEqual(action["domain"], expected_domain)
diff --git a/account_move_budget/views/res_partner_view.xml b/account_move_budget/views/res_partner_view.xml
new file mode 100644
index 00000000000..c5c35b5ca0f
--- /dev/null
+++ b/account_move_budget/views/res_partner_view.xml
@@ -0,0 +1,21 @@
+
+
+
+ res.partner.form.inherit
+ res.partner
+
+
+
+
+
+
+
+