Skip to content

Commit

Permalink
[FIX] budget_control: widget budgetpopover
Browse files Browse the repository at this point in the history
  • Loading branch information
Saran440 committed Aug 1, 2024
1 parent 1b7baf3 commit d930b1a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 60 deletions.
58 changes: 31 additions & 27 deletions budget_control/models/base_budget_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,39 +242,43 @@ def _compute_commit(self):

def _compute_json_budget_popover(self):
FloatConverter = self.env["ir.qweb.field.float"]

Check warning on line 244 in budget_control/models/base_budget_move.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/base_budget_move.py#L244

Added line #L244 was not covered by tests
# FIXME: How can we do with multi analytic account in 1 line.
for rec in self:
# analytic = rec[self._budget_analytic_field]
# if not analytic:
# rec.json_budget_popover = False
# continue
# # Budget Period is required, even a False one
# budget_period = self.env["budget.period"]._get_eligible_budget_period(
# date=rec.date_commit
# )
# analytic = analytic.with_context(budget_period_ids=[budget_period.id])
analytic_distribution = rec[self._budget_analytic_field]
analytic_account = rec._convert_analytics(

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

View check run for this annotation

Codecov / codecov/patch

budget_control/models/base_budget_move.py#L246-L247

Added lines #L246 - L247 were not covered by tests
analytic_distribution=analytic_distribution
)
if not analytic_account:
rec.json_budget_popover = False
continue

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

View check run for this annotation

Codecov / codecov/patch

budget_control/models/base_budget_move.py#L251-L252

Added lines #L251 - L252 were not covered by tests
# Budget Period is required, even a False one
budget_period = self.env["budget.period"]._get_eligible_budget_period(

Check warning on line 254 in budget_control/models/base_budget_move.py

View check run for this annotation

Codecov / codecov/patch

budget_control/models/base_budget_move.py#L254

Added line #L254 was not covered by tests
date=rec.date_commit
)
rec.json_budget_popover = dumps(
{
"title": _("Budget Figure"),
"icon": "fa-info-circle",
"popoverTemplate": "budget_control.budgetPopOver",
# "analytic": analytic,
"analytic_ids": [1, 2],
"budget": FloatConverter.value_to_html(
10, {"decimal_precision": "Product Price"}
),
"consumed": FloatConverter.value_to_html(
20, {"decimal_precision": "Product Price"}
),
"balance": FloatConverter.value_to_html(
30, {"decimal_precision": "Product Price"}
),
# "consumed": FloatConverter.value_to_html(
# analytic.amount_consumed, {"decimal_precision": "Product Price"}
# ),
# "balance": FloatConverter.value_to_html(
# analytic.amount_balance, {"decimal_precision": "Product Price"}
# ),
"analytic": [
{
"id": aa.id,
"name": aa.display_name,
"budget": FloatConverter.value_to_html(
aa.amount_budget, {"decimal_precision": "Product Price"}
),
"consumed": FloatConverter.value_to_html(
aa.amount_consumed,
{"decimal_precision": "Product Price"},
),
"balance": FloatConverter.value_to_html(
aa.amount_balance,
{"decimal_precision": "Product Price"},
),
}
for aa in analytic_account.with_context(
budget_period_ids=[budget_period.id]
)
],
}
)

Expand Down
68 changes: 35 additions & 33 deletions budget_control/static/src/xml/budget_popover.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<templates id="template" xml:space="preserve">
<div t-name="budget_control.budgetPopOver" owl="1">
<p>
AA1
</p>
<table class="table table-borderless">
<tbody>
<tr>
<td>
Planned
</td>
<td class="text-right">
<t t-esc="budget" />
</td>
</tr>
<tr>
<td>
Used
</td>
<td class="text-right">
- <t t-esc="consumed" />
</td>
</tr>
<tr class="table-info">
<td>
Available
</td>
<td class="text-right text-nowrap">
= <t t-esc="balance" />
</td>
</tr>
</tbody>
</table>
</div>
<t t-name="budget_control.budgetPopOver" owl="1">
<t t-foreach="props.analytic" t-as="item" t-key="item.id">
<div>
<b><t t-out="item.name" /></b>
</div>
<table class="table table-borderless">
<tbody>
<tr>
<td>
Planned
</td>
<td class="text-right">
<t t-out="item.budget" />
</td>
</tr>
<tr>
<td>
Used
</td>
<td class="text-right">
- <t t-out="item.consumed" />
</td>
</tr>
<tr class="table-info">
<td>
Available
</td>
<td class="text-right text-nowrap">
= <t t-out="item.balance" />
</td>
</tr>
</tbody>
</table>
</t>
</t>
</templates>

0 comments on commit d930b1a

Please sign in to comment.