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

[16.0][ADD] shopinvader_search_engine_product_multi_price #1498

Conversation

qgroulard
Copy link
Contributor

@qgroulard qgroulard commented Jan 26, 2024

See #1441 and #1467 for PRs on related matter.

  1. Remove price from the schema in shopinvader_product as there are a lot of different ways to expose product prices and they should be handled in dedicated modules.
    '_get_price()' method has already been extracted to OCA/product-attribute module 'product_get_price_helper'.

  2. Add a module to export prices for a list of pricelists set on the index or backend.

@qgroulard qgroulard force-pushed the 16.0-shopinvader_product_multi_price-qgr branch from b3e26de to 12a4226 Compare January 26, 2024 15:42
@simahawk
Copy link
Contributor

@qgroulard the 1st commit can be dropped now, no?

index_id = self.env.context.get("index_id", False)
index = self.env["se.index"].browse(index_id)
for product in self:
prices = {"default": product._get_price()}
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't make more consistent to have the ID of the default pricelist here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went for the simplest solution possible. Here we have no such thing as "default pricelist", the default price is the price without pricelist.

Maybe it would make even more sense to remove this "default" key (I can still add it at my project level).

For now we have no reliable solution for prices on the main branch, I think it would be great to have at lease one simple option available. Then we can build up on that or add other modules for other ways of computing and exposing prices.

I'm glad to finally see someone care about prices 😁

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 testing this now and if the pricelist is already on the backend or the index we'll have a duplicated price info

Copy link
Contributor

Choose a reason for hiding this comment

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

As for the default: either we add a specific field to configure which pricelist is the default one or we drop this "default" key and we assume that the client must know which pricelist to use.

Copy link
Contributor

@simahawk simahawk Feb 26, 2024

Choose a reason for hiding this comment

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

Another option: add a key _default pointing to the default id but it will still index duplicated info across all records

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you are testing with both shopinvader_search_engine_product_multi_price and shopinvader_search_engine_product_price (#1441) installed ?

I actually think we don't need a "default" key in prices of shopinvader_search_engine_product_multi_price, if people want a default price they can install shopinvader_search_engine_product_price, choose the (default) pricelist on the backend, and consider the key price as the default price.

We can also rename the key prices into prices_by_pricelist or pricelist_prices to clarify things.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm not testing w/ both modules. The default key comes because of this module. You are not replacing the dict you are updating it. price_by_pricelist is probably more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I've been busy for the past two weeks.
I have removed the key "default" and I have renamed the key prices to price_by_pricelist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@qgroulard
Copy link
Contributor Author

@qgroulard the 1st commit can be dropped now, no?

In theory yes, the keys price and prices can coexist.

But I think price should be removed anyway as it is a broken first draft. Prices were still WIP when schemas have been merged, keeping it on the main branch seems wrong to me.

@simahawk
Copy link
Contributor

@qgroulard the 1st commit can be dropped now, no?

In theory yes, the keys price and prices can coexist.

But I think price should be removed anyway as it is a broken first draft. Prices were still WIP when schemas have been merged, keeping it on the main branch seems wrong to me.

I meant that you already removed it when creating the helper module, no?

@simahawk
Copy link
Contributor

@qgroulard the 1st commit can be dropped now, no?

In theory yes, the keys price and prices can coexist.
But I think price should be removed anyway as it is a broken first draft. Prices were still WIP when schemas have been merged, keeping it on the main branch seems wrong to me.

I meant that you already removed it when creating the helper module, no?

It seems not, in fact 😅

@simahawk
Copy link
Contributor

@qgroulard can we fast track #1507 while fixing this one?

for product in self:
prices = {"default": product._get_price()}
if index_id:
for pricelist in index._get_pricelists():
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this returning the default pricelist as well?
If so, I would've put {"default": default_list.id}.
Otherwise you compute the price twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved with the last change, the "default" key has been removed.

if index_id:
for pricelist in index._get_pricelists():
price = product._get_price(pricelist=pricelist)
prices.update({f"{pricelist.id}": price})
Copy link
Contributor

Choose a reason for hiding this comment

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

why not {str(pricelist_id): price}?
I don't think we need to format strings here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@qgroulard qgroulard force-pushed the 16.0-shopinvader_product_multi_price-qgr branch 4 times, most recently from c1cb7f7 to 45eb5e3 Compare March 13, 2024 12:59
@simahawk
Copy link
Contributor

simahawk commented Apr 8, 2024

@qgroulard ping :)

@qgroulard qgroulard force-pushed the 16.0-shopinvader_product_multi_price-qgr branch from 45eb5e3 to 2c1c43f Compare June 3, 2024 14:26
@sebastienbeau sebastienbeau added this to the 16.0 milestone Jun 3, 2024


class ProductProduct(BaseProduct, extends=True):
price_by_pricelist: dict[str, ProductPriceInfo] = {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
price_by_pricelist: dict[str, ProductPriceInfo] = {}
price_by_pricelist: dict[int, ProductPriceInfo] = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@lmignon lmignon left a comment

Choose a reason for hiding this comment

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

@qgroulard The key should be an integer.... It's confusing to have to convert an identifier from the user's profile for example to a string to get the right price. The type of a value should not vary depending where it's used...

@qgroulard qgroulard force-pushed the 16.0-shopinvader_product_multi_price-qgr branch from 2c1c43f to 18ef55b Compare June 4, 2024 09:23
@qgroulard qgroulard force-pushed the 16.0-shopinvader_product_multi_price-qgr branch from 18ef55b to 005e5ff Compare June 4, 2024 12:27
Copy link
Contributor

@sebastienbeau sebastienbeau left a comment

Choose a reason for hiding this comment

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

LGTM (code review)

@lmignon
Copy link
Collaborator

lmignon commented Jun 4, 2024

/ocabot merge nobump

@shopinvader-git-bot
Copy link

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-1498-by-lmignon-bump-nobump, awaiting test results.

@shopinvader-git-bot shopinvader-git-bot merged commit 033d62d into shopinvader:16.0 Jun 4, 2024
3 checks passed
@shopinvader-git-bot
Copy link

Congratulations, your PR was merged at d544edf. Thanks a lot for contributing to shopinvader. ❤️

@lmignon lmignon deleted the 16.0-shopinvader_product_multi_price-qgr branch June 4, 2024 16:49
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.

6 participants