From bc34ec21303263bc1976550ababa51b43124719e Mon Sep 17 00:00:00 2001 From: chaule97 Date: Tue, 10 Dec 2024 12:00:59 +0700 Subject: [PATCH] [UDP] Replace _() to self.env._() --- mis_builder/models/aep.py | 6 ++--- mis_builder/models/kpimatrix.py | 5 ++-- mis_builder/models/mis_kpi_data.py | 4 ++-- mis_builder/models/mis_report.py | 16 ++++++------- mis_builder/models/mis_report_instance.py | 24 +++++++++---------- mis_builder/models/mis_report_style.py | 6 ++--- mis_builder/models/mis_report_subreport.py | 6 ++--- .../models/prorata_read_group_mixin.py | 4 ++-- .../report/mis_report_instance_xlsx.py | 4 ++-- .../models/mis_budget_abstract.py | 4 ++-- .../models/mis_budget_item_abstract.py | 8 +++---- 11 files changed, 43 insertions(+), 44 deletions(-) diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index fc687b9ff..b5b604a01 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -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 @@ -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." ) @@ -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" diff --git a/mis_builder/models/kpimatrix.py b/mis_builder/models/kpimatrix.py index 116d5e50f..64dcfd22e 100644 --- a/mis_builder/models/kpimatrix.py +++ b/mis_builder/models/kpimatrix.py @@ -4,7 +4,6 @@ import logging from collections import OrderedDict, defaultdict -from odoo import _ from odoo.exceptions import UserError from .accounting_none import AccountingNone @@ -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, @@ -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", diff --git a/mis_builder/models/mis_kpi_data.py b/mis_builder/models/mis_kpi_data.py index a4f814b3e..0b1143e3b 100644 --- a/mis_builder/models/mis_kpi_data.py +++ b/mis_builder/models/mis_kpi_data.py @@ -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 @@ -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, diff --git a/mis_builder/models/mis_report.py b/mis_builder/models/mis_report.py index dac2cd1f8..b496759da 100644 --- a/mis_builder/models/mis_report.py +++ b/mis_builder/models/mis_report.py @@ -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, @@ -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 ) ) @@ -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, ) @@ -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 ) ) @@ -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 @@ -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.", @@ -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 " @@ -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( diff --git a/mis_builder/models/mis_report_instance.py b/mis_builder/models/mis_report_instance.py index a38745092..1e23973e7 100644 --- a/mis_builder/models/mis_report_instance.py +++ b/mis_builder/models/mis_report_instance.py @@ -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 @@ -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 ) ) @@ -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." ) @@ -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 " @@ -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, @@ -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, @@ -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 @@ -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, @@ -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): @@ -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, ) @@ -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, diff --git a/mis_builder/models/mis_report_style.py b/mis_builder/models/mis_report_style.py index eff4eef65..776cab7ab 100644 --- a/mis_builder/models/mis_report_style.py +++ b/mis_builder/models/mis_report_style.py @@ -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 @@ -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")] @@ -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: diff --git a/mis_builder/models/mis_report_subreport.py b/mis_builder/models/mis_report_subreport.py index a112772cd..a1941c435 100644 --- a/mis_builder/models/mis_report_subreport.py +++ b/mis_builder/models/mis_report_subreport.py @@ -1,7 +1,7 @@ # Copyright 2020 ACSONE SA/NV () # 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 @@ -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, ) @@ -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 diff --git a/mis_builder/models/prorata_read_group_mixin.py b/mis_builder/models/prorata_read_group_mixin.py index df8cd0d6d..4800e6360 100644 --- a/mis_builder/models/prorata_read_group_mixin.py +++ b/mis_builder/models/prorata_read_group_mixin.py @@ -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 @@ -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 diff --git a/mis_builder/report/mis_report_instance_xlsx.py b/mis_builder/report/mis_report_instance_xlsx.py index f855c14b0..1e1b023eb 100644 --- a/mis_builder/report/mis_report_instance_xlsx.py +++ b/mis_builder/report/mis_report_instance_xlsx.py @@ -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 @@ -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), diff --git a/mis_builder_budget/models/mis_budget_abstract.py b/mis_builder_budget/models/mis_budget_abstract.py index b1f0fb0ba..92ac039d7 100644 --- a/mis_builder_budget/models/mis_budget_abstract.py +++ b/mis_builder_budget/models/mis_budget_abstract.py @@ -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): @@ -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") diff --git a/mis_builder_budget/models/mis_budget_item_abstract.py b/mis_builder_budget/models/mis_budget_item_abstract.py index bec7ca69c..ff0c4eb04 100644 --- a/mis_builder_budget/models/mis_budget_item_abstract.py +++ b/mis_builder_budget/models/mis_budget_item_abstract.py @@ -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 @@ -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, @@ -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,