Skip to content

Commit

Permalink
[MIG] budget_control: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Jul 25, 2024
1 parent 0dbca90 commit 6a329d5
Show file tree
Hide file tree
Showing 36 changed files with 646 additions and 575 deletions.
60 changes: 26 additions & 34 deletions budget_control/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Budget Control
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:170b7aa450e2ccdfa27c0d5840cf49a8511a46198988caa073e23f03a6689384
!! source digest: sha256:353c8401879120bf194a5135e6f67838a807a00dc09ec0d8388ce36d90910040
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand All @@ -17,7 +17,7 @@ Budget Control
: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
:target: https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control
:target: https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control
:alt: ecosoft-odoo/budgeting

|badge1| |badge2| |badge3|
Expand All @@ -43,16 +43,11 @@ Budget Control Core Features:
for approved expense.
Note that, in this budget_control module, there is no extension for budget commitment yet.

* **Budget KPI (budget.kpi)**

Budget KPI is used to measure the efficiency of planning compared to actual usage.
It is linked to Account Codes, and one Budget KPI can be associated with more than one account code.

* **Budget Template (budget.template)**

A Budget Template in the budget control system serves as a framework for controlling the budget,
allowing for the budget to be managed according to the pre-defined template.
The budget template has a relationship with the budget kpi and accounting,
The budget template has a relationship with the accounting,
and is used to control spending based on pre-configured accounts.

* **Budget Period (budget.period)**
Expand Down Expand Up @@ -117,11 +112,10 @@ Following are brief explanation of what the extended module will do.

These modules extend base.budget.move for other document budget commitment.

* budget_control_advance_clearing
* budget_control_contract
* budget_control_expense
* budget_control_purchase
* budget_control_purchase_request
* budget_control_sale

**Budget Allocation**

Expand All @@ -130,11 +124,6 @@ until set budget control. and allow create Master Data source of fund, analytic
Users can view source of fund monitoring report

* budget_allocation
* budget_allocation_advance_clearing
* budget_allocation_contract
* budget_allocation_expense
* budget_allocation_purchase
* budget_allocation_purchase_request

**Tier Validation**

Expand All @@ -153,6 +142,10 @@ we can use dimension to create persistent dimension columns
Following modules ensure that, analytic_tag_dimension will work with all new
budget control objects. These are important for reporting purposes.

* budget_allocation
* budget_allocation_expense
* budget_allocation_purchase

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
Expand All @@ -167,15 +160,14 @@ Usage
=====

Before start using this module, following access right must be set.

- Budget User for Budget Control Sheet, Budget Report
- Budget Manager for Budget Period
- Budget User for Budget Control Sheet, Budget Report
- Budget Manager for Budget Period

Followings are sample steps to start with,

1. Create new Budget KPI

- To create budget KPI using in budget template
To create budget KPI using in budget template

2. Create new Budget Template

Expand All @@ -190,29 +182,26 @@ Followings are sample steps to start with,

4. Create Budget Control Sheet

To create budget control sheet, you can create by using the helper,
To create budget control sheet, you can either create manually one by one or by using the helper,
Action > Create Budget Control Sheet

- Choose Analytic Group
- Check All Analytic Accounts, this will list all analytic account in selected groups
- Choose Analytic budget_control_purchase_tag_dimension
- Check All Analytic Account, this will list all analytic account in selected groups
- Uncheck Initial Budget By Commitment, this is used only on following year to
init budget allocation if they were committed amount carried over.
- Click "Generate Budget Control Sheet", and then view the newly created control sheets.
- Click "Create Budget Control Sheet", and then view the newly created control sheets.

5. Allocate amount in Budget Control Sheets

Each analytic account will have its own sheet. Form Budget Period, click on the
icon "Budget Control" or by Menu > Budgeting > Budget Control Sheet, to open them.
icon "Budget Control Sheets" or by Menu > Budgeting > Budget Control Sheet, to open them.

