2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-19 13:18:03 +00:00

Batch code generation (#7000)

* Refactor framework for generating batch codes

- Provide additional kwargs to plugin
- Move into new file
- Error handling

* Implement API endpoint for generating a new batch code

* Fixes

* Refactor into stock.generators

* Fix API endpoint

* Pass time context through to plugins

* Generate batch code when receiving items

* Create useGenerator hook

- Build up a dataset and query server whenever it changes
- Look for result in response data
- For now, just used for generating batch codes
- may be used for more in the future

* Refactor PurchaseOrderForms to use new generator hook

* Refactor StockForms implementation

* Remove dead code

* add OAS diff

* fix ref

* fix ref again

* wrong branch, sorry

* Update src/frontend/src/hooks/UseGenerator.tsx

Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com>

* Bump API version

* Do not override batch code if already generated

* Add serial number generator

- Move to /generate/ API endpoint
- Move batch code generator too

* Update PUI endpoints

* Add debouncing to useGenerator hook

* Refactor useGenerator func

* Add serial number generator to stock form

* Add batch code genereator to build order form

* Update buildfields

* Use build batch code when creating new output

---------

Co-authored-by: Matthias Mair <code@mjmair.com>
Co-authored-by: Lukas <76838159+wolflu05@users.noreply.github.com>
This commit is contained in:
Oliver
2024-05-20 23:56:45 +10:00
committed by GitHub
parent 5cb61d5ad0
commit e93d9c4a74
21 changed files with 513 additions and 64 deletions

View File

@@ -145,7 +145,17 @@ class SampleValidatorPlugin(SettingsMixin, ValidationMixin, InvenTreePlugin):
if len(batch_code) > 0 and prefix and not batch_code.startswith(prefix):
self.raise_error(f"Batch code must start with '{prefix}'")
def generate_batch_code(self):
def generate_batch_code(self, **kwargs):
"""Generate a new batch code."""
now = datetime.now()
return f'BATCH-{now.year}:{now.month}:{now.day}'
batch = f'SAMPLE-BATCH-{now.year}:{now.month}:{now.day}'
# If a Part instance is provided, prepend the part name to the batch code
if part := kwargs.get('part', None):
batch = f'{part.name}-{batch}'
# If a Build instance is provided, prepend the build number to the batch code
if build := kwargs.get('build_order', None):
batch = f'{build.reference}-{batch}'
return batch