georgegebbett / recipe-buddy

Recipe Buddy is a tool that enables the easy adding of recipes to Grocy through web scraping.
GNU General Public License v3.0
172 stars 29 forks source link

Adding Item Displays Wrong Calories/Cost #483

Open Bovive opened 7 months ago

Bovive commented 7 months ago

This one is a bit unusual, and it took me a while to narrow down how it is occurring. One of my products is a stick of butter. It is 1 lb and the calories is 1,920 kcal/pound. If I use Recipe Buddy to import a recipe that uses a stick of butter, the calories are displayed as 1,920 regardless of the quantity that is entered. For example, if I enter 4 tablespoons, it displays at 1,920 kcal on the recipe page. If I edit the amount it still displays incorrectly, even if I change it to teaspoons. If I delete the stick of butter entirely from the recipe and then reenter it in Grocy, the calories and cost are displayed correctly.

I'm not sure where the value for the cost is coming from. It says $12.64 for 4 tablespoons of butter when I import it using Recipe Buddy. When I delete and renter it, the cost changes to $0.40.

Another example is shredded cheddar cheese: Imported: 880 kcal Reentered: 440 kcal

It does not seem to affect every item, but I am unable to find a commonality amongst the items that are affected.

georgegebbett commented 7 months ago

Hmm - what version of Grocy are you seeing this on? I know there were big changes to how quantity units and conversions between them are handled in Grocy v4, and I've only just started using v4 myself at home so haven't noticed much like this (also we aren't big users of the cost/calorie tracking lol). It might be down to this, I will do some digging.

Bovive commented 7 months ago

My Grocy version is 4.2.0. Much appreciated!

georgegebbett commented 7 months ago

Okay I have a feeling I know what causes this - I assume you have quantity unit equivalences set up between your stock unit of butter (presumably lbs) and the recipe unit (ozs)?

RB is currently set up so that if your recipe doesn't use the standard quantity unit for an ingredient, it is sent over the wire with the Only check if any amount is in stock flag set to true.

image

This then results in the cost/calorie values being the value for one stock quantity unit multiplied by the ingredient quantity - in this Grocy instance, 1 bottle of Prosecco is 100cal, and it has been multiplied by 500 to get 50,000cal for the 500ml!

image

This is definitely fixable but will require a bit of an overhaul of the way quantity units are put in the UI because if you don't set the only check if any amount flag to true you will get an error for ingredients that don't have a QU mapping set up, so it becomes necessary to ensure that only appropriate QUs are displayed.

This was more obvious in V1 of RB but was sacrificed to the redesign...

Bovive commented 7 months ago

Yup, you are absolutely correct. I tested a couple more recipes and that is exactly what is occurring. I appreciate you taking a look into this. On the bright side, only showing appropriate QUs in the UI is kind of a nice feature to have anyway.