- Within the "Plan Date Range" period, the Plan table displays all KPIs split by Plan Date Range
- If you need to edit the plan, click the "Reset Options" tab, then select the KPIs you want to plan
- Click the "Soft Reset" button to generate KPIs. The amounts in the plan table will not disappear.
- Click the "Hard Reset" button to generate KPIs. The amounts in the plan table will disappear.
- Based on "Plan Date Range" period, Plan table will show all KPI split by Plan Date Range
- Allocate budget amount as appropriate.
- Click Submit > Control, state will change to Controlled.
- Click Control button, state will change to Controlled.

Note: Make sure the Plan Date Rang period already has date ranges that covers entire budget period.
Once ready, you can click on "Soft Reset" or "Hard Reset" anytime.
Once ready, you can click on "Reset Plan" anytime.

6. Budget Reports

Expand All @@ -232,7 +221,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/ecosoft-odoo/budgeting/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/ecosoft-odoo/budgeting/issues/new?body=module:%20budget_control%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -256,11 +245,14 @@ Maintainers
.. |maintainer-kittiu| image:: https://github.com/kittiu.png?size=40px
:target: https://github.com/kittiu
:alt: kittiu
.. |maintainer-ru3ix-bbb| image:: https://github.com/ru3ix-bbb.png?size=40px
:target: https://github.com/ru3ix-bbb
:alt: ru3ix-bbb

Current maintainer:
Current maintainers:

|maintainer-kittiu|
|maintainer-kittiu| |maintainer-ru3ix-bbb|

This module is part of the `ecosoft-odoo/budgeting <https://github.com/ecosoft-odoo/budgeting/tree/15.0/budget_control>`_ project on GitHub.
This module is part of the `ecosoft-odoo/budgeting <https://github.com/ecosoft-odoo/budgeting/tree/16.0/budget_control>`_ project on GitHub.

You are welcome to contribute.
7 changes: 4 additions & 3 deletions budget_control/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Budget Control",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"author": "Ecosoft, Odoo Community Association (OCA)",
Expand All @@ -25,6 +25,7 @@
"wizards/confirm_state_budget_view.xml",
"wizards/budget_commit_forward_info_view.xml",
"wizards/budget_balance_forward_info_view.xml",
"views/account_budget_move.xml",
"views/budget_menuitem.xml",
"views/budget_kpi_view.xml",
"views/budget_template_view.xml",
Expand All @@ -45,12 +46,12 @@
],
"demo": ["demo/budget_template_demo.xml"],
"assets": {
"web.assets_qweb": [
"web.assets_backend": [
"budget_control/static/src/xml/budget_popover.xml",
],
},
"installable": True,
"maintainers": ["kittiu"],
"maintainers": ["kittiu", "ru3ix-bbb"],
"post_init_hook": "update_data_hooks",
"uninstall_hook": "uninstall_hook",
"development_status": "Alpha",
Expand Down
18 changes: 9 additions & 9 deletions budget_control/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ def recompute_budget_move(self):
def close_budget_move(self):
self.mapped("invoice_line_ids").close_budget_move()

Check warning on line 47 in budget_control/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/account_move.py#L47

Added line #L47 was not covered by tests

@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
"""The default value of "Not affect budget" depends on journal.
except in the case of a manaully created journal entry.
"""
not_affect_budget = vals.get("not_affect_budget", "None")
journal_id = vals.get("journal_id")
if not_affect_budget == "None" and journal_id:
journal = self.env["account.journal"].browse(journal_id)
vals["not_affect_budget"] = journal.not_affect_budget
return super().create(vals)
for vals in vals_list:
if "not_affect_budget" not in vals and "journal_id" in vals:
journal = self.env["account.journal"].browse(vals["journal_id"])
vals["not_affect_budget"] = journal.not_affect_budget

Check warning on line 57 in budget_control/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/account_move.py#L56-L57

Added lines #L56 - L57 were not covered by tests
return super().create(vals_list)

def write(self, vals):
"""
Expand Down Expand Up @@ -87,7 +86,8 @@ def _filtered_move_check_budget(self):

def action_post(self):
res = super().action_post()
self.flush()
# Update database, then check budget
self.flush_model()
BudgetPeriod = self.env["budget.period"]
for move in self._filtered_move_check_budget():
BudgetPeriod.check_budget(move.line_ids)
Expand Down
13 changes: 6 additions & 7 deletions budget_control/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,24 @@ def recompute_budget_move(self):
# Commit on invoice
invoice_line.commit_budget()

def _init_docline_budget_vals(self, budget_vals):
def _init_docline_budget_vals(self, budget_vals, analytic_id):
self.ensure_one()
if self.move_id.move_type == "entry":
budget_vals["amount_currency"] = self.amount_currency
total_amount = self.amount_currency

Check warning on line 42 in budget_control/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/account_move_line.py#L42

Added line #L42 was not covered by tests
else:
sign = -1 if self.move_id.move_type in ("out_refund", "in_refund") else 1
discount = (100 - self.discount) / 100 if self.discount else 1
budget_vals["amount_currency"] = (
sign * self.price_unit * self.quantity * discount
)
total_amount = sign * self.price_unit * self.quantity * discount
percent_analytic = self[self._budget_analytic_field].get(str(analytic_id))
budget_vals["amount_currency"] = total_amount * percent_analytic / 100
budget_vals["tax_ids"] = self.tax_ids.ids
# Document specific vals
budget_vals.update(
{
"move_line_id": self.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
}
)
return super()._init_docline_budget_vals(budget_vals)
return super()._init_docline_budget_vals(budget_vals, analytic_id)

def _valid_commit_state(self):
return self.move_id.state == "posted"
Expand Down
27 changes: 19 additions & 8 deletions budget_control/models/analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,28 @@ def _find_next_analytic(self, next_date_range):

def _update_val_analytic(self, next_analytic, next_date_range):
BudgetPeriod = self.env["budget.period"]
vals_update = {}
type_id = next_analytic.budget_period_id.plan_date_range_type_id
period_id = BudgetPeriod.search(

Check warning on line 171 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L168-L171

Added lines #L168 - L171 were not covered by tests
[
("bm_date_from", "=", next_date_range),
("plan_date_range_type_id", "=", type_id.id),
]
)
return {"budget_period_id": period_id.id}
if period_id:
vals_update = {"budget_period_id": period_id.id}

Check warning on line 178 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L178

Added line #L178 was not covered by tests
else:
# No budget period found, update date_from and date_to
vals_update = {

Check warning on line 181 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L181

Added line #L181 was not covered by tests
"bm_date_from": next_date_range,
"bm_date_to": next_analytic.bm_date_to + relativedelta(years=1),
}
return vals_update

Check warning on line 185 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L185

Added line #L185 was not covered by tests

def _auto_create_next_analytic(self, next_date_range):
self.ensure_one()

Check warning on line 188 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L188

Added line #L188 was not covered by tests
next_analytic = self.copy()
# Core odoo will add (copy) after name, but we need same name
next_analytic = self.copy(default={"name": self.name})
val_update = self._update_val_analytic(next_analytic, next_date_range)
next_analytic.write(val_update)
return next_analytic

Check warning on line 193 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L190-L193

Added lines #L190 - L193 were not covered by tests
Expand Down Expand Up @@ -230,12 +240,13 @@ def _compute_bm_date(self):
rec.bm_date_to = rec.budget_period_id.bm_date_to

def _auto_adjust_date_commit(self, docline):
self.ensure_one()
if self.auto_adjust_date_commit:
if self.bm_date_from and self.bm_date_from > docline.date_commit:
docline.date_commit = self.bm_date_from
elif self.bm_date_to and self.bm_date_to < docline.date_commit:
docline.date_commit = self.bm_date_to
for rec in self:
if not rec.auto_adjust_date_commit:
continue

Check warning on line 245 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L245

Added line #L245 was not covered by tests
if rec.bm_date_from and rec.bm_date_from > docline.date_commit:
docline.date_commit = rec.bm_date_from

Check warning on line 247 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L247

Added line #L247 was not covered by tests
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 {

Check warning on line 252 in budget_control/models/analytic_account.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/analytic_account.py#L252

Added line #L252 was not covered by tests
Expand Down
Loading

0 comments on commit 6a329d5

Please sign in to comment.