2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 03:56:43 +00:00
InvenTree/docs/docs/build/allocate.md
Oliver 6ba777d363
Build Order Updates (#4855)
* Add new BuildLine model

- Represents an instance of a BOM item against a BuildOrder

* Create BuildLine instances automatically

When a new Build is created, automatically generate new BuildLine items

* Improve logic for handling exchange rate backends

* logic fixes

* Adds API endpoints

Add list and detail API endpoints for new BuildLine model

* update users/models.py

- Add new model to roles definition

* bulk-create on auto_allocate

Save database hits by performing a bulk-create

* Add skeleton data migration

* Create BuildLines for existing orders

* Working on building out BuildLine table

* Adds link for "BuildLine" to "BuildItem"

- A "BuildItem" will now be tracked against a BuildLine
- Not tracked directly against a build
- Not tracked directly against a BomItem
- Add schema migration
- Add data migration to update links

* Adjust migration 0045

- bom_item and build fields are about to be removed
- Set them to "nullable" so the data doesn't get removed

* Remove old fields from BuildItem model

- build fk
- bom_item fk
- A lot of other required changes too

* Update BuildLine.bom_item field

- Delete the BuildLine if the BomItem is removed
- This is closer to current behaviour

* Cleanup for Build model

- tracked_bom_items -> tracked_line_items
- untracked_bom_items -> tracked_bom_items
- remove build.can_complete
- move bom_item specific methods to the BuildLine model
- Cleanup / consolidation

* front-end work

- Update javascript
- Cleanup HTML templates

* Add serializer annotation and filtering

- Annotate 'allocated' quantity
- Filter by allocated / trackable / optional / consumable

* Make table sortable

* Add buttons

* Add callback for building new stock

* Fix Part annotation

* Adds callback to order parts

* Allocation works again

* template cleanup

* Fix allocate / unallocate actions

- Also turns out "unallocate" is not a word..

* auto-allocate works again

* Fix call to build.is_over_allocated

* Refactoring updates

* Bump API version

* Cleaner implementation of allocation sub-table

* Fix rendering in build output table

* Improvements to StockItem list API

- Refactor very old code
- Add option to include test results to queryset

* Add TODO for later me

* Fix for serializers.py

* Working on cleaner implementation of build output table

* Add function to determine if a single output is fully allocated

* Updates to build.js

- Button callbacks
- Table rendering

* Revert previous changes to build.serializers.py

* Fix for forms.js

* Rearrange code in build.js

* Rebuild "allocated lines" for output table

* Fix allocation calculation

* Show or hide column for tracked parts

* Improve debug messages

* Refactor "loadBuildLineTable"

- Allow it to also be used as output sub-table

* Refactor "completed tests" column

* Remove old javascript

- Cleans up a *lot* of crusty old code

* Annotate the available stock quantity to BuildLine serializer

- Similar pattern to BomItem serializer
- Needs refactoring in the future

* Update available column

* Fix build allocation table

- Bug fix
- Make pretty

* linting fixes

* Allow sorting by available stock

* Tweak for "required tests" column

* Bug fix for completing a build output

* Fix for consumable stock

* Fix for trim_allocated_stock

* Fix for creating new build

* Migration fix

- Ensure initial django_q migrations are applied
- Why on earth is this failing now?

* Catch exception

* Update for exception handling

* Update migrations

- Ensure inventreesetting is added

* Catch all exceptions when getting default currency code

* Bug fix for currency exchange rates update

* Working on unit tests

* Unit test fixes

* More work on unit tests

* Use bulk_create in unit test

* Update required quantity when a BuildOrder is saved

* Tweak overage display in BOM table

* Fix icon in BOM table

* Fix spelling error

* More unit test fixes

* Build reports

- Add line_items
- Update docs
- Cleanup

* Reimplement is_partially_allocated method

* Update docs about overage

* Unit testing for data migration

* Add "required_for_build_orders" annotation

- Makes API query *much* faster now
- remove old "required_parts_to_complete_build" method
- Cleanup part API filter code

* Adjust order of fixture loading

* Fix unit test

* Prevent "schedule_pricing_update" in unit tests

- Should cut down on DB hits significantly

* Unit test updates

* Improvements for unit test

- Don't hard-code pk values
- postgresql no likey

* Better unit test
2023-06-13 20:18:32 +10:00

8.6 KiB

title
title
Build Allocation

Build Allocation

Allocating stock items to a build order signals an intent that those stock items will be removed from the InvenTree database once the build order is completed.

Depending on the particular requirements of the build, and your stock control setup, allocating stock items to a build can be a complex task. In this regard, InvenTree provides an allocation interface which attempts to keep the number of user interactions required to a minimum.

!!! warning "Build Completion" Marking a build as complete will remove allocated items from stock. This operation cannot be reversed, so take care!

Untracked vs Tracked Stock

Before continuing, it is important that the difference between untracked and tracked parts, as they impose different requirements when it comes to stock allocation.

Untracked Stock

Untracked stock items are consumed against the build order, once the order is completed. When a build order is completed, any allocated stock items which are not trackable are marked as consumed. These items remain in the InvenTree database, but are unavailable for use in any stock operations.

!!! info "Example: Untracked Parts" You require 15 x 47K resistors to make a batch of PCBs. You have a reel of 1,000 resistors which you allocate to the build. At completion of the build, the available stock quantity is reduced to 985.

Tracked Stock

Tracked stock items, on the other hand, require special attention. These are parts which we wish to track against specific build outputs. When the build order is completed, tracked stock items are installed within the assembled build output.

!!! info "Example: Tracked Parts" The assembled PCB (in the example above) is a trackable part, and is given a serial number #001. The PCB is then used to make a larger assembly in a subsequent build order. At the completion of that build order, the tracked PCB is installed in the assembly.

BOM Considerations

A Bill of Materials to generate an assembly may consist of a mixture of untracked and tracked components. The build order process can facilitate this, as documentated in the sections below.

Tracked Build Outputs

If a Build Order is created for an assembled part which is itself designed as trackable, some extra restrictions apply:

  • Build outputs must be single quantity
  • Build outputs must be serialized as they are created

Allocating Untracked Stock

Untracked stock items are allocated against the Build Order itself. We do not need to track which Build Output these items will be installed into, and so the allocation process can be simplified.

Navigate to the Allocate Stock tab to view the stock allocation table:

{% with id="build_allocate_detail", url="build/build_allocate_detail.png", description="Allocate stock" %} {% include "img.html" %} {% endwith %}

In this example, there are two BOM line items which have been partially allocated to the build. Each line has a progress bar indicating how much of the required stock has been allocated.

In each row, pressing the icon expands the row, showing a list of stock items which have been allocated against this build.

!!! info "Multiple Allocations" Note that multiple stock items can be allocated to the given BOM line, if a single stock item does not have sufficient stock

{% with id="build_allocation_expand", url="build/build_allocation_expand.png", description="Allocate expand" %} {% include "img.html" %} {% endwith %}

Manual Stock Allocation

For each line in the BOM, stock will be automatically allocated if one (and only one) stock item (for the referenced part) is found (within the specified source location for the build):

Selecting Allocate Stock opens a dialog window which displays the stock items which will be allocated to the build during the auto allocation process:

{% with id="build_auto", url="build/build_auto_allocate.png", description="Auto allocate" %} {% include "img.html" %} {% endwith %}

Note here that there are two parts in the BOM which can be automatically allocated, as they only have a single corresponding StockItem available. However the other BOM line item exists in multiple locations, and thus cannot be automatically allocated. These will need to be manually selected by the user.

Row Allocation

Stock can be manually allocated to the build as required, using the Allocate stock button available in each row of the allocation table

Edit Allocations

Stock allocations can be manually adjusted or deleted using the action buttons available in each row of the allocation table.

Deallocate Stock

The Deallocate Stock button can be used to remove all allocations of untracked stock items against the build order.

Automatic Stock Allocation

To speed up the allocation process, the Auto Allocate button can be used to allocate untracked stock items to the build. Automatic allocation of stock items does not work in every situation, as a number of criteria must be met.

The Automatic Allocation dialog is presented as shown below:

{% with id="auto_allocate_dialog", url="build/auto_allocate_dialog.png", description="Automatic allocation dialog" %} {% include "img.html" %} {% endwith %}

Source Location

Select the master location where stock items are to be allocated from. Leave this input blank to allocate stock items from any available location.

Interchangeable Stock

Set this option to True to signal that stock items can be used interchangeably. This means that in the case where multiple stock items are available, the auto-allocation routine does not care which stock item it uses.

!!! warning "Take Care" If the Interchangeable Stock option is enabled, and there are multiple stock items available, the results of the automatic allocation algorithm may somewhat unexpected.

!!! info "Example" Let's say that we have 5 reels of our C_100nF_0603 capacitor, each with 4,000 parts available. If we do not mind which of these reels the stock should be taken from, we enable the Interchangeable Stock option in the dialog above. In this case, the stock will be allocated from one of these reels, and eventually subtracted from stock when the build is completed.

Substitute Stock

Set this option to True to allow substitute parts (as specified by the BOM) to be allocated, if the primary parts are not available.

Allocating Tracked Stock

Allocation of tracked stock items is slightly more complex. Instead of being allocated against the Build Order, tracked stock items must be allocated against an individual Build Output.

Allocating tracked stock items to particular build outputs is performed in the Pending Items tab:

In the Pending Items tab, we can see that each build output has a stock allocation requirement which must be met before that build output can be completed:

{% with id="build_allocate_tracked_parts", url="build/build_allocate_tracked_parts.png", description="Allocate tracked parts" %} {% include "img.html" %} {% endwith %}

Here we can see that the incomplete build outputs (serial numbers 15 and 14) now have a progress bar indicating the status of tracked stock item allocation:

  • Serial number 15 has been fully allocated, and can be completed
  • Serial number 14 has not been fully allocated, and cannot yet be completed

Allocated Stock

Tracked stock items which are allocated against the selected build output will be removed from stock, and installed "inside" the output assembly. The allocated stock items will still exist in the InvenTree database, however will no longer be available for regular stock actions.

!!! note "Example: Tracked Stock" Let's say we have 5 units of "Tracked Part" in stock - with 1 unit allocated to the build output. Once we complete the build output, there will be 4 units of "Tracked Part" in stock, with 1 unit being marked as "installed" within the assembled part

Completing a Build

!!! warning "Complete Build Outputs" A build order cannot be completed if there are outstanding build outputs. Ensure that all build outputs are completed first.

Once all build outputs have been completed, the build order itself can be completed by selecting the Complete Build button:

{% with id="build_complete", url="build/complete_build.png", description="Complete build order" %} {% include "img.html" %} {% endwith %}

Allocated Stock

All untracked stock items which are allocated against this build will be removed from stock, and consumed by the build order. These consumed items can be later viewed in the consumed stock tab.