You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FR] Allocate "untracked stock" to build order #3012
When "untracked" stock items (e.g. fungible parts such as capacitors, connectors, screws, etc) are allocated to a build order, the required stock quantity is depleted when the build is completed. The removed quantity is currently deleted from the database, and there is no way of tracking which batches of stock were consumed to fulfil a particular BuildOrder
Proposed Change
When a BuildOrder is "completed", any allocated stock items which are not tracked are marked as "consumed by" the build. The stock item data remains in the database, but those stock items are not available for further use.
This allows us to go back over time and look at stock consumption information for a particular build order.
Considerations
Adds a new field on a StockItem to indicate it has been consumed by a BuildOrder
When the BuildOrder is deleted, any consumed_by items must also be deleted
How about just using the existing StockItemTracking model with enhanced metadata for this, as is already done with purchase orders?
E.g. putting a reference to the build order into the tracking entry that is created when the item is consumed, that seems more flexible than a field on the stock item itself, since it allows the stock item to be partially consumed by multiple builds - I think if you added a field on the stockitem itself, you'd have to split the item each time a build order consumes some of it, etc.
See what you think of the commit above - I won't open a pull request yet, just an experiment for now... but if you like the approach I can tidy it up and open a request.
@mattbnz that pretty much matches the intent with the metadata in that model. Looks great!
Feel free to just open draft PRs if you are working on stuff. That way everyone knows and we can use gitpod.io to easily test the system in a production like environment.
@mattbnz I like the idea and your approach is clean, and I think that it forms part of what is needed here.
I think if you added a field on the stockitem itself, you'd have to split the item each time a build order consumes some of it, etc.
Yep, you absolutely would have to do this. The idea here does present more "work" for the system, but it allows better traceability through the system. Say you need to find out where a reel of dodgy capacitors ended up.. Currently, the stock is just invisibly "consumed" (once it is used up, it is deleted). The new approach does not delete the stock, it splits into a new database entry which is assigned to the build.
I'm enjoying a long weekend her in NZ and have a few things on early next week, but I'm happy to have a look at reworkign this further later next week.
So if you want that splitting behaviour and the more explicit tracking it provides, why not just make the parts trackable? Doesn't that already give the precise functionality that you're looking for here?
I assume the answer is that the current trackable implementation, while functionally a match for this use-case, adds too much usability overhead for non-serialized parts - because while a trackable part doesn't explicitly require a serialized stock item today - the UI basically assumes trackable parts will be serialized and requires you to explicitly allocate them to build outputs, etc, so the current trackable imlplementation is too painful to use for resistors/caps, etc even though it would perfecrtly match the desired functionality here at the DB level. (FWIW, this mismatch between trackable/serialized actually caught me out - where I marked parts as trackable, and then forgot to serialize them in the PO and got into a mess... I have a branch with a half-thought fix for that from a month or so ago acutally - https://github.com/mattbnz/InvenTree/tree/enforce-trackable-serials)
Have I missed anything else that makes the code powering trackable more distinct from what's being considered here other than the usability/UI of the current feature?
Given that, my thought would be to actually make "trackable" and "serialized' proper concepts at the part level, and then flow that through consistently, rather than the current trackable/serializable terminology being somewhat interdepedent.
trackable parts get all the splitting/association logic, but none of the integer quantity/uniqueness/manual allocation logic.
serialized parts are trackable (enforced), and add the integer/serial number/manual allocation logic.
At allocation time:
trackable (but not serialized) parts are assigned to the build (and can be auto-assigned) as per "normal" logic.
serialized parts must be assigned manually to each build output (as per current workflow)
At build output completion time
no changes for trackable parts (remain associated to the build)
serialized parts are (split, if required, and then) installed into the new stock items (as trackable parts are today)
At build completion time
trackable parts are split, marked as "consumed" (not deleted) and remain associated to the build (but not installed into stock items)
Post Build
for a given stock-item
serialized parts can be accessed directly via installed_items
tracked parts can be accessed indirectly via the associated build
add a new "trackable" bool to Part - turns on only the splitting behaviour described above, does not require integer quantities, uniqueness, or installation into output stock items.
Thoughts?
Variations/Open Questions
tracked/untracked/serialized - the above proposal has 3 types of stock, an alternate would be to simply change the default behaviour and make every part tracked by default. Obviously reduces a bit of code, but mostly it's a UI/UX simplification. I don't have a strong personal preference in general - but I feel like leaving the default behaviour unchanged and upgrading the current trackable to serialized, and then introducing a new concept of trackable, provides much more tenable migration/backwards compatibility path than trying to change the overall default... but YMMV.
always install trackable items - for simplicity, you could install both trackable and serializable items rather than adding a new association between the trackable SI and the build - so installed items could be singular (serialized), or multiple (tracked) within a particular stock titem. The main benefit being you get a direct link between stock items used/contained and avoid introducing a new build<->stock item relationship that you have to indirect through to find the parts used in a stock item, or vice versa (SIs using a specific part), but at the cost of more splitting/DB rows... doesn't seem worthwhile trade-off to me, but again YMMV
@mattbnz Comment: I love how detailed and clear you listed the thought process and workflow!
Questions:
I would strongly prefer 3 types as migrations are cleaner
Intresting potential problem; I think the stock endpoint could optionally contain a list of all tracking info (maybe with a enum off, ids, full stock items); I would not do that on a db level but as a cacheable lookup.
Activity
matmair commentedon Jun 6, 2022
@SchrodingersGat I think an option to 'recycle' already consumed parts would be also good.
mattbnz commentedon Jun 22, 2022
How about just using the existing StockItemTracking model with enhanced metadata for this, as is already done with purchase orders?
E.g. putting a reference to the build order into the tracking entry that is created when the item is consumed, that seems more flexible than a field on the stock item itself, since it allows the stock item to be partially consumed by multiple builds - I think if you added a field on the stockitem itself, you'd have to split the item each time a build order consumes some of it, etc.
mattbnz commentedon Jun 23, 2022
See what you think of the commit above - I won't open a pull request yet, just an experiment for now... but if you like the approach I can tidy it up and open a request.
matmair commentedon Jun 23, 2022
@mattbnz that pretty much matches the intent with the metadata in that model. Looks great!
Feel free to just open draft PRs if you are working on stuff. That way everyone knows and we can use gitpod.io to easily test the system in a production like environment.
SchrodingersGat commentedon Jun 24, 2022
@mattbnz I like the idea and your approach is clean, and I think that it forms part of what is needed here.
Yep, you absolutely would have to do this. The idea here does present more "work" for the system, but it allows better traceability through the system. Say you need to find out where a reel of dodgy capacitors ended up.. Currently, the stock is just invisibly "consumed" (once it is used up, it is deleted). The new approach does not delete the stock, it splits into a new database entry which is assigned to the build.
mattbnz commentedon Jun 25, 2022
I'm enjoying a long weekend her in NZ and have a few things on early next week, but I'm happy to have a look at reworkign this further later next week.
matmair commentedon Jun 25, 2022
@mattbnz sounds nice, enjoy!
mattbnz commentedon Aug 9, 2022
So if you want that splitting behaviour and the more explicit tracking it provides, why not just make the parts trackable? Doesn't that already give the precise functionality that you're looking for here?
I assume the answer is that the current trackable implementation, while functionally a match for this use-case, adds too much usability overhead for non-serialized parts - because while a trackable part doesn't explicitly require a serialized stock item today - the UI basically assumes trackable parts will be serialized and requires you to explicitly allocate them to build outputs, etc, so the current trackable imlplementation is too painful to use for resistors/caps, etc even though it would perfecrtly match the desired functionality here at the DB level. (FWIW, this mismatch between trackable/serialized actually caught me out - where I marked parts as trackable, and then forgot to serialize them in the PO and got into a mess... I have a branch with a half-thought fix for that from a month or so ago acutally - https://github.com/mattbnz/InvenTree/tree/enforce-trackable-serials)
Have I missed anything else that makes the code powering trackable more distinct from what's being considered here other than the usability/UI of the current feature?
Given that, my thought would be to actually make "trackable" and "serialized' proper concepts at the part level, and then flow that through consistently, rather than the current trackable/serializable terminology being somewhat interdepedent.
At allocation time:
At build output completion time
At build completion time
Post Build
Key model changes
Thoughts?
Variations/Open Questions
tracked/untracked/serialized - the above proposal has 3 types of stock, an alternate would be to simply change the default behaviour and make every part tracked by default. Obviously reduces a bit of code, but mostly it's a UI/UX simplification. I don't have a strong personal preference in general - but I feel like leaving the default behaviour unchanged and upgrading the current trackable to serialized, and then introducing a new concept of trackable, provides much more tenable migration/backwards compatibility path than trying to change the overall default... but YMMV.
always install trackable items - for simplicity, you could install both trackable and serializable items rather than adding a new association between the trackable SI and the build - so installed items could be singular (serialized), or multiple (tracked) within a particular stock titem. The main benefit being you get a direct link between stock items used/contained and avoid introducing a new build<->stock item relationship that you have to indirect through to find the parts used in a stock item, or vice versa (SIs using a specific part), but at the cost of more splitting/DB rows... doesn't seem worthwhile trade-off to me, but again YMMV
matmair commentedon Aug 9, 2022
@mattbnz Comment: I love how detailed and clear you listed the thought process and workflow!
Questions:
SchrodingersGat commentedon May 15, 2023
@matmair @mattbnz took a while but there's an implementation of this incoming - #4817