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

[14.0][IMP] shopinvader_variant: main product: add hooks #1529

Open
wants to merge 2 commits into
base: 14.0
Choose a base branch
from

Conversation

mmequignon
Copy link
Contributor

This pr adds the ability to modify the way variants are sorted to compute main variants.
For instance now, you can add new fields in _get_sort_read_fields in order to be able to filter out variants that cannot be the main variant for a given product.

@mmequignon mmequignon changed the base branch from 16.0 to 14.0 April 8, 2024 12:37
@mmequignon mmequignon force-pushed the shopinvader_variant-add_hooks_for_sort branch 5 times, most recently from bb48f34 to 725a06f Compare April 9, 2024 10:41
def _get_main_product_sorted_variants(cls, variants):
# NOTE: if the order is changed by adding `asc/desc` this can be broken
# but it's very unlikely that the default order for product.product
# will be changed.
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 that's not a nice assumption

Perhaps it's out of the scope of this PR, but I wonder why this method is even necessary.

When variants are searched (Line 330-336), the order is explicitly set to order="shopinvader_product_id". which should be enough for the ORM to return the records in the right variant order (according to the product.product model order)

Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is what I copied from the original method.
I don't like this implementation, but we don't have the budget to improve it for now.
Using sql syntax order and converting it to a python sort lambda function looks very risky to me…

Copy link
Contributor

Choose a reason for hiding this comment

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

It's stable guys, please don't touch it! Merci! 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for the 1st sorting in the search is to be able to use groupby, the 2nd sorting is the real sorting that normally happens when you pick up variants. @mmequignon you can add this my old comment 😉

Copy link
Contributor

@marielejeune marielejeune Apr 24, 2024

Choose a reason for hiding this comment

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

I understand this is a feature distinct from this PR, but if someone wants to improve it, it has been done in v16 by @qgroulard (because the default Odoo ordering on product.product changed and a priority desc was added) and it suffices to backport it.
Feel free to take the inspiration from

for order_key in reversed(order_by):

return ["shopinvader_product_id", "backend_id", "lang_id"] + order_by

@api.model
def _get_main_product_sorted_variants(cls, variants):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I see the value for this hook.
Wouldn't _pick_main_variant suffice?

Copy link
Contributor

@simahawk simahawk left a comment

Choose a reason for hiding this comment

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

LG overall. Needs test to turn 🟢

def _get_main_product_sorted_variants(cls, variants):
# NOTE: if the order is changed by adding `asc/desc` this can be broken
# but it's very unlikely that the default order for product.product
# will be changed.
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for the 1st sorting in the search is to be able to use groupby, the 2nd sorting is the real sorting that normally happens when you pick up variants. @mmequignon you can add this my old comment 😉

@simahawk
Copy link
Contributor

FTR tests are red on whole 14.0. See #1532

@marielejeune
Copy link
Contributor

Forward-port in version 16 here: #1524

@sebastienbeau sebastienbeau added this to the 14.0 milestone Jun 3, 2024
@lmignon
Copy link
Collaborator

lmignon commented Jun 4, 2024

@mmequignon Can you rebase to trigger tests plz?

@mmequignon mmequignon force-pushed the shopinvader_variant-add_hooks_for_sort branch from 725a06f to bbe8d6b Compare November 12, 2024 05:43
@mmequignon mmequignon force-pushed the shopinvader_variant-add_hooks_for_sort branch from bbe8d6b to 2fb2c24 Compare November 12, 2024 06:01
@simahawk
Copy link
Contributor

/ocabot merge minor

@shopinvader-git-bot
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@shopinvader-git-bot
Copy link

On my way to merge this fine PR!
Prepared branch 14.0-ocabot-merge-pr-1529-by-simahawk-bump-minor, awaiting test results.

shopinvader-git-bot pushed a commit that referenced this pull request Nov 12, 2024
Signed-off-by simahawk
@shopinvader-git-bot
Copy link

@simahawk your merge command was aborted due to failed check(s), which you can inspect on this commit of 14.0-ocabot-merge-pr-1529-by-simahawk-bump-minor.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

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.

9 participants