mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Reference fields (#3267)
* Adds a configurable 'reference pattern' to the IndexingReferenceMixin class * Expand tests for reference_pattern validator: - Prevent inclusion of illegal characters - Prevent multiple groups of hash (#) characters - Add unit tests * Validator now checks for valid strftime formatter * Adds build order reference pattern * Adds function for creating a valid regex from the supplied pattern - More unit tests - Use it to validate BuildOrder reference field * Refactoring the whole thing again - try using python string.format * remove datetime-matcher from requirements.txt * Add some more formatting helper functions - Construct a regular expression from a format string - Extract named values from a string, based on a format string * Fix validator for build order reference field * Adding unit tests for the new format string functionality * Adds validation for reference fields * Require the 'ref' format key as part of a valid reference pattern * Extend format extraction to allow specification of integer groups * Remove unused import * Fix requirements * Add method for generating the 'next' reference field for a model * Fix function for generating next BuildOrder reference value - A function is required as class methods cannot be used - Simply wraps the existing class method * Remove BUILDORDER_REFERENCE_REGEX setting * Add unit test for build order reference field validation * Adds unit testing for extracting integer values from a reference field * Fix bugs from previous commit * Add unit test for generation of default build order reference * Add data migration for BuildOrder model - Update reference field with old prefix - Construct new pattern based on old prefix * Adds unit test for data migration - Check that the BuildOrder reference field is updated as expected * Remove 'BUILDORDER_REFERENCE_PREFIX' setting * Adds new setting for SalesOrder reference pattern * Update method by which next reference value is generated * Improved error handling in api_tester code * Improve automated generation of order reference fields - Handle potential errors - Return previous reference if something goes wrong * SalesOrder reference has now been updated also - New reference pattern setting - Updated default and validator for reference field - Updated serializer and API - Added unit tests * Migrate the "PurchaseOrder" reference field to the new system * Data migration for SalesOrder and PurchaseOrder reference fields * Remove PURCHASEORDER_REFERENCE_PREFIX * Remove references to SALESORDER_REFERENCE_PREFIX * Re-add maximum value validation * Bug fixes * Improve algorithm for generating new reference - Handle case where most recent reference does not conform to the reference pattern * Fixes for 'order' unit tests * Unit test fixes for order app * More unit test fixes * More unit test fixing * Revert behaviour for "extract_int" clipping function * Unit test value fix * Prevent build order notification if we are importing records
This commit is contained in:
@ -748,6 +748,7 @@ class BuildListTest(BuildAPITest):
|
||||
|
||||
Build.objects.create(
|
||||
part=part,
|
||||
reference="BO-0006",
|
||||
quantity=10,
|
||||
title='Just some thing',
|
||||
status=BuildStatus.PRODUCTION,
|
||||
@ -773,20 +774,23 @@ class BuildListTest(BuildAPITest):
|
||||
Build.objects.create(
|
||||
part=part,
|
||||
quantity=10,
|
||||
reference=f"build-000{i}",
|
||||
reference=f"BO-{i + 10}",
|
||||
title=f"Sub build {i}",
|
||||
parent=parent
|
||||
)
|
||||
|
||||
# And some sub-sub builds
|
||||
for sub_build in Build.objects.filter(parent=parent):
|
||||
for ii, sub_build in enumerate(Build.objects.filter(parent=parent)):
|
||||
|
||||
for i in range(3):
|
||||
|
||||
x = ii * 10 + i + 50
|
||||
|
||||
Build.objects.create(
|
||||
part=part,
|
||||
reference=f"{sub_build.reference}-00{i}-sub",
|
||||
reference=f"BO-{x}",
|
||||
title=f"{sub_build.reference}-00{i}-sub",
|
||||
quantity=40,
|
||||
title=f"sub sub build {i}",
|
||||
parent=sub_build
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user