Skip to content

feat: 5553 - add prices for category products #6552

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

Merged
merged 25 commits into from
Jun 12, 2025

Conversation

monsieurtanuki
Copy link
Contributor

What

  • Now when we add prices, we can add prices related to a category (e.g. "apples") instead of barcode

Screenshots

new "category input" button new "category input" page
Screenshot_1744719718 Screenshot_1744719743
new "price per" button category price input
Screenshot_1744719765 Screenshot_1744719770

Fixes bug(s)

Files

New files:

  • price_category_input_page.dart: Page that lets the user type in and select a single category for prices.
  • price_per_extension.dart: Extension for PricePer.

Impacted files:

  • app_en.arb: added 4 labels related to category and prices
  • app_fr.arb: added 4 labels related to category and prices
  • background_task_add_other_price.dart: added parameters related to category prices
  • background_task_add_price.dart: added parameters related to category prices
  • background_task_price.dart: added parameters related to category prices
  • price_add_product_card.dart: added an "add category product" button
  • price_amount_card.dart: added a DropDownButton for "price per" for category product
  • price_amount_model.dart: taken category prices into consideration
  • price_existing_amount_card.dart: unrelated localization
  • price_meta_product.dart: added a new meta product, related to category
  • price_model.dart: added parameters related to category prices
  • smooth_autocomplete_text_field.dart: added an "onSelected" optional parameter, in order to be able to select immediately a suggestion
  • smooth_dropdown.dart: added an "isExpanded" optional parameter, in order to match the screen width

New files:
* `price_category_input_page.dart`: Page that lets the user type in and select a single category for prices.
* `price_per_extension.dart`: Extension for PricePer.

Impacted files:
* `app_en.arb`: added 4 labels related to category and prices
* `app_fr.arb`: added 4 labels related to category and prices
* `background_task_add_other_price.dart`: added parameters related to category prices
* `background_task_add_price.dart`: added parameters related to category prices
* `background_task_price.dart`: added parameters related to category prices
* `price_add_product_card.dart`: added an "add category product" button
* `price_amount_card.dart`: added a DropDownButton for "price per" for category product
* `price_amount_model.dart`: taken category prices into consideration
* `price_existing_amount_card.dart`: unrelated localization
* `price_meta_product.dart`: added a new meta product, related to category
* `price_model.dart`: added parameters related to category prices
* `smooth_autocomplete_text_field.dart`: added an "onSelected" optional parameter, in order to be able to select immediately a suggestion
* `smooth_dropdown.dart`: added an "isExpanded" optional parameter, in order to match the screen width
Impacted files:
* `app_en.arb`: additional translations for "price per"
* `app_fr.arb`: additional translations for "price per"
* `price_existing_amount_field.dart`: localization
* `price_meta_product.dart`: minor refactoring
* `price_per_extension.dart`: additional translations for "price per"
@monsieurtanuki monsieurtanuki requested a review from teolemon April 15, 2025 12:47
@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 0.44248% with 225 lines in your changes missing coverage. Please review.

Project coverage is 5.69%. Comparing base (4d9c7fc) to head (091bdaa).
Report is 896 commits behind head on develop.

Files with missing lines Patch % Lines
...pp/lib/pages/prices/price_category_input_page.dart 0.92% 107 Missing ⚠️
...p/lib/pages/prices/price_existing_amount_card.dart 0.00% 26 Missing ⚠️
...ooth_app/lib/background/background_task_price.dart 0.00% 24 Missing ⚠️
...mooth_app/lib/pages/prices/price_meta_product.dart 0.00% 19 Missing ⚠️
...h_app/lib/pages/prices/price_add_product_card.dart 0.00% 12 Missing ⚠️
...smooth_app/lib/pages/prices/price_amount_card.dart 0.00% 11 Missing ⚠️
...kages/smooth_app/lib/pages/prices/price_model.dart 0.00% 8 Missing ⚠️
...ooth_app/lib/pages/prices/price_per_extension.dart 0.00% 6 Missing ⚠️
...ib/pages/input/smooth_autocomplete_text_field.dart 0.00% 5 Missing ⚠️
..._app/lib/pages/prices/price_product_list_tile.dart 0.00% 3 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #6552      +/-   ##
==========================================
- Coverage     9.54%   5.69%   -3.86%     
==========================================
  Files          325     512     +187     
  Lines        16411   30639   +14228     
