Skip to content
Merged
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
5 changes: 5 additions & 0 deletions budget_activity/report/budget_monitor_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class BudgetMonitorReport(models.Model):

activity = fields.Char()

def _select_forward_balance_extra(self):
select = super()._select_forward_balance_extra()
select[20] = "null::char as activity"
return select

# Budget
def _select_budget(self):
select_budget_query = super()._select_budget()
Expand Down
6 changes: 1 addition & 5 deletions budget_control/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==============
Budget Control
==============
Expand All @@ -17,7 +13,7 @@ Budget Control
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-ecosoft--odoo%2Fbudgeting-lightgray.png?logo=github
Expand Down
1 change: 0 additions & 1 deletion budget_control/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"data/budget_data.xml",
"data/sequence_data.xml",
# Wizards
"wizards/analytic_budget_edit_view.xml",
"wizards/analytic_budget_info_view.xml",
"wizards/confirm_state_budget_view.xml",
"wizards/budget_commit_forward_info_view.xml",
Expand Down
61 changes: 35 additions & 26 deletions budget_control/models/analytic_account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2021 Ecosoft Co., Ltd. (http://ecosoft.co.th)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from collections import defaultdict

from dateutil.relativedelta import relativedelta

from odoo import api, fields, models
Expand Down Expand Up @@ -59,6 +61,16 @@ class AccountAnalyticAccount(models.Model):
compute="_compute_amount_budget_info",
help="Sum of amount plan",
)
amount_forward_in = fields.Monetary(
string="Forward In",
compute="_compute_amount_budget_info",
help="Available budget carried in from another budget period.",
)
amount_forward_out = fields.Monetary(
string="Forward Out",
compute="_compute_amount_budget_info",
help="Available budget carried out, shown as a positive amount.",
)
amount_consumed = fields.Monetary(
string="Consumed",
compute="_compute_amount_budget_info",
Expand All @@ -67,13 +79,7 @@ class AccountAnalyticAccount(models.Model):
amount_balance = fields.Monetary(
string="Available",
compute="_compute_amount_budget_info",
help="Available = Total Budget - Consumed",
)
initial_available = fields.Monetary(
copy=False,
readonly=True,
tracking=True,
help="Initial Balance come from carry forward available accumulated",
help="Available = Total Budget - Forward Out - Consumed",
)
initial_commit = fields.Monetary(
string="Initial Commitment",
Expand Down Expand Up @@ -182,23 +188,36 @@ def _compute_amount_budget_info(self):
admin_uid = self.env.ref("base.user_admin").id
dataset_all = MonitorReport.with_user(admin_uid).read_group(
domain=domain,
fields=["analytic_account_id", "amount_type", "amount"],
fields=[
"analytic_account_id",
"amount_type",
"amount",
],
groupby=["analytic_account_id", "amount_type"],
lazy=False,
)
dataset_map = defaultdict(list)
for data in dataset_all:
dataset_map[data["analytic_account_id"][0]].append(data)
forward_map = self.env["budget.balance.forward.line"]._get_forward_balance_map(
ctx.get("budget_period_ids", []), analytic_ids
)
forward_totals = defaultdict(float)
for (_period_id, analytic_id), amount in forward_map.items():
forward_totals[analytic_id] += amount
for rec in self:
# Filter according to budget_control parameter
dataset = list(
filter(
lambda dataset: rec._filter_by_analytic_account(dataset),
dataset_all,
)
)
# Get data from dataset
dataset = [
data
for data in dataset_map[rec.id]
if rec._filter_by_analytic_account(data)
]
budget_info = BudgetPeriod.get_budget_info_from_dataset(query, dataset)
rec.amount_budget = budget_info["amount_budget"]
rec.amount_forward_in = forward_totals[rec.id]
rec.amount_forward_out = budget_info["amount_forward_out"]
rec.amount_consumed = budget_info["amount_consumed"]
rec.amount_balance = rec.amount_budget - rec.amount_consumed
rec.amount_balance = budget_info["amount_balance"]

def _find_next_analytic(self, next_date_range):
self.ensure_one()
Expand Down Expand Up @@ -308,13 +327,3 @@ def _auto_adjust_date_commit(self, docline):
docline.date_commit = rec.bm_date_from
elif rec.bm_date_to and rec.bm_date_to < docline.date_commit:
docline.date_commit = rec.bm_date_to

def action_edit_initial_available(self):
return {
"name": self.env._("Edit Analytic Budget"),
"type": "ir.actions.act_window",
"res_model": "analytic.budget.edit",
"view_mode": "form",
"target": "new",
"context": {"default_initial_available": self.initial_available},
}
Loading
Loading