2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Improvements for part creation API endpoint (#4281)

* Refactor javascript for creating a new part

* Simplify method of removing create fields from serializer

* Fix bug which resulted in multiple model instances being created

* remove custom code required on Part model

* Reorganize existing Part API test code

* Add child serializer for part duplication options

* Part duplication is now handled by the DRF serializer

- Improved validation options
- API is self-documenting (no more secret fields)
- More DRY

* Initial stock is now handled by the DRF serializer

* Adds child serializer for adding initial supplier data for a Part instance

* Create initial supplier and manufacturer parts as specified

* Adding unit tests

* Add unit tests for part duplication via API

* Bump API version

* Add javascript for automatically extracting info for nested fields

* Improvements for part creation form rendering

- Move to nested fields (using API metadata)
- Visual improvements
- Improve some field name / description values

* Properly format nested fields for sending to the server

* Handle error case for scrollIntoView

* Display errors for nested fields

* Fix bug for filling part category

* JS linting fixes

* Unit test fixes

* Fixes for unit tests

* Further fixes to unit tests
This commit is contained in:
Oliver
2023-02-02 09:24:16 +11:00
committed by GitHub
parent c6df0dbb2d
commit 4f029d4d81
15 changed files with 770 additions and 585 deletions

View File

@ -391,17 +391,6 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
# For legacy reasons the 'variant_of' field is used to indicate the MPTT parent
parent_attr = 'variant_of'
def __init__(self, *args, **kwargs):
"""Custom initialization routine for the Part model.
Ensures that custom serializer fields (without matching model fields) are removed
"""
# Remote image specified during creation via API
kwargs.pop('remote_image', None)
super().__init__(*args, **kwargs)
@staticmethod
def get_api_url():
"""Return the list API endpoint URL associated with the Part model"""
@ -2034,41 +2023,6 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
parameter.save()
@transaction.atomic
def deep_copy(self, other, **kwargs):
"""Duplicates non-field data from another part.
Does not alter the normal fields of this part, but can be used to copy other data linked by ForeignKey refernce.
Keyword Args:
image: If True, copies Part image (default = True)
bom: If True, copies BOM data (default = False)
parameters: If True, copies Parameters data (default = True)
"""
# Copy the part image
if kwargs.get('image', True):
if other.image:
# Reference the other image from this Part
self.image = other.image
# Copy the BOM data
if kwargs.get('bom', False):
self.copy_bom_from(other)
# Copy the parameters data
if kwargs.get('parameters', True):
self.copy_parameters_from(other)
# Copy the fields that aren't available in the duplicate form
self.salable = other.salable
self.assembly = other.assembly
self.component = other.component
self.purchaseable = other.purchaseable
self.trackable = other.trackable
self.virtual = other.virtual
self.save()
def getTestTemplates(self, required=None, include_parent=True):
"""Return a list of all test templates associated with this Part.