custom-components / grocy

Custom Grocy integration for Home Assistant
Apache License 2.0
163 stars 50 forks source link

Shopping list quantity is in the wrong units #315

Open BenBergman opened 14 hours ago

BenBergman commented 14 hours ago

Unless all relevant information is provided, I can't help you

Describe the bug When viewing the shopping list in Grocy, the correct units are used for quantity (ie. "Default quantity unit purchase"). image

image

In the shopping list attributes, the unit used is the "Quantity unit stock" (see the 'amount' field).

{'id': 1, 'product_id': 2, 'amount': 60.0, 'note': None, 'product': {'name': 'Nature Clean Natural Dishwasher Pods, 60 count', 'id': 2, 'product_group_id': 2, 'available_amount': 0.0, 'amount_aggregated': None, 'amount_opened': None, 'amount_opened_aggregated': None, 'is_aggregated_amount': None, 'best_before_date': None, 'barcodes': ['058951380207'], 'product_barcodes': [{'barcode': '058951380207'}], 'amount_missing': None, 'is_partly_in_stock': None, 'default_quantity_unit_purchase': {'id': 3, 'name': 'Pack', 'name_plural': 'Packs', 'description': None}}}

When I change the "Quantity unit stock" to match "Default quantity unit purchase", the amount displayed is as I would expect.

Expected behavior The amount for the shopping list item should match the shopping list in Grocy UI, ie. it should be in the "Default quantity unit purchase" unit, or at the very least have this added as on additional field.

To Reproduce

  1. Create a product in Grocy and use different units for "Quantity unit stock" and "Default quantity unit purchase".
  2. Add the product to your shopping list
  3. Compare the amount in the Grocy UI for the shopping list and the products attribute of sensor.grocy_shopping_list

General information to help debugging:

Core 2024.11.3 Supervisor 2024.11.4 Operating System 13.2 Frontend 20241106.2

Grocy 4.2.0 (installed as add-on) Grocy custom component 4.11.1

BenBergman commented 14 hours ago

This might be an issue with the Grocy API. Playing with the API explorer, I see the "wrong" amount when I get the shopping list through the API at http://<grocy_ip>:9192/api/objects/shopping_list. I'll dig around the API a bit more and see if the "correct" value is available.

BenBergman commented 13 hours ago

I opened an issue with upstream Grocy as the API seems to be reporting the same incorrect values. This integration has more detailed info in the shopping list attributes so there must be more than just returning the raw API results so I'll leave this as open for now in case it makes sense to patch around it here, but odds are it makes more sense to wait for the upstream fix.

BenBergman commented 1 hour ago

From that other ticket it sounds like I misunderstood how the Grocy API works and there is no bug there.

Since this integration seems to be returning more than just the results of a single API call, could a field be added with the amount in the purchase quantity? I had a hard time finding the right place for this when I dug through the code yesterday, but if I find some time I'll try to poke at it a bit myself.

Edit: if adding a "purchase amount" field is undesirable, at least having a field in the product for the stock quantity unit so a conversion can be looked up would be nice.