Skip to content

Commit

Permalink
[MIG] l10n_br_mdfe_spec: Migration to 16.0
Browse files Browse the repository at this point in the history
don't reformat MDFe generated code
  • Loading branch information
rvalyi committed Jan 16, 2025
1 parent da35ad7 commit 7b25cea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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$|
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_mdfe_spec/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 12 additions & 8 deletions l10n_br_mdfe_spec/tests/test_mdfe_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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):
Expand Down

0 comments on commit 7b25cea

Please sign in to comment.