Skip to content

Commit

Permalink
[UDP] Replace _() to self.env._()
Browse files Browse the repository at this point in the history
  • Loading branch information
chaule97 committed Dec 10, 2024
1 parent dc52bcd commit bc34ec2
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 44 deletions.
6 changes: 3 additions & 3 deletions mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
from collections import defaultdict

from odoo import _, fields
from odoo import fields
from odoo.exceptions import UserError
from odoo.models import expression
from odoo.tools.float_utils import float_is_zero
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(self, companies, currency=None, account_model="account.account"):
self.currency = companies.mapped("currency_id")
if len(self.currency) > 1:
raise UserError(
_(
self.env._(
"If currency_id is not provided, "
"all companies must have the same currency."
)
Expand Down Expand Up @@ -359,7 +359,7 @@ def do_queries(
)
except ValueError as e:
raise UserError(
_(
self.env._(
'Error while querying move line source "%(model_name)s". '
"This is likely due to a filter or expression referencing "
"a field that does not exist in the model.\n\n"
Expand Down
5 changes: 2 additions & 3 deletions mis_builder/models/kpimatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
from collections import OrderedDict, defaultdict

from odoo import _
from odoo.exceptions import UserError

from .accounting_none import AccountingNone
Expand Down Expand Up @@ -308,7 +307,7 @@ def compute_comparisons(self):
common_subkpis = self._common_subkpis([col, base_col])
if (col.subkpis or base_col.subkpis) and not common_subkpis:
raise UserError(
_(
self.env._(
"Columns %(descr)s and %(base_descr)s are not comparable",
descr=col.description,
base_descr=base_col.description,
Expand Down Expand Up @@ -394,7 +393,7 @@ def compute_sums(self):
common_subkpis = self._common_subkpis(sumcols)
if any(c.subkpis for c in sumcols) and not common_subkpis:
raise UserError(
_(
self.env._(
"Sum cannot be computed in column %s "
"because the columns to sum have no "
"common subkpis",
Expand Down
4 changes: 2 additions & 2 deletions mis_builder/models/mis_kpi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections import defaultdict

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression

Expand Down Expand Up @@ -97,7 +97,7 @@ def _query_kpi_data(self, date_from, date_to, base_domain):
res_avg[item.kpi_expression_id].append((i_days, item.amount))
else:
raise UserError(
_(
self.env._(
"Unexpected accumulation method %(method)s for %(name)s.",
method=item.kpi_expression_id.kpi_id.accumulation_method,
name=item.name,
Expand Down
16 changes: 8 additions & 8 deletions mis_builder/models/mis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import dateutil
import pytz

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools.safe_eval import (
datetime as safe_datetime,
Expand Down Expand Up @@ -158,7 +158,7 @@ def _check_name(self):
for record in self:
if not _is_valid_python_var(record.name):
raise ValidationError(
_(
self.env._(
"KPI name (%s) must be a valid python identifier", record.name
)
)
Expand Down Expand Up @@ -264,7 +264,7 @@ def _check_name(self):
for record in self:
if not _is_valid_python_var(record.name):
raise ValidationError(
_(
self.env._(
"Sub-KPI name (%s) must be a valid python identifier",
record.name,
)
Expand Down Expand Up @@ -393,7 +393,7 @@ def _check_name(self):
for record in self:
if not _is_valid_python_var(record.name):
raise ValidationError(
_(
self.env._(
"Query name (%s) must be valid python identifier", record.name
)
)
Expand Down Expand Up @@ -515,7 +515,7 @@ def get_wizard_report_action(self):
def copy(self, default=None):
self.ensure_one()
default = dict(default or [])
default["name"] = _("%s (copy)", self.name)
default["name"] = self.env._("%s (copy)", self.name)
new = super().copy(default)
# after a copy, we have new subkpis, but the expressions
# subkpi_id fields still point to the original one, so
Expand Down Expand Up @@ -709,7 +709,7 @@ def _declare_and_compute_col( # noqa: C901 (TODO simplify this fnction)
vals = vals[0]
if len(vals) != col.colspan:
raise SubKPITupleLengthError(
_(
self.env._(
'KPI "%(kpi)s" is valued as a tuple of '
"length %(length)s while a tuple of length"
"%(expected_length)s is expected.",
Expand All @@ -722,7 +722,7 @@ def _declare_and_compute_col( # noqa: C901 (TODO simplify this fnction)
vals = (vals[0],) * col.colspan
else:
raise SubKPIUnknownTypeError(
_(
self.env._(
'KPI "%(kpi)s" has type %(type)s while a tuple was '
"expected.\n\nThis can be fixed by either:\n\t- "
"Changing the KPI value to a tuple of length "
Expand Down Expand Up @@ -928,7 +928,7 @@ def _get_target_move_domain(self, target_move, aml_model_name):
return [("parent_state", "in", ("posted", "draft"))]
else:
raise UserError(
_("Unexpected value %s for target_move.", target_move)
self.env._("Unexpected value %s for target_move.", target_move)
)

def evaluate(
Expand Down
24 changes: 12 additions & 12 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from dateutil.relativedelta import relativedelta

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError

from .aep import AccountingExpressionProcessor as AEP
Expand Down Expand Up @@ -58,7 +58,7 @@ def _check_period_to_sum(self):
for rec in self:
if rec.period_id == rec.period_to_sum_id:
raise ValidationError(
_(
self.env._(
"You cannot sum period %s with itself.", rec.period_id.name
)
)
Expand Down Expand Up @@ -308,7 +308,7 @@ def _compute_source_aml_model_id(self):
if record.source == SRC_ACTUALS:
if not record.report_instance_id.report_id:
raise UserError(
_(
self.env._(
"Please select a report template and/or "
"save the report before adding columns."
)
Expand Down Expand Up @@ -340,7 +340,7 @@ def _check_source_aml_model_id(self):
report_account_model = record.report_id.account_model
if record_model != report_account_model:
raise ValidationError(
_(
self.env._(
"Actual (alternative) models used in columns must "
"have the same account model in the Account field and must "
"be the same defined in the "
Expand Down Expand Up @@ -416,7 +416,7 @@ def _check_mode_source(self):
if rec.source in (SRC_ACTUALS, SRC_ACTUALS_ALT):
if rec.mode == MODE_NONE:
raise DateFilterRequired(
_(
self.env._(
"A date filter is mandatory for this source "
"in column %s.",
rec.name,
Expand All @@ -425,7 +425,7 @@ def _check_mode_source(self):
elif rec.source in (SRC_SUMCOL, SRC_CMPCOL):
if rec.mode != MODE_NONE:
raise DateFilterForbidden(
_(
self.env._(
"No date filter is allowed for this source "
"in column %s.",
rec.name,
Expand All @@ -438,13 +438,13 @@ def _check_source_cmpcol(self):
if rec.source == SRC_CMPCOL:
if not rec.source_cmpcol_from_id or not rec.source_cmpcol_to_id:
raise ValidationError(
_(
self.env._(
"Please provide both columns to compare in %s.", rec.name
)
)
if rec.source_cmpcol_from_id == rec or rec.source_cmpcol_to_id == rec:
raise ValidationError(
_("Column %s cannot be compared to itrec.", rec.name)
self.env._("Column %s cannot be compared to itrec.", rec.name)
)
if (
rec.source_cmpcol_from_id.report_instance_id
Expand All @@ -453,7 +453,7 @@ def _check_source_cmpcol(self):
!= rec.report_instance_id
):
raise ValidationError(
_(
self.env._(
"Columns to compare must belong to the same report "
"in %s",
rec.name,
Expand Down Expand Up @@ -665,7 +665,7 @@ def _vacuum_report(self, hours=24):
def copy(self, default=None):
self.ensure_one()
default = dict(default or {})
default["name"] = _("%s (copy)", self.name)
default["name"] = self.env._("%s (copy)", self.name)
return super().copy(default)

def _format_date(self, date):
Expand Down Expand Up @@ -802,7 +802,7 @@ def display_settings(self):
def _add_column_move_lines(self, aep, kpi_matrix, period, label, description):
if not period.date_from or not period.date_to:
raise UserError(
_(
self.env._(
"Column %s with move lines source must have from/to dates.",
period.name,
)
Expand Down Expand Up @@ -877,7 +877,7 @@ def _compute_matrix(self):
elif period.date_from and period.date_to:
date_from = self._format_date(period.date_from)
date_to = self._format_date(period.date_to)
description = _(
description = self.env._(
"from %(date_from)s to %(date_to)s",
date_from=date_from,
date_to=date_to,
Expand Down
6 changes: 3 additions & 3 deletions mis_builder/models/mis_report_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import sys

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError

from .accounting_none import AccountingNone
Expand Down Expand Up @@ -56,7 +56,7 @@ def check_positive_val(self):
for record in self:
if record.indent_level < 0:
raise ValidationError(
_("Indent level must be greater than or equal to 0")
self.env._("Indent level must be greater than or equal to 0")
)

_font_style_selection = [("normal", "Normal"), ("italic", "Italic")]
Expand Down Expand Up @@ -236,7 +236,7 @@ def compare_and_render(
if var_type == TYPE_PCT:
delta = value - base_value
if delta and round(delta, (style_props.dp or 0) + 2) != 0:
delta_style.update(divider=0.01, prefix="", suffix=_("pp"))
delta_style.update(divider=0.01, prefix="", suffix=self.env._("pp"))
else:
delta = AccountingNone
elif var_type == TYPE_NUM:
Expand Down
6 changes: 3 additions & 3 deletions mis_builder/models/mis_report_subreport.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError

from .mis_report import _is_valid_python_var
Expand Down Expand Up @@ -50,7 +50,7 @@ def _check_name(self):
for rec in self:
if not _is_valid_python_var(rec.name):
raise InvalidNameError(
_(
self.env._(
"Subreport name (%s) must be a valid python identifier",
rec.name,
)
Expand All @@ -70,6 +70,6 @@ def _has_subreport(reports, report):

for rec in self:
if _has_subreport(rec.subreport_id, rec.report_id):
raise ParentLoopError(_("Subreport loop detected"))
raise ParentLoopError(self.env._("Subreport loop detected"))

# TODO check subkpi compatibility in subreports
4 changes: 2 additions & 2 deletions mis_builder/models/prorata_read_group_mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import UserError
from odoo.fields import Date

Expand Down Expand Up @@ -29,7 +29,7 @@ def _search_date(self, operator, value):
elif operator in ("<=", "<"):
return [("date_from", operator, value)]
raise UserError(
_("Unsupported operator %s for searching on date", operator)
self.env._("Unsupported operator %s for searching on date", operator)
)

@api.model
Expand Down
4 changes: 2 additions & 2 deletions mis_builder/report/mis_report_instance_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import defaultdict
from datetime import datetime

from odoo import _, fields, models
from odoo import fields, models

from ..models.accounting_none import AccountingNone
from ..models.data_error import DataError
Expand Down Expand Up @@ -161,7 +161,7 @@ def generate_xlsx_report(self, workbook, data, objects):
now_tz = fields.Datetime.context_timestamp(
self.env["res.users"], datetime.now()
)
create_date = _(
create_date = self.env._(
"Generated on %(gen_date)s at %(gen_time)s",
gen_date=now_tz.strftime(lang.date_format),
gen_time=now_tz.strftime(lang.time_format),
Expand Down
4 changes: 2 additions & 2 deletions mis_builder_budget/models/mis_budget_abstract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017-2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import api, fields, models


class MisBudgetAbstract(models.AbstractModel):
Expand Down Expand Up @@ -31,7 +31,7 @@ def copy(self, default=None):
if default is None:
default = {}
if "name" not in default:
default["name"] = _("%s (copy)", self.name)
default["name"] = self.env._("%s (copy)", self.name)
return super().copy(default=default)

@api.onchange("date_range_id")
Expand Down
8 changes: 4 additions & 4 deletions mis_builder_budget/models/mis_budget_item_abstract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017-2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -62,12 +62,12 @@ def _check_dates(self):
# date_from <= date_to
if rec.date_from > rec.date_to:
raise ValidationError(
_("%s start date must not be after end date", rec.display_name,)
self.env._("%s start date must not be after end date", rec.display_name,)
)
# within budget dates
if rec.date_from < rec.budget_date_from or rec.date_to > rec.budget_date_to:
raise ValidationError(
_(
self.env._(
"%(rec_name)s is not within budget %(budget_name)s date range.",
rec_name=rec.display_name,
budget_name=rec.budget_id.display_name,
Expand All @@ -78,7 +78,7 @@ def _check_dates(self):
res = self.search(domain, limit=1)
if res:
raise ValidationError(
_(
self.env._(
"%(rec_name)s overlaps %(res_name)s in budget %(budget_name)s",
rec_name=rec.display_name,
res_name=res.display_name,
Expand Down

0 comments on commit bc34ec2

Please sign in to comment.