Skip to content

Commit

Permalink
[MIG] l10n_br_cte_spec: Migration to 16.0
Browse files Browse the repository at this point in the history
don't format CTe generated code
  • Loading branch information
rvalyi committed Jan 16, 2025
1 parent 9e6a0fa commit 4126bdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 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_cte_spec/models/v4_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_cte_spec/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cte 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
25 changes: 13 additions & 12 deletions l10n_br_cte_spec/tests/test_cte_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def build_attrs_fake(self, node, create_m2o=False):
value = getattr(node, fname)
if value is None:
continue
key = "%s%s" % (
self._field_prefix,
fname,
)
key = f"{self._field_prefix}{fname}"

if (
fspec.type == str or not any(["." in str(i) for i in fspec.type.__args__])
Expand Down Expand Up @@ -150,26 +147,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 @@ -199,7 +198,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 @@ -219,7 +218,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 @@ -233,8 +232,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 4126bdf

Please sign in to comment.