From 7b25cea0cec6fc12e003cd531d89d0a0709d3e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Thu, 16 Jan 2025 03:41:58 +0000 Subject: [PATCH] [MIG] l10n_br_mdfe_spec: Migration to 16.0 don't reformat MDFe generated code --- .pre-commit-config.yaml | 1 + l10n_br_mdfe_spec/__manifest__.py | 2 +- l10n_br_mdfe_spec/tests/test_mdfe_import.py | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b507726ba60..9a7f1663d885 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,6 +3,7 @@ exclude: | # NOT INSTALLABLE ADDONS # END NOT INSTALLABLE ADDONS ^l10n_br_nfe_spec/models/v4_0/| # (don't reformat generated code) + ^l10n_br_mdfe_spec/models/v3_0/| # (don't reformat generated code) ^spec_driven_model/tests/| # (tests include generated code) # Files and folders generated by bots, to avoid loops ^setup/|/static/description/index\.html$| diff --git a/l10n_br_mdfe_spec/__manifest__.py b/l10n_br_mdfe_spec/__manifest__.py index 923cacdfd3fb..cd3f917146ed 100644 --- a/l10n_br_mdfe_spec/__manifest__.py +++ b/l10n_br_mdfe_spec/__manifest__.py @@ -1,6 +1,6 @@ { "name": "mdfe spec", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "author": "Akretion, Odoo Community Association (OCA)", "license": "LGPL-3", "category": "Accounting", diff --git a/l10n_br_mdfe_spec/tests/test_mdfe_import.py b/l10n_br_mdfe_spec/tests/test_mdfe_import.py index ae79f02ae95d..c40649a37528 100644 --- a/l10n_br_mdfe_spec/tests/test_mdfe_import.py +++ b/l10n_br_mdfe_spec/tests/test_mdfe_import.py @@ -137,26 +137,28 @@ def fields_convert_to_cache(self, value, record, validate=True): # cache format: tuple(ids) if isinstance(value, BaseModel): if validate and value._name != self.comodel_name: - raise ValueError("Wrong value for %s: %s" % (self, value)) + raise ValueError(f"Wrong value for {self}: {value}") ids = value._ids if record and not record.id: # x2many field value of new record is new records ids = tuple(it and NewId(it) for it in ids) return ids - elif isinstance(value, (list, tuple)): + elif isinstance(value, list | tuple): # value is a list/tuple of commands, dicts or record ids comodel = record.env[self.comodel_name] # if record is new, the field's value is new records # THE NEXT LINE WAS PATCHED: if record and hasattr(record, "id") and not record.id: - browse = lambda it: comodel.browse([it and NewId(it)]) + + def browse(it): + return comodel.browse([it and NewId(it)]) else: browse = comodel.browse # determine the value ids ids = OrderedSet(record[self.name]._ids if validate else ()) # modify ids with the commands for command in value: - if isinstance(command, (tuple, list)): + if isinstance(command, tuple | list): if command[0] == Command.CREATE: # THE NEXT 4 LINES WERE PATCHED: if hasattr(comodel.new(command[2], ref=command[1]), "id"): @@ -186,7 +188,7 @@ def fields_convert_to_cache(self, value, record, validate=True): return tuple(ids) elif not value: return () - raise ValueError("Wrong value for %s: %s" % (self, value)) + raise ValueError(f"Wrong value for {self}: {value}") fields_convert_to_cache._original_method = fields._RelationalMulti.convert_to_cache @@ -206,7 +208,7 @@ def models_update_cache(self, values, validate=True): try: field_values = [(fields[name], value) for name, value in values.items()] except KeyError as e: - raise ValueError("Invalid field %r on model %r" % (e.args[0], self._name)) + raise ValueError(f"Invalid field {e.args[0]!r} on model {self._name!r}") from e # convert monetary fields after other columns for correct value rounding for field, value in sorted(field_values, key=lambda item: item[0].write_sequence): cache.set(self, field, field.convert_to_cache(value, self, validate)) @@ -220,8 +222,10 @@ def models_update_cache(self, values, validate=True): continue for invf in self.pool.field_inverses[field]: # DLE P98: `test_40_new_fields` - # /home/dle/src/odoo/master-nochange-fp/odoo/addons/test_new_api/tests/test_new_fields.py - # Be careful to not break `test_onchange_taxes_1`, `test_onchange_taxes_2`, `test_onchange_taxes_3` + # /home/dle/src/odoo/master-nochange-fp/ + # odoo/addons/test_new_api/tests/test_new_fields.py + # Be careful to not break `test_onchange_taxes_1`, + # `test_onchange_taxes_2`, `test_onchange_taxes_3` # If you attempt to find a better solution for inv_rec in inv_recs: if not cache.contains(inv_rec, invf):