Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG][17.0] product_configurator: Migration to 17.0 #141

Merged

Conversation

bizzappdev
Copy link
Contributor

No description provided.

@simahawk
Copy link
Contributor

simahawk commented Nov 4, 2024

@bizzappdev are you taking over #135 ?

@bizzappdev
Copy link
Contributor Author

@bizzappdev are you taking over #135 ?

Yes, We have started working on this MR for the migration.

@simahawk
Copy link
Contributor

simahawk commented Nov 6, 2024

/ocabot migration product_configurator

@OCA-git-bot OCA-git-bot added this to the 17.0 milestone Nov 6, 2024
@OCA-git-bot OCA-git-bot mentioned this pull request Nov 6, 2024
3 tasks
@bizzappdev bizzappdev force-pushed the 17.0-mig-product_configurator-BAD branch 5 times, most recently from 232f351 to e5a6322 Compare November 14, 2024 15:44
@bizzappdev bizzappdev marked this pull request as ready for review November 14, 2024 16:36

# Process each `field_vals` operation for the current attribute
for field_vals in vals.get(field_name, []):
if field_vals and field_vals[0] == Command.SET:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to take care of other Commands, too (e.g: CLEAR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not triggered from the onchange web client, so even if we add code for those cases, we will not have a proper way to reproduce and test them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It's a bit fragile, though.
If, for some reason, Odoo refactors the onchange and starts outputting other commands, this would fail.

I wonder if we can use the field's convert_to_cache method instead. (many examples in odoo code)
That method offers the advantage of not having to worry about the internals of onchange nor commands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the optimal way to use convert_to_cache is to use this logic for the dynamic fields that are not present in _fields, which will restrict us from using direct convert_to_cache.
One possibility is to have a field instance via add_field, but I am not sure it is wiser to create a field instance just to use convert_to_cache.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for taking the time to explain all this.

elif field_vals and field_vals[0] == Command.UNLINK:
if field_vals[1] in final_val:
final_val.remove(field_vals[1])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems some of these cases aren't covered by unit tests.
Would it be possible to test them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will take care of the test cases in later stages.

local_domain_prefix = field_names and field_names[0].startswith(
domain_field_prefix
)
if field_type == list and (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous lines of code kind of assume the field_names is a list
(with things like field_names and field_names[0].startswith)

So, can it be something different than list or not?
Either this condition is redundant, or the previous code might fail

Looking at the core methods, it seems it's safe to assume it's always going to be a list, and so this condition can be removed

For simplicity and readability, I'd do something like this:

regular_field_names = (
    fname for fname in field_names
    if not any(fname.startswith(prefix) for prefix in self._prefixes.values())
)
if regular_field_names:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In odoo v17.0, it will return the list of fields changed from the web client. In the case of form view, even if it is always one field, it is still a list of a field.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's my point.
Checking if field_type == list is redundant then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bizzappdev bizzappdev force-pushed the 17.0-mig-product_configurator-BAD branch from e5a6322 to 3d27245 Compare November 19, 2024 19:45

# Process each `field_vals` operation for the current attribute
for field_vals in vals.get(field_name, []):
if field_vals and field_vals[0] == Command.SET:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It's a bit fragile, though.
If, for some reason, Odoo refactors the onchange and starts outputting other commands, this would fail.

I wonder if we can use the field's convert_to_cache method instead. (many examples in odoo code)
That method offers the advantage of not having to worry about the internals of onchange nor commands

local_domain_prefix = field_names and field_names[0].startswith(
domain_field_prefix
)
if field_type == list and (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's my point.
Checking if field_type == list is redundant then :)

@bizzappdev bizzappdev force-pushed the 17.0-mig-product_configurator-BAD branch from 3d27245 to 0d3ade8 Compare November 21, 2024 08:23
@bizzappdev bizzappdev force-pushed the 17.0-mig-product_configurator-BAD branch from 0d3ade8 to e78af0c Compare November 21, 2024 17:26
@bizzappdev
Copy link
Contributor Author

@ivantodorovich After your approval, we have made some changes to the code to make it compatible and generic with the website_product_configurator module.
BTW, you are also welcome to review #143, which is also ready for review.

Copy link

@ivantodorovich ivantodorovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@simahawk
Copy link
Contributor

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 17.0-ocabot-merge-pr-141-by-simahawk-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 9a19f68 into OCA:17.0 Nov 27, 2024
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 356cbb9. Thanks a lot for contributing to OCA. ❤️

@bizzappdev bizzappdev deleted the 17.0-mig-product_configurator-BAD branch November 28, 2024 13:47
@bizzappdev bizzappdev restored the 17.0-mig-product_configurator-BAD branch February 3, 2025 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants