Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_move_budget: add budget smart button in partner form + add multi-company rules #1956

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions account_move_budget/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}
1 change: 1 addition & 0 deletions account_move_budget/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import account_move_budget
from . import account_move_budget_line
from . import res_partner
32 changes: 32 additions & 0 deletions account_move_budget/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions account_move_budget/security/account_move_budget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="ir.rule" id="rule_account_move_budget_company">
<field name="name">Account Move Budget Multi-Company</field>
<field name="model_id" ref="account_move_budget.model_account_move_budget" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>

<record model="ir.rule" id="rule_account_move_budget_line_company">
<field name="name">Account Move Budget Line Multi-Company</field>
<field
name="model_id"
ref="account_move_budget.model_account_move_budget_line"
/>
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
</odoo>
1 change: 0 additions & 1 deletion account_move_budget/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
56 changes: 56 additions & 0 deletions account_move_budget/tests/test_account_move_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions account_move_budget/views/res_partner_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_form_inherit" model="ir.ui.view">
<field name="name">res.partner.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
class="oe_stat_button"
MarinaAForgeFlow marked this conversation as resolved.
Show resolved Hide resolved
name="action_view_budget"
type="object"
groups="account.group_account_user"
icon="fa-usd"
>
<field string="Budgets" name="budget_count" widget="statinfo" />
</button>
</div>
</field>
</record>
</odoo>
Loading