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

[14.0][REF] account_compensate_advance: name_get display info Total and Balance #75

Merged
merged 1 commit into from
Jul 5, 2024
Merged
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
19 changes: 13 additions & 6 deletions account_compensate_advance/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
# flake8: noqa: B950

import locale

from odoo import _, models
from odoo.tools.misc import formatLang


class AccountMoveLine(models.Model):
Expand All @@ -16,19 +15,24 @@
Override the name_get method to customize the display name of records based on the context.
"""
context = self._context or {}
locale.setlocale(locale.LC_ALL, self.env.user.lang)

# Customize name display for 'advance_id' based on context
if "advance_id_name_get" in context and context["advance_id_name_get"]:
result = []
balance_str = _("Balance")
for rec in self:
total_str = formatLang(

Check warning on line 24 in account_compensate_advance/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

account_compensate_advance/models/account_move_line.py#L24

Added line #L24 was not covered by tests
self.env, abs(rec.price_total), currency_obj=rec.currency_id
)
balance_residual_str = formatLang(

Check warning on line 27 in account_compensate_advance/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

account_compensate_advance/models/account_move_line.py#L27

Added line #L27 was not covered by tests
self.env, abs(rec.amount_residual), currency_obj=rec.currency_id
)
# Format name with localized date, total, and balance
name = (
f"{rec.name} | "
f"{_('Date')}: {rec.move_id.date.strftime('%x')} | "
f"{_('Total')}: {locale.format_string('%.2f', abs(rec.price_total), grouping=True)} | "
f"{balance_str}: {locale.format_string('%.2f', abs(rec.amount_residual), grouping=True)}"
f"{_('Total')}: {total_str} | "
f"{balance_str}: {balance_residual_str}"
)
result.append((rec.id, name))
return result
Expand All @@ -37,11 +41,14 @@
if "line_id_name_get" in context and context["line_id_name_get"]:
result = []
for rec in self:
total_str = formatLang(

Check warning on line 44 in account_compensate_advance/models/account_move_line.py

View check run for this annotation

Codecov / codecov/patch

account_compensate_advance/models/account_move_line.py#L44

Added line #L44 was not covered by tests
self.env, abs(rec.price_total), currency_obj=rec.currency_id
)
# Format name with localized date and total
name = (
f"{rec.name or rec.move_id.name} | "
f"{_('Date')}: {rec.date_maturity.strftime('%x')} | "
f"{_('Total')}: {locale.format_string('%.2f', abs(rec.price_total), grouping=True)}"
f"{_('Total')}: {total_str}"
)
result.append((rec.id, name))
return result
Expand Down
Loading