Skip to content

[FR] Allocate "untracked stock" to build order #3012

Closed

Description

@SchrodingersGat

Current Behaviour

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
  • Add unit testing

Activity

  1. added
    enhancement
    build
    roadmap
    on May 16, 2022
  2. added this to the 0.8.0 milestone on May 16, 2022
  3. matmair commented on Jun 6, 2022

    @matmair
    Member

    @SchrodingersGat I think an option to 'recycle' already consumed parts would be also good.

  4. modified the milestones: 0.8.0, 0.9.0 on Jun 18, 2022
  5. mattbnz commented on Jun 22, 2022

    @mattbnz
    Contributor

    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.

  6. mattbnz commented on Jun 23, 2022

    @mattbnz
    Contributor

    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.

  7. matmair commented on Jun 23, 2022

    @matmair
    Member

    @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.

  8. SchrodingersGat commented on Jun 24, 2022

    @SchrodingersGat
    MemberAuthor

    @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.

  9. mattbnz commented on Jun 25, 2022

    @mattbnz
    Contributor

    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.

  10. matmair commented on Jun 25, 2022

    @matmair
    Member

    @mattbnz sounds nice, enjoy!

  11. mattbnz commented on Aug 9, 2022

    @mattbnz
    Contributor

    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

    Key model changes

    Thoughts?

    Variations/Open Questions

    1. 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.

    2. 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

  12. matmair commented on Aug 9, 2022

    @matmair
    Member

    @mattbnz Comment: I love how detailed and clear you listed the thought process and workflow!
    Questions:

    1. I would strongly prefer 3 types as migrations are cleaner
    2. 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.
  13. removed this from the 0.9.0 milestone on Oct 20, 2022
  14. added this to the 0.10.0 milestone on Nov 22, 2022
  15. modified the milestones: 0.10.0, 0.11.0 on Feb 2, 2023
  16. modified the milestones: 0.11.0, 0.12.0 on Apr 12, 2023
  17. SchrodingersGat commented on May 15, 2023

    @SchrodingersGat
    MemberAuthor

    @matmair @mattbnz took a while but there's an implementation of this incoming - #4817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buildenhancementroadmap

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions