Brewtarget / brewtarget

Main brewtarget source code repository.
GNU General Public License v3.0
315 stars 134 forks source link

[RFC] Improve inventory management (long) #322

Open mordante opened 8 years ago

mordante commented 8 years ago

Introduction

This is a request for comment on the improvements I'd like to add the inventory management of Brewtarget. In short I'd like to be able to create a shopping list for one or more recipes and other items required. After buying the ingredients the amount in the inventory should be automatically updated. The goal of this RFC is to get feedback on the idea and possibly additional idea's. For example I originally wanted to buy for one recipe, but issue #188 already asks to buy for multiple recipes. It will be easier to implement these features when known upfront. (Just to be clear; I don't ask somebody to implement this feature, I just ask for feedback/hints. I will take care of the implementation myself.)

The proposal has two stages:

  1. The cake: This makes the inventory management functional. It will be completely usable, but some things could be better.
  2. The icing: This will make the inventory management even better. This part is a lot of work and I think having stage 1 is a huge improvement. So I'd like to finish that stage 1 first.

The noticeable missing part in this improvement is a way to show, print, or export your inventory. This is a feature I'm already working on and is rather straightforward.

The cake

User visible part

This stage involves the following features:

There will be an auxiliary table with the following fields:

This table will get one extra field:

This will be a new table with the following fields:

When the user adds a recipe to the shopping list:

If the user manually modifies required, minimum, or inventory the amount is updated with the same formula. It will never lower the amount field. It is possible the user already adjusted the amount to his/her wanted value. (When we add lot sizes in the second stage we can lower amount.)

In order to facilitate adding multiple recipes it still needs to add shopping list records which are completely in stock. After adding a second recipe the total amount required may be larger than the inventory. When the shopping list is printed or exported these 0 amount records are not shown.

When the user deletes an item from the shopping list the minimum in the inventory table will be set to 0. (This will not happen in stage 2. However in stage 1 the minimum acts like a part of the shopping list and not of the ingredient.) The minimum amount is still wanted in stage 1, since it makes sure it will not deplete certain ingredients. For example I like to keep a spare satchel of yeast, just in case my fermentation gets stuck. So if I happen to use the same yeast in a recipe I still want to buy a new one, despite having one in the fridge.

There will be a way to select multiple record and mark them as bought. This will:

The auxiliary table has no inventory and minimum. For shopping list items from this table only the amount field is available.

The icing

User visible part

This stage involves the following features:

This table will get one extra field:

The fields minimum and lot_size will be shown in the appropriate editors. Editing the minimum, lot_size, or inventory in the ingredient editors will also update the amount in the shopping list, and when necessary add a record to the shopping list. For example, my fermentation gets stuck and I use my emergency yeast satchel. I update the inventory to 0. The minimum is 1 so a new shopping list record is created to buy 1 new satchel. (The lot_size is 0.)

The Shopping list table

The table does not change much. The editor will now also display the lot_size from the inventory table.

When the amount is determined its value will be rounded up to the next multiple of lot_size. It will now also lower the value. It is still possible to manually override the amount, but a recalculation may lower it again.

mikfire commented 8 years ago

The design looks pretty solid to me. I have just one minor nit.

The only thing I can really suggest is could we use a different name for the foreign key in the shopping list table? "key" is similar (in my mind at least) to "id" and it doesn't immediately suggest it is a foreign key. I would be happy even with something like fkey.

It is, as I said, a minor nit.

mordante commented 8 years ago

Thanks for the review. I agree with the naming. The current code uses foreign_key and foreign_table for these fields.

pricelessbrewing commented 6 years ago

@mordante Still up to doing this?

mattiasmaahl commented 3 years ago

@mordante You still want to implement this?

matty0ung commented 3 years ago

I think the underlying data model has moved on a bit since the above conversation. That said, the new database layer I'm soon (hopefully!) backporting from Brewken will make extending inventory functionality a bit easier, as it creates an Inventory class.

mattiasmaahl commented 3 years ago

That would be cool, the ideas in this issue/feature is intriguing. Would be a nice feature to have i think.