==========================================
+ Hits          1567    1745     +178     
- Misses       14844   28894   +14050     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TTalex
Copy link
Collaborator

TTalex commented Apr 16, 2025

Very cool, some thoughts:

  • Maybe the "Enter a category" text can be replace with something like "Add a product without barcode" ? We have the same issue in prices web, the category term isn't clear for new users.
  • The API also supports fields like organic (is the product organic) and orgin (where is the product from). They aren't mandatory, but useful for data quality. Maybe something to add in a V2.
  • More of a taxonomy issue, but it would be nice to only suggest categories related to products without barcodes (fruits and vegetables)

@monsieurtanuki
Copy link
Contributor Author

Thank you @TTalex for your feedback!

Maybe the "Enter a category" text can be replace with something like "Add a product without barcode" ? We have the same issue in prices web, the category term isn't clear for new users.

I can do that.
Fun fact: yesterday I was in a French store (monoprix) and there were tourists trying to weight a melon on a machine. They couldn't find the "melon" button. I told the guy he won't manage to do that and he replied something like "but there's no barcode!". In that case the price was per unit. The concept of "no barcode" may indeed be relevant.

The API also supports fields like organic (is the product organic) and orgin (where is the product from). They aren't mandatory, but useful for data quality. Maybe something to add in a V2.

I'm not sure I'm going to do that right now, UX-wise.
I'm going to populate those extra fields, though, for internal reasons.

  • More of a taxonomy issue, but it would be nice to only suggest categories related to products without barcodes (fruits and vegetables)

I'm sure they sell "home-made muesli" so it wouldn't be a good idea to limit to fruits and vegetables.
As a matter of fact, my first addition was a fish.

Impacted files:
* `app_en.arb`: improved a label and added 3 labels
* `app_fr.arb`: improved a label and added 3 labels
* `background_task_add_other_price.dart`: now setting origins and labels
* `background_task_add_price.dart`: now setting origins and labels
* `background_task_price.dart`: now setting origins and labels
* `price_add_product_card.dart`: refactored as we now set origins too (in addition to just category)
* `price_category_input_page.dart`: refactored as we now set origins too (in addition to just category)
* `price_existing_amount_card.dart`: display origins too
* `price_meta_product.dart`: now setting and displaying origins too
* `price_model.dart`: we now set origins too, and prepared code for labels when ready on the "prices" side
* `price_product_list_tile.dart`: now displaying origins too
@monsieurtanuki
Copy link
Contributor Author

@TTalex Changed the label into "no barcode" and added origins.

@raphael0202 @raphodn @teolemon Something not working with the labels to tags conversion (prefixing with 2-letter iso code), for both "category" and "origins".
Sometimes it work, sometimes it doesn't.
I'm not even sure the taxonomy and the autocomplete share the same data:

new "no barcode" label new "origins" input
Screenshot_1745767113 Screenshot_1745767708
"category" autocomplete "origins" autocomplete
Screenshot_1745767127 Screenshot_1745767148
prices input when done
Screenshot_1745767179 Screenshot_1745767951

@monsieurtanuki
Copy link
Contributor Author

@teolemon ping

@teolemon
Copy link
Member

@g123k @monsieurtanuki ok to merge ?

@github-project-automation github-project-automation bot moved this from 💬 To discuss and validate to 🏗️ In Progress in 🤳🥫 The Open Food Facts mobile app (Android & iOS) May 16, 2025
@g123k
Copy link
Collaborator

g123k commented May 16, 2025

/gemini review

Honestly, this is just some spam

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for entering and storing category-based prices alongside barcode-based prices.

  • Introduces a new “category input” page and metadata in PriceMetaProduct
  • Extends the pricing model and background tasks to include category tags, origin tags, labels, and price-per units
  • Updates multiple UI cards and dropdowns to let users select categories and price-per units

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
smooth_dropdown.dart Added isExpanded flag to SmoothDropdownButton
price_product_list_tile.dart Conditionally show barcode and origin names
price_per_extension.dart Added PricePer extension for localized titles
price_model.dart Collected category/origin/label/price-per data in tasks
price_meta_product.dart New category constructor and related getters
price_existing_amount_field.dart Display localized short price-per suffix
price_existing_amount_card.dart Show saved category and origin alongside price
price_category_input_page.dart New page for entering/selecting a price category
smooth_autocomplete_text_field.dart Optional onSelected callback in autocomplete field
price_amount_model.dart Validation updated to allow category-only entries
price_amount_card.dart Category dropdown for selecting price-per unit
price_add_product_card.dart Added button to open category input page
background_task_price.dart Serialize/deserialize category/origin/label/price-per
background_task_add_price.dart Pass new metadata through to base task
background_task_add_other_price.dart Pass new metadata through to base task
app_fr.arb / app_en.arb Added localization keys for category and price-per
Comments suppressed due to low confidence (3)

packages/smooth_app/lib/pages/prices/price_amount_model.dart:63

  • [nitpick] The returned error message still says “no product” even when the issue may be a missing category. Consider updating the message to reflect that a category must be provided when no barcode is entered.
if (product.barcode.isEmpty && product.categoryTag.isEmpty) {

packages/smooth_app/lib/pages/prices/price_category_input_page.dart:21

  • New UI page PriceCategoryInputPage has no accompanying unit or widget tests. Adding tests would help prevent regressions in the category-entry flow.
class PriceCategoryInputPage extends StatefulWidget {

packages/smooth_app/lib/pages/prices/price_existing_amount_card.dart:36

  • Property name originsTags does not exist on PriceMetaProduct. The getter is named originTags, so this should be widget.price.originTags.
_originTags = widget.price.originsTags;

@raphael0202
Copy link
Collaborator

@raphael0202 @raphodn @teolemon Something not working with the labels to tags conversion (prefixing with 2-letter iso code), for both "category" and "origins".
Sometimes it work, sometimes it doesn't.
I'm not even sure the taxonomy and the autocomplete share the same data:

They should share the same data, we load it from the server regularly on Robotoff.

But there is definitely a bug on openfoodfacts-python, where the matching with xx: prefixes is not working. Thank you for bringing that up!

raphael0202 added a commit to openfoodfacts/open-prices that referenced this pull request Jun 2, 2025
@g123k
Copy link
Collaborator

g123k commented Jun 9, 2025

Sorry for the late review @monsieurtanuki.
Could you use in the new view SmoothCardWithRoundedHeader?

Screenshot 2025-06-09 at 08 41 55

It will have the same look'n'feel as the price addition.
Thanks 👍

@monsieurtanuki
Copy link
Contributor Author

Sorry for the late review @monsieurtanuki. Could you use in the new view SmoothCardWithRoundedHeader?

@g123k Thank your for your comment.
Assuming that it's the only "negative" comment you have about this PR, I'll be happy to code your suggestion in that PR if that PR gets approved first.
We're very close to my "Closing-as-stale after 2 months" policy. Again.

Copy link
Member

@teolemon teolemon left a comment

Choose a reason for hiding this comment

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

We can probably indeed survive visually until the next PR if that's the only thing left @monsieurtanuki @g123k

@teolemon teolemon merged commit 9db5c5e into openfoodfacts:develop Jun 12, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Done in 💸 Open Prices Jun 12, 2025
@teolemon
Copy link
Member

thank you for your patience @monsieurtanuki

@teolemon
Copy link
Member

and thanks for this nice addition for Open Prices :-)

@monsieurtanuki
Copy link
Contributor Author

Thank you @teolemon for your review!

@g123k Actually I was in the middle of coding your SmoothCardWithRoundedHeader suggestion:
Screenshot_1749745102
It looks like we'd be better off implementing other features too, like being able to delete an already selected value (here, 'France"), and I'm sure that while using this "no barcode product" feature we'll find other improvements.
I'm about to open an issue about it.

@monsieurtanuki
Copy link
Contributor Author

I've just created #6645.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autocomplete 🔁 Background tasks ✏️ Editing Many products are incomplete and don't have Nutri-Score, Eco-Score…so editing is important for users 🌐 l10n Prices
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Allow to add prices of products without barcode
6 participants