Skip to content

Commit

Permalink
Merge PR #577 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by sbidoul
  • Loading branch information
OCA-git-bot committed Nov 15, 2023
2 parents ed2f837 + 116c6f6 commit d93839b
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 130 deletions.
6 changes: 5 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.17.2
_commit: v1.19.2
_src_path: git+https://github.com/OCA/oca-addons-repo-template
additional_ruff_rules: []
ci: GitHub
convert_readme_fragments_to_markdown: false
generate_requirements_txt: true
github_check_license: true
github_ci_extra_env: {}
Expand Down Expand Up @@ -36,4 +38,6 @@ repo_description: "Management Information System reports for Odoo: easily build
repo_name: MIS Builder
repo_slug: mis-builder
repo_website: https://github.com/OCA/mis-builder
use_pyproject_toml: false
use_ruff: true

12 changes: 0 additions & 12 deletions .flake8

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/
*.py[cod]
/.venv
/.pytest_cache
/.ruff_cache

# C extensions
*.so
Expand Down
13 changes: 0 additions & 13 deletions .isort.cfg

This file was deleted.

43 changes: 9 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ exclude: |
^docs/_templates/.*\.html$|
# Don't bother non-technical authors with formatting issues in docs
readme/.*\.(rst|md)$|
# Ignore build and dist directories in addons
/build/|/dist/|
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)
default_language_version:
Expand All @@ -35,7 +37,7 @@ repos:
language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools
rev: 969238e47c07d0c40573acff81d170f63245d738
rev: f71041f22b8cd68cf7c77b73a14ca8d8cd190a60
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
Expand All @@ -48,26 +50,12 @@ repos:
- --org-name=OCA
- --repo-name=mis-builder
- --if-source-changed
- --keep-source-digest
- repo: https://github.com/OCA/odoo-pre-commit-hooks
rev: v0.0.25
hooks:
- id: oca-checks-odoo-module
- id: oca-checks-po
- repo: https://github.com/myint/autoflake
rev: v1.6.1
hooks:
- id: autoflake
args:
- --expand-star-imports
- --ignore-init-module-imports
- --in-place
- --remove-all-unused-imports
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
Expand Down Expand Up @@ -109,19 +97,6 @@ repos:
- id: check-xml
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
hooks:
- id: pyupgrade
args: ["--keep-percent-format"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
name: isort except __init__.py
args:
- --settings=.
exclude: /__init__\.py$
- repo: https://github.com/acsone/setuptools-odoo
rev: 3.1.8
hooks:
Expand All @@ -132,12 +107,12 @@ repos:
- requirements.txt
- --header
- "# generated from manifests external_dependencies"
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==21.9.2"]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/OCA/pylint-odoo
rev: v8.0.19
hooks:
Expand Down
30 changes: 30 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

target-version = "py310"
fix = true

[lint]
extend-select = [
"B",
"C90",
"E501", # line too long (default 88)
"I", # isort
"UP", # pyupgrade
]
exclude = ["setup/*"]

[format]
exclude = ["setup/*"]

[per-file-ignores]
"__init__.py" = ["F401", "I001"] # ignore unused and unsorted imports in __init__.py
"__manifest__.py" = ["B018"] # useless expression

[isort]
section-order = ["future", "standard-library", "third-party", "odoo", "odoo-addons", "first-party", "local-folder"]

[isort.sections]
"odoo" = ["odoo"]
"odoo-addons" = ["odoo.addons"]

[mccabe]
max-complexity = 16
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
6 changes: 3 additions & 3 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 Expand Up @@ -543,4 +543,4 @@ def get_unallocated_pl(cls, companies, date):
# TODO shoud we include here the accounts of type "unaffected"
# or leave that to the caller?
bals = cls._get_balances(cls.MODE_UNALLOCATED, companies, date, date)
return tuple(map(sum, zip(*bals.values())))
return tuple(map(sum, zip(*bals.values(), strict=True)))
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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -58,7 +58,7 @@ def eval_expressions_by_account(self, expressions, locals_dict):
vals = []
drilldown_args = []
name_error = False
for expr, replaced_expr in zip(exprs, replaced_exprs):
for expr, replaced_expr in zip(exprs, replaced_exprs, strict=True):
val = mis_safe_eval(replaced_expr, locals_dict)
vals.append(val)
if replaced_expr != expr:
Expand Down
35 changes: 19 additions & 16 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 @@ -234,7 +234,9 @@ def set_values_detail_account(
cell_tuple = []
assert len(vals) == col.colspan
assert len(drilldown_args) == col.colspan
for val, drilldown_arg, subcol in zip(vals, drilldown_args, col.iter_subcols()):
for val, drilldown_arg, subcol in zip(
vals, drilldown_args, col.iter_subcols(), strict=True
):
if isinstance(val, DataError):
val_rendered = val.name
val_comment = val.msg
Expand All @@ -249,7 +251,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 +316,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 @@ -346,7 +348,10 @@ def compute_comparisons(self):
]
comparison_cell_tuple = []
for val, base_val, comparison_subcol in zip(
vals, base_vals, comparison_col.iter_subcols()
vals,
base_vals,
comparison_col.iter_subcols(),
strict=True,
):
# TODO FIXME average factors
comparison = self._style_model.compare_and_render(
Expand Down Expand Up @@ -442,8 +447,7 @@ def iter_rows(self):
yield kpi_row
detail_rows = self._detail_rows[kpi_row.kpi].values()
detail_rows = sorted(detail_rows, key=lambda r: r.label)
for detail_row in detail_rows:
yield detail_row
yield from detail_rows

def iter_cols(self):
"""Iterate columns in display order.
Expand All @@ -460,8 +464,7 @@ def iter_subcols(self):
and comparison.
"""
for col in self.iter_cols():
for subcol in col.iter_subcols():
yield subcol
yield from col.iter_subcols()

def _load_account_names(self):
account_ids = set()
Expand All @@ -471,9 +474,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
Loading

0 comments on commit d93839b

Please sign in to comment.