mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
[PUI] PO line item import (#7671)
* Fix typo * Adds new field to DataImportSession model - field_filters - Allows custom API field filters to be specified * Update serializer * Add button to import purchase order line items * Fix instance renderer * Make use of "filters" attribute * Specify default currency for import * Update serializer * Bump API version * Rename purchaseorderline -> purchaseorderlineitem
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
"""InvenTree API version information."""
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 224
|
||||
INVENTREE_API_VERSION = 225
|
||||
|
||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||
|
||||
|
||||
INVENTREE_API_TEXT = """
|
||||
v225 - 2024-07-17 : https://github.com/inventree/InvenTree/pull/7671
|
||||
- Adds "filters" field to DataImportSession API
|
||||
|
||||
v224 - 2024-07-14 : https://github.com/inventree/InvenTree/pull/7667
|
||||
- Add notes field to ManufacturerPart and SupplierPart API endpoints
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.14 on 2024-07-16 03:04
|
||||
|
||||
from django.db import migrations, models
|
||||
import importer.validators
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('importer', '0002_dataimportsession_field_overrides'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='dataimportsession',
|
||||
name='field_filters',
|
||||
field=models.JSONField(blank=True, null=True, validators=[importer.validators.validate_field_defaults], verbose_name='Field Filters'),
|
||||
),
|
||||
]
|
@ -32,8 +32,9 @@ class DataImportSession(models.Model):
|
||||
data_file: FileField for the data file to import
|
||||
status: IntegerField for the status of the import session
|
||||
user: ForeignKey to the User who initiated the import
|
||||
field_defaults: JSONField for field default values
|
||||
field_overrides: JSONField for field override values
|
||||
field_defaults: JSONField for field default values - provides a backup value for a field
|
||||
field_overrides: JSONField for field override values - used to force a value for a field
|
||||
field_filters: JSONField for field filter values - optional field API filters
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
@ -101,6 +102,13 @@ class DataImportSession(models.Model):
|
||||
validators=[importer.validators.validate_field_defaults],
|
||||
)
|
||||
|
||||
field_filters = models.JSONField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_('Field Filters'),
|
||||
validators=[importer.validators.validate_field_defaults],
|
||||
)
|
||||
|
||||
@property
|
||||
def field_mapping(self):
|
||||
"""Construct a dict of field mappings for this import session.
|
||||
|
@ -50,6 +50,7 @@ class DataImportSessionSerializer(InvenTreeModelSerializer):
|
||||
'column_mappings',
|
||||
'field_defaults',
|
||||
'field_overrides',
|
||||
'field_filters',
|
||||
'row_count',
|
||||
'completed_row_count',
|
||||
]
|
||||
@ -104,6 +105,19 @@ class DataImportSessionSerializer(InvenTreeModelSerializer):
|
||||
|
||||
return overrides
|
||||
|
||||
def validate_field_filters(self, filters):
|
||||
"""De-stringify the field filters."""
|
||||
if filters is None:
|
||||
return None
|
||||
|
||||
if type(filters) is not dict:
|
||||
try:
|
||||
filters = json.loads(str(filters))
|
||||
except:
|
||||
raise ValidationError(_('Invalid field filters'))
|
||||
|
||||
return filters
|
||||
|
||||
def create(self, validated_data):
|
||||
"""Override create method for this serializer.
|
||||
|
||||
|
@ -373,13 +373,13 @@ class PurchaseOrderLineItemSerializer(
|
||||
|
||||
fields = [
|
||||
'pk',
|
||||
'part',
|
||||
'quantity',
|
||||
'reference',
|
||||
'notes',
|
||||
'order',
|
||||
'order_detail',
|
||||
'overdue',
|
||||
'part',
|
||||
'part_detail',
|
||||
'supplier_part_detail',
|
||||
'received',
|
||||
@ -454,6 +454,14 @@ class PurchaseOrderLineItemSerializer(
|
||||
|
||||
return queryset
|
||||
|
||||
part = serializers.PrimaryKeyRelatedField(
|
||||
queryset=part_models.SupplierPart.objects.all(),
|
||||
many=False,
|
||||
required=True,
|
||||
allow_null=True,
|
||||
label=_('Supplier Part'),
|
||||
)
|
||||
|
||||
quantity = serializers.FloatField(min_value=0, required=True)
|
||||
|
||||
def validate_quantity(self, quantity):
|
||||
|
Reference in New Issue
Block a user