2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Table custom buttons (#5075)

* Add generic implementation for barcode actions

- Commonize code against tables
- Cleaner UI
- Better code
- Will make future react refactor easier

* Add permissions.js

- Separate .js file for dynamically checking permissions

* Update stock table to use client-side actions

* API endpoint for bulk category adjustment

* Bug fix for purchase_order.js

- Prevent some really strange API calls

* Refactor actions for part table

- Now done dynamically

* Refactor actions for the attachment tables

* Refactor actions for build output table

* Increment API version

* Cleanup janky button

* Refactor supplier part table

* Refactor manufacturer part table

* Remove linkButtonsToSelection

- no longer needed
- Cleanup, yay!

* Cleanup purchase order line table

* Refactor BOM table buttons

* JS linting

* Further cleanup

* Template cleanup

- remove extra div elements

* js linting

* js fix
This commit is contained in:
Oliver
2023-06-20 07:45:35 +10:00
committed by GitHub
parent 13389845b1
commit 4c9d4add2c
43 changed files with 837 additions and 905 deletions

View File

@ -291,6 +291,56 @@ class PartBriefSerializer(InvenTree.serializers.InvenTreeModelSerializer):
pricing_max = InvenTree.serializers.InvenTreeMoneySerializer(source='pricing_data.overall_max', allow_null=True, read_only=True)
class PartSetCategorySerializer(serializers.Serializer):
"""Serializer for changing PartCategory for multiple Part objects"""
class Meta:
"""Metaclass options"""
fields = [
'parts',
'category',
]
parts = serializers.PrimaryKeyRelatedField(
queryset=Part.objects.all(),
many=True, required=True, allow_null=False,
label=_('Parts'),
)
def validate_parts(self, parts):
"""Validate the selected parts"""
if len(parts) == 0:
raise serializers.ValidationError(_("No parts selected"))
return parts
category = serializers.PrimaryKeyRelatedField(
queryset=PartCategory.objects.filter(structural=False),
many=False, required=True, allow_null=False,
label=_('Category'),
help_text=_('Select category',)
)
@transaction.atomic
def save(self):
"""Save the serializer to change the location of the selected parts"""
data = self.validated_data
parts = data['parts']
category = data['category']
parts_to_save = []
for p in parts:
if p.category == category:
continue
p.category = category
parts_to_save.append(p)
Part.objects.bulk_update(parts_to_save, ['category'])
class DuplicatePartSerializer(serializers.Serializer):
"""Serializer for specifying options when duplicating a Part.