-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] budget_management: add module for managing budgets
Add budget_management module for managing budgets. Implemented bulk creation of budgets on monthly and quarter basis. Each budget line is linked to its respective analytic account lines and analytic account. Budget lines have graph, gantt and pivot views for better presentation.
- Loading branch information
Showing
13 changed files
with
342 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from . import models | ||
from . import models, wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from . import budget_budget, budget_lines | ||
from . import budget_budget | ||
from . import budget_line | ||
from . import account_analytic_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class AccountAnalyticLine(models.Model): | ||
_inherit = "account.analytic.line" | ||
|
||
budget_line_id = fields.Many2one(comodel_name="budget.line", string="Budget Line", ondelete="cascade" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from odoo import api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class BudgetLine(models.Model): | ||
_name = "budget.line" | ||
_description = "Budget Lines" | ||
|
||
name = fields.Char("Name") | ||
analytic_account = fields.Many2one("account.analytic.account") | ||
budget_amount = fields.Integer("Budget Amount", required=True) | ||
achieved_amount = fields.Float( | ||
"Achieved Amount", compute="_compute_achieved_amount", store=True | ||
) | ||
budget_id = fields.Many2one("budget.budget") | ||
progress = fields.Float("Achieved (%)", compute="_compute_progress") | ||
account_analytics_line_ids = fields.One2many( | ||
comodel_name="account.analytic.line", inverse_name="budget_line_id" | ||
) | ||
date_from=fields.Date(related='budget_id.date_from') | ||
date_to=fields.Date(related='budget_id.date_to') | ||
user_id=fields.Many2one(related='budget_id.user_id') | ||
|
||
@api.constrains("achieved_amount", "budget_amount", "account_analytics_line_ids") | ||
def _check_restriction_on_creation(self): | ||
for record in self: | ||
if record.budget_id.over_budget == "restriction": | ||
if record.achieved_amount > record.budget_amount: | ||
raise ValidationError( | ||
"Cannot create this analytic line, achieved amount is greater than budget amount" | ||
) | ||
|
||
@api.depends("account_analytics_line_ids.amount",) | ||
def _compute_achieved_amount(self): | ||
for budget_line in self: | ||
budget_line.achieved_amount = abs( | ||
sum(budget_line.account_analytics_line_ids.filtered(lambda l : l.amount<0).mapped("amount")) | ||
) | ||
|
||
@api.depends("achieved_amount", "budget_amount") | ||
def _compute_progress(self): | ||
for record in self: | ||
if record.budget_amount: | ||
record.progress = abs( | ||
(record.achieved_amount / record.budget_amount) * 100 | ||
) | ||
else: | ||
record.progress = 0 | ||
|
||
def action_related_account_analytic_lines(self): | ||
self.ensure_one() | ||
for record in self: | ||
action = record.env["ir.actions.act_window"]._for_xml_id( | ||
"analytic.account_analytic_line_action" | ||
) | ||
action["display_name"] = f"Analytic Lines ({self.analytic_account.name})" | ||
action["domain"] = [("budget_line_id", "=", self.id)] | ||
action["context"] = { | ||
"default_budget_line_id": self.id, | ||
"default_account_id": self.analytic_account.id, | ||
} | ||
return action |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink | ||
access_budget_budget,access_budget_budget,budget_management.model_budget_budget,base.group_user,1,1,1,1 | ||
access_budget_line,access_budget_line,budget_management.model_budget_line,base.group_user,1,1,1,1 | ||
access_budget_line,access_budget_line,budget_management.model_budget_line,base.group_user,1,1,1,1 | ||
access_bulk_budget,access_bulk_budget,budget_management.model_bulk_budget,base.group_user,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.