Skip to content

Commit

Permalink
Ruff auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Oct 28, 2023
1 parent f17eee3 commit 50d21df
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 58 deletions.
2 changes: 1 addition & 1 deletion mis_builder/models/accounting_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
__all__ = ["AccountingNone"]


class AccountingNoneType(object):
class AccountingNoneType:
def __add__(self, other):
if other is None:
return AccountingNone
Expand Down
4 changes: 2 additions & 2 deletions mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _is_domain(s):
return _DOMAIN_START_RE.match(s)


class AccountingExpressionProcessor(object):
class AccountingExpressionProcessor:
"""Processor for accounting expressions.
Expressions of the form <field><mode>[accounts][optional move line domain]
Expand Down Expand Up @@ -480,7 +480,7 @@ def f(mo):

@classmethod
def _get_balances(cls, mode, companies, date_from, date_to):
expr = "deb{mode}[], crd{mode}[]".format(mode=mode)
expr = f"deb{mode}[], crd{mode}[]"
aep = AccountingExpressionProcessor(companies)
# disable smart_end to have the data at once, instead
# of initial + variation
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/models/data_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, name, msg):
self.msg = msg

def __repr__(self):
return "{}({})".format(self.__class__.__name__, repr(self.name))
return f"{self.__class__.__name__}({repr(self.name)})"


class NameDataError(DataError):
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/models/expression_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .mis_safe_eval import NameDataError, mis_safe_eval


class ExpressionEvaluator(object):
class ExpressionEvaluator:
def __init__(
self,
aep,
Expand Down
20 changes: 10 additions & 10 deletions mis_builder/models/kpimatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
_logger = logging.getLogger(__name__)


class KpiMatrixRow(object):
class KpiMatrixRow:
# TODO: ultimately, the kpi matrix will become ignorant of KPI's and
# accounts and know about rows, columns, sub columns and styles only.
# It is already ignorant of period and only knowns about columns.
Expand Down Expand Up @@ -48,7 +48,7 @@ def row_id(self):
if not self.account_id:
return self.kpi.name
else:
return "{}:{}".format(self.kpi.name, self.account_id)
return f"{self.kpi.name}:{self.account_id}"

def iter_cell_tuples(self, cols=None):
if cols is None:
Expand All @@ -69,7 +69,7 @@ def is_empty(self):
return True


class KpiMatrixCol(object):
class KpiMatrixCol:
def __init__(self, key, label, description, locals_dict, subkpis):
self.key = key
self.label = label
Expand Down Expand Up @@ -100,7 +100,7 @@ def get_cell_tuple_for_row(self, row):
return self._cell_tuples_by_row.get(row)


class KpiMatrixSubCol(object):
class KpiMatrixSubCol:
def __init__(self, col, label, description, index=0):
self.col = col
self.label = label
Expand All @@ -123,7 +123,7 @@ def get_cell_for_row(self, row):
return cell_tuple[self.index]


class KpiMatrixCell(object): # noqa: B903 (immutable data class)
class KpiMatrixCell: # noqa: B903 (immutable data class)
def __init__(
self,
row,
Expand All @@ -145,7 +145,7 @@ def __init__(
self.val_type = val_type


class KpiMatrix(object):
class KpiMatrix:
def __init__(self, env, multi_company=False, account_model="account.account"):
# cache language id for faster rendering
lang_model = env["res.lang"]
Expand Down Expand Up @@ -249,7 +249,7 @@ def set_values_detail_account(
row.kpi._get_expression_str_for_subkpi(subcol.subkpi),
)
else:
val_comment = "{} = {}".format(row.kpi.name, row.kpi.expression)
val_comment = f"{row.kpi.name} = {row.kpi.expression}"
cell_style_props = row.style_props
if row.kpi.style_expression:
# evaluate style expression
Expand Down Expand Up @@ -314,7 +314,7 @@ def compute_comparisons(self):
)
)
if not label:
label = "{} vs {}".format(col.label, base_col.label)
label = f"{col.label} vs {base_col.label}"
comparison_col = KpiMatrixCol(
cmpcol_key,
label,
Expand Down Expand Up @@ -471,9 +471,9 @@ def _load_account_names(self):
self._account_names = {a.id: self._get_account_name(a) for a in accounts}

def _get_account_name(self, account):
result = "{} {}".format(account.code, account.name)
result = f"{account.code} {account.name}"
if self._multi_company:
result = "{} [{}]".format(result, account.company_id.name)
result = f"{result} [{account.company_id.name}]"
return result

def get_account_name(self, account_id):
Expand Down
16 changes: 10 additions & 6 deletions mis_builder/models/mis_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
from odoo.models import expression as osv_expression
from odoo.tools.safe_eval import (
datetime as safe_datetime,
)
from odoo.tools.safe_eval import (
dateutil as safe_dateutil,
)
from odoo.tools.safe_eval import (
safe_eval,
)
from odoo.tools.safe_eval import (
time as safe_time,
)

Expand All @@ -42,7 +48,7 @@ class SubKPIUnknownTypeError(UserError):
pass


class AutoStruct(object):
class AutoStruct:
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
Expand Down Expand Up @@ -144,7 +150,7 @@ class MisReportKpi(models.Model):
def name_get(self):
res = []
for rec in self:
name = "{} ({})".format(rec.description, rec.name)
name = f"{rec.description} ({rec.name})"
res.append((rec.id, name))
return res

Expand All @@ -171,9 +177,7 @@ def _compute_expression(self):
for expression in kpi.expression_ids:
if expression.subkpi_id:
exprs.append(
"{}\xa0=\xa0{}".format(
expression.subkpi_id.name, expression.name
)
f"{expression.subkpi_id.name}\xa0=\xa0{expression.name}"
)
else:
exprs.append(expression.name or "AccountingNone")
Expand Down Expand Up @@ -671,7 +675,7 @@ def _declare_and_compute_col( # noqa: C901 (TODO simplify this fnction)
subkpis = self.subkpi_ids

SimpleArray_cls = named_simple_array(
"SimpleArray_{}".format(col_key), [subkpi.name for subkpi in subkpis]
f"SimpleArray_{col_key}", [subkpi.name for subkpi in subkpis]
)
locals_dict["SimpleArray"] = SimpleArray_cls

Expand Down
12 changes: 2 additions & 10 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class DateFilterForbidden(ValidationError):


class MisReportInstancePeriodSum(models.Model):

_name = "mis.report.instance.period.sum"
_description = "MIS Report Instance Period Sum"

Expand Down Expand Up @@ -918,13 +917,6 @@ def _get_drilldown_action_name(self, arg):

if account_id:
account = self.env[self.report_id.account_model].browse(account_id)
return "{kpi} - {account} - {period}".format(
kpi=kpi.description,
account=account.display_name,
period=period.display_name,
)
return f"{kpi.description} - {account.display_name} - {period.display_name}"
else:
return "{kpi} - {period}".format(
kpi=kpi.description,
period=period.display_name,
)
return f"{kpi.description} - {period.display_name}"
7 changes: 3 additions & 4 deletions mis_builder/models/mis_report_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def copy(self): # pylint: disable=copy-wo-api-one,method-required-super


class MisReportKpiStyle(models.Model):

_name = "mis.report.style"
_description = "MIS Report Style"

Expand Down Expand Up @@ -280,9 +279,9 @@ def to_xlsx_style(self, var_type, props, no_indent=False):
num_format += "."
num_format += "0" * props.dp
if props.prefix:
num_format = '"{} "{}'.format(props.prefix, num_format)
num_format = f'"{props.prefix} "{num_format}'
if props.suffix:
num_format = '{}" {}"'.format(num_format, props.suffix)
num_format = f'{num_format}" {props.suffix}"'
xlsx_attributes.append(("num_format", num_format))
elif var_type == TYPE_PCT:
num_format = "0"
Expand All @@ -305,7 +304,7 @@ def to_css_style(self, props, no_indent=False):
("background-color", props.background_color),
]
if props.indent_level is not None and not no_indent:
css_attributes.append(("text-indent", "{}em".format(props.indent_level)))
css_attributes.append(("text-indent", f"{props.indent_level}em"))
return (
"; ".join(["%s: %s" % a for a in css_attributes if a[1] is not None])
or None
Expand Down
2 changes: 1 addition & 1 deletion mis_builder/models/simple_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def __rtruediv__(self, other):
return self._cast(other)._op(operator.truediv, self)

def __repr__(self):
return "{}({})".format(self.__class__.__name__, tuple.__repr__(self))
return f"{self.__class__.__name__}({tuple.__repr__(self)})"


def named_simple_array(typename, field_names):
Expand Down
1 change: 0 additions & 1 deletion mis_builder/report/mis_report_instance_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MisBuilderXlsx(models.AbstractModel):
_inherit = "report.report_xlsx.abstract"

def generate_xlsx_report(self, workbook, data, objects):

# get the computed result of the report
matrix = objects._compute_matrix()
style_obj = self.env["mis.report.style"]
Expand Down
1 change: 0 additions & 1 deletion mis_builder/tests/fake_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class MisKpiDataTestItem(models.Model):

_name = "mis.kpi.data.test.item"
_inherit = "mis.kpi.data"
_description = "MIS Kpi Data test item"
3 changes: 2 additions & 1 deletion mis_builder/tests/test_aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from odoo.tools.safe_eval import safe_eval

from ..models.accounting_none import AccountingNone
from ..models.aep import AccountingExpressionProcessor as AEP, _is_domain
from ..models.aep import AccountingExpressionProcessor as AEP
from ..models.aep import _is_domain


class TestAEP(common.TransactionCase):
Expand Down
7 changes: 2 additions & 5 deletions mis_builder/tests/test_mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def test_multi_company_compute(self):
for row in matrix.iter_rows():
if row.account_id:
account = self.env["account.account"].browse(row.account_id)
self.assertEqual(row.label, "{} {}".format(account.code, account.name))
self.assertEqual(row.label, f"{account.code} {account.name}")

def test_evaluate(self):
company = self.env.ref("base.main_company")
Expand Down Expand Up @@ -444,10 +444,7 @@ def test_drilldown_action_name_without_account(self):
"kpi_id": self.kpi1.id,
}
action_name = self.report_instance._get_drilldown_action_name(args)
expected_name = "{kpi} - {period}".format(
kpi=self.kpi1.description,
period=period.display_name,
)
expected_name = f"{self.kpi1.description} - {period.display_name}"
assert action_name == expected_name

def test_qweb(self):
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisBudget(models.Model):

_name = "mis.budget"
_description = "MIS Budget by KPI"
_inherit = ["mis.budget.abstract", "mail.thread"]
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisBudgetAbstract(models.AbstractModel):

_name = "mis.budget.abstract"
_description = "MIS Budget (Abstract Base Class)"
_inherit = ["mail.thread"]
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget_by_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisBudgetByAccount(models.Model):

_name = "mis.budget.by.account"
_description = "MIS Budget by Account"
_inherit = ["mis.budget.abstract", "mail.thread"]
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget_by_account_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisBudgetByAccountItem(models.Model):

_inherit = ["mis.budget.item.abstract", "prorata.read_group.mixin"]
_name = "mis.budget.by.account.item"
_description = "MIS Budget Item (by Account)"
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisBudgetItem(models.Model):

_inherit = ["mis.budget.item.abstract", "mis.kpi.data"]
_name = "mis.budget.item"
_description = "MIS Budget Item (by KPI)"
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_budget_item_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class MisBudgetItemAbstract(models.AbstractModel):

_name = "mis.budget.item.abstract"
_description = "MIS Budget Item (Abstract Base Class)"

Expand Down
2 changes: 0 additions & 2 deletions mis_builder_budget/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ def eval_expressions(self, expressions, locals_dict):


class MisReportInstance(models.Model):

_inherit = "mis.report.instance"

def _add_column_mis_budget(self, aep, kpi_matrix, period, label, description):

# fetch budget data for the period
base_domain = AND(
[
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_report_instance_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class MisReportInstancePeriod(models.Model):

_inherit = "mis.report.instance.period"

source = fields.Selection(
Expand Down
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_report_kpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisReportKpi(models.Model):

_inherit = "mis.report.kpi"

budgetable = fields.Boolean(default=False)
1 change: 0 additions & 1 deletion mis_builder_budget/models/mis_report_kpi_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class MisReportKpiExpression(models.Model):

_inherit = "mis.report.kpi.expression"

@api.model
Expand Down
2 changes: 1 addition & 1 deletion mis_builder_budget/tests/test_mis_budget_by_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUpClass(cls):
report_id=cls.report.id,
name="k1",
description="kpi 1",
expression="balp[('id', '=', {})]".format(account.id),
expression=f"balp[('id', '=', {account.id})]",
)
)
# budget
Expand Down
4 changes: 2 additions & 2 deletions mis_builder_demo/models/mis_committed_purchase.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from os.path import dirname, join as opj
from os.path import dirname
from os.path import join as opj

from odoo import fields, models, tools


class MisCommittedPurchase(models.Model):

_name = "mis.committed.purchase"
_description = "MIS Commitment"
_auto = False
Expand Down

0 comments on commit 50d21df

Please sign in to comment.