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][ENH] budget_control_*: decimal digit, extend analytic and rounding #457

Merged
merged 5 commits into from
Sep 24, 2024
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
1 change: 1 addition & 0 deletions budget_control/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"web_widget_x2many_2d_matrix",
],
"data": [
"data/budget_data.xml",
"data/sequence_data.xml",
"security/budget_control_security_groups.xml",
"security/budget_control_rules.xml",
Expand Down
7 changes: 7 additions & 0 deletions budget_control/data/budget_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="decimal_budget_precision" model="decimal.precision" forcecreate="True">
<field name="name">Budget Precision</field>
<field name="digits">2</field>
</record>
</odoo>
3 changes: 3 additions & 0 deletions budget_control/models/base_budget_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ class BaseBudgetMove(models.AbstractModel):
)
amount_currency = fields.Float(
required=True,
digits="Budget Precision",
help="Amount in multi currency",
)
credit = fields.Float(
readonly=True,
digits="Budget Precision",
)
debit = fields.Float(
readonly=True,
digits="Budget Precision",
)
company_id = fields.Many2one(
comodel_name="res.company",
Expand Down
31 changes: 20 additions & 11 deletions budget_control/models/budget_commit_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,16 @@
# For case extend
for line in rec.forward_line_ids:
if not reverse and line.method_type == "extend":
line.to_analytic_account_id.bm_date_to = (
rec.to_budget_period_id.bm_date_to
)
# Update end date of analytic account,
# if it is extended by max date.
if line.to_analytic_account_id.bm_date_to:
date_to = max(

Check warning on line 258 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L258

Added line #L258 was not covered by tests
line.to_analytic_account_id.bm_date_to,
rec.to_budget_period_id.bm_date_to,
)
else:
date_to = rec.to_budget_period_id.bm_date_to
line.to_analytic_account_id.bm_date_to = date_to

Check warning on line 264 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L263-L264

Added lines #L263 - L264 were not covered by tests

def _do_update_initial_commit(self, reverse=False):
"""Update all Analytic Account's initial commit value related to budget period"""
Expand Down Expand Up @@ -298,15 +305,17 @@
self._recompute_budget_move()

def action_cancel(self):
"""Do not allow cancel document is past period."""
forwards = self.env["budget.commit.forward"].search([("state", "=", "done")])
max_date_commit = max(forwards.mapped("to_date_commit"))
# Not allow cancel document is past period.
if max_date_commit and any(
rec.to_date_commit < max_date_commit for rec in self
):
raise UserError(
_("Unable to cancel this document as it belongs to a past period.")
)
if forwards:
max_date_commit = max(forwards.mapped("to_date_commit"))

Check warning on line 311 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L311

Added line #L311 was not covered by tests
# Not allow cancel document is past period.
if max_date_commit and any(
rec.to_date_commit < max_date_commit for rec in self
):
raise UserError(

Check warning on line 316 in budget_control/models/budget_commit_forward.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/budget_commit_forward.py#L316

Added line #L316 was not covered by tests
_("Unable to cancel this document as it belongs to a past period.")
)
self.filtered(lambda l: l.state == "done")._do_forward_commit(reverse=True)
self.write({"state": "cancel"})
self._do_update_initial_commit(reverse=True)
Expand Down
1 change: 1 addition & 0 deletions budget_control/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUpClass(cls):
cls.Partner = cls.env["res.partner"]
cls.Move = cls.env["account.move"]
cls.BudgetAdjust = cls.env["budget.move.adjustment"]
cls.CommitForward = cls.env["budget.commit.forward"]

# Create vendor
cls.vendor = cls.Partner.create({"name": "Sample Vendor"})
Expand Down
Loading
Loading