Open mordante opened 7 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.
Thanks for the review. I agree with the naming. The current code uses foreign_key and foreign_table for these fields.
@mordante Still up to doing this?
@mordante You still want to implement this?
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.
That would be cool, the ideas in this issue/feature is intriguing. Would be a nice feature to have i think.
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:
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:
The implementation details
Auxiliary table
There will be an auxiliary table with the following fields:
id
: The unique key.name
: The name of the item.unit
: An optional string containing the dimensions for the item. For example:The ingredient inventory table
This table will get one extra field:
minimum
: The minimum amount of this to be in the inventory. The reason to put it in this table is for the second stage of the project. For the first stage this field will only be editable in the shopping list. In the second stage it will also be available in the ingredient's editor dialogue.The Shopping list table
This will be a new table with the following fields:
id
L The unique key.table
: The foreign table we link to. This is one of:key
: Theid
of the record intable
.required
: The amount required for brewing.amount
: The amount to buy.When the user adds a recipe to the shopping list:
required
field.required
field.amount
required:amount' = required + minimum - inventory
amount'
is greater than 0 theamount
is not updated.amount
to the maximum ofamount
andamount'
.If the user manually modifies
required
,minimum
, orinventory
theamount
is updated with the same formula. It will never lower theamount
field. It is possible the user already adjusted theamount
to his/her wanted value. (When we add lot sizes in the second stage we can loweramount
.)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:
amount
in the record toinventory
.minimum
field in the inventory.The auxiliary table has no
inventory
andminimum
. For shopping list items from this table only theamount
field is available.The icing
User visible part
This stage involves the following features:
The implementation details
The ingredient inventory table
This table will get one extra field:
lot_size
: The ingredient will always be bought in a multiple of this value. (Obviously, unless zero.)The fields
minimum
andlot_size
will be shown in the appropriate editors. Editing theminimum
,lot_size
, orinventory
in the ingredient editors will also update theamount
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 theinventory
to 0. Theminimum
is1
so a new shopping list record is created to buy 1 new satchel. (Thelot_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 oflot_size
. It will now also lower the value. It is still possible to manually override theamount
, but a recalculation may lower it again.