Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build default location #7160

Merged
Merged
5 changes: 4 additions & 1 deletion src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""InvenTree API version information."""

# InvenTree API version
INVENTREE_API_VERSION = 195
INVENTREE_API_VERSION = 196
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""

INVENTREE_API_TEXT = """

v196 - 2024-05-05 : https://github.com/inventree/InvenTree/pull/7160
- Adds "location" field to BuildOutputComplete API endpoint

v195 - 2024-05-03 : https://github.com/inventree/InvenTree/pull/7153
- Fixes bug in BuildOrderCancel API endpoint

Expand Down
11 changes: 10 additions & 1 deletion src/backend/InvenTree/build/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def save(self, *args, **kwargs):
self.validate_reference_field(self.reference)
self.reference_int = self.rebuild_reference_field(self.reference)

# On first save (i.e. creation), run some extra checks
if self.pk is None:
# Set the destination location (if not specified)
if not self.destination:
self.destination = self.part.get_default_location()

try:
super().save(*args, **kwargs)
except InvalidMove:
Expand Down Expand Up @@ -682,10 +688,13 @@ def create_build_output(self, quantity, **kwargs):
"""
user = kwargs.get('user', None)
batch = kwargs.get('batch', self.batch)
location = kwargs.get('location', self.destination)
location = kwargs.get('location', None)
serials = kwargs.get('serials', None)
auto_allocate = kwargs.get('auto_allocate', False)

if location is None:
location = self.destination or self.part.get_default_location()

"""
Determine if we can create a single output (with quantity > 0),
or multiple outputs (with quantity = 1)
Expand Down
26 changes: 17 additions & 9 deletions src/backend/InvenTree/build/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@
help_text=_('Enter serial numbers for build outputs'),
)

location = serializers.PrimaryKeyRelatedField(
queryset=StockLocation.objects.all(),
label=_('Location'),
help_text=_('Stock location for build output'),
required=False, allow_null=True
)

def validate_serial_numbers(self, serial_numbers):
"""Clean the provided serial number string"""
serial_numbers = serial_numbers.strip()
Expand All @@ -310,6 +317,11 @@
quantity = data['quantity']
serial_numbers = data.get('serial_numbers', '')

if part.trackable and not serial_numbers:
raise ValidationError({

Check warning on line 321 in src/backend/InvenTree/build/serializers.py

View check run for this annotation

Codecov / codecov/patch

src/backend/InvenTree/build/serializers.py#L321

Added line #L321 was not covered by tests
'serial_numbers': _('Serial numbers must be provided for trackable parts')
})

if serial_numbers:

try:
Expand Down Expand Up @@ -346,19 +358,15 @@
"""Generate the new build output(s)"""
data = self.validated_data

quantity = data['quantity']
batch_code = data.get('batch_code', '')
auto_allocate = data.get('auto_allocate', False)

build = self.get_build()
user = self.context['request'].user

build.create_build_output(
quantity,
data['quantity'],
serials=self.serials,
batch=batch_code,
auto_allocate=auto_allocate,
user=user,
batch=data.get('batch_code', ''),
location=data.get('location', None),
auto_allocate=data.get('auto_allocate', False),
user=self.context['request'].user,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type ApiFormFieldType = {
description?: string;
preFieldContent?: JSX.Element;
postFieldContent?: JSX.Element;
onValueChange?: (value: any) => void;
onValueChange?: (value: any, record?: any) => void;
adjustFilters?: (value: ApiFormAdjustFilterType) => any;
headers?: string[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function RelatedModelField({
setPk(_pk);

// Run custom callback for this field (if provided)
definition.onValueChange?.(_pk);
definition.onValueChange?.(_pk, value.data ?? {});
},
[field.onChange, definition]
);
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/enums/ApiEndpoints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export enum ApiEndpoints {
// Build API endpoints
build_order_list = 'build/',
build_order_cancel = 'build/:id/cancel/',
build_output_create = 'build/:id/create-output/',
build_output_complete = 'build/:id/complete/',
build_output_scrap = 'build/:id/scrap-outputs/',
build_output_delete = 'build/:id/delete-outputs/',
build_order_attachment_list = 'build/attachment/',
build_line_list = 'build/line/',

Expand All @@ -64,6 +68,7 @@ export enum ApiEndpoints {
part_parameter_template_list = 'part/parameter/template/',
part_thumbs_list = 'part/thumbs/',
part_pricing_get = 'part/:id/pricing/',
part_serial_numbers = 'part/:id/serial-numbers/',
part_pricing_internal = 'part/internal-price/',
part_pricing_sale = 'part/sale-price/',
part_stocktake_list = 'part/stocktake/',
Expand Down
Loading
Loading