Ulugbek erkinov master (#5872)

* Remove stat context variables

* Revert "Remove stat context variables"

This reverts commit 0989c308d0.

* Allow longer timeout for image download tests

* fix: Adding specific quantity of a part as installed item(s

* fix: Adding specific quantity of a part as installed item(s

* Update serializers.py

* Mark field as not required

* If value not provided, revert to "default" behavior

* Fix serializer validation

* Update frontend forms to mach

* Bump API version

---------

Co-authored-by: Ulugbek Erkinov <ulugbekerkinov606@gmail.com>
This commit is contained in:
Oliver 2023-11-06 22:58:46 +11:00 committed by GitHub
parent 390906532e
commit 63edd39e2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 4 deletions

View File

@ -2,11 +2,14 @@
# InvenTree API version
INVENTREE_API_VERSION = 147
INVENTREE_API_VERSION = 148
"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about
v148 -> 2023-11-06 : https://github.com/inventree/InvenTree/pull/5872
- Allow "quantity" to be specified when installing an item into another item
v147 -> 2023-11-04: https://github.com/inventree/InvenTree/pull/5860
- Adds "completed_lines" field to SalesOrder API endpoint
- Adds "completed_lines" field to PurchaseOrder API endpoint

View File

@ -489,6 +489,14 @@ class InstallStockItemSerializer(serializers.Serializer):
help_text=_('Select stock item to install'),
)
quantity = serializers.IntegerField(
min_value=1,
default=1,
required=False,
label=_('Quantity to Install'),
help_text=_('Enter the quantity of items to install'),
)
note = serializers.CharField(
label=_('Note'),
help_text=_('Add transaction note (optional)'),
@ -496,26 +504,47 @@ class InstallStockItemSerializer(serializers.Serializer):
allow_blank=True,
)
def validate_quantity(self, quantity):
"""Validate the quantity value."""
if quantity < 1:
raise ValidationError(_("Quantity to install must be at least 1"))
return quantity
def validate_stock_item(self, stock_item):
"""Validate the selected stock item."""
if not stock_item.in_stock:
# StockItem must be in stock to be "installed"
raise ValidationError(_("Stock item is unavailable"))
# Extract the "parent" item - the item into which the stock item will be installed
parent_item = self.context['item']
parent_part = parent_item.part
# Check if the selected part is in the Bill of Materials of the parent item
if not parent_part.check_if_part_in_bom(stock_item.part):
raise ValidationError(_("Selected part is not in the Bill of Materials"))
return stock_item
def validate(self, data):
"""Ensure that the provided dataset is valid"""
stock_item = data['stock_item']
quantity = data.get('quantity', stock_item.quantity)
if quantity > stock_item.quantity:
raise ValidationError(_("Quantity to install must not exceed available quantity"))
return data
def save(self):
"""Install the selected stock item into this one."""
data = self.validated_data
stock_item = data['stock_item']
quantity_to_install = data.get('quantity', stock_item.quantity)
note = data.get('note', '')
parent_item = self.context['item']
@ -523,7 +552,7 @@ class InstallStockItemSerializer(serializers.Serializer):
parent_item.installStockItem(
stock_item,
stock_item.quantity,
quantity_to_install,
request.user,
note,
)

View File

@ -3217,6 +3217,12 @@ function installStockItem(stock_item_id, part_id, options={}) {
in_stock: true,
tracked: true,
},
onSelect: function(data, field, opts) {
// Adjust the 'quantity' field
if ('quantity' in data) {
updateFieldValue('quantity', data.quantity, opts);
}
},
adjustFilters: function(filters, opts) {
var part = getFormFieldValue('part', {}, opts);
@ -3226,7 +3232,8 @@ function installStockItem(stock_item_id, part_id, options={}) {
return filters;
}
}
},
quantity: {},
},
confirm: true,
title: '{% trans "Install Stock Item" %}',