mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-04 06:00:38 +00:00
Stocktake exporter updates (#12179)
* Optionally exclude zero-stock entries * Add more columns to exported dataset * Adjust unit test * More test fixes
This commit is contained in:
@@ -29,7 +29,13 @@ class PartStocktakeExportOptionsSerializer(serializers.Serializer):
|
||||
export_include_variant_items = serializers.BooleanField(
|
||||
default=False,
|
||||
label=_('Include Variant Items'),
|
||||
help_text=_('Include part variant stock in pricing calculations'),
|
||||
help_text=_('Include part variant stock in stocktake data'),
|
||||
)
|
||||
|
||||
export_exclude_zero_stock_entries = serializers.BooleanField(
|
||||
default=False,
|
||||
label=_('Exclude Zero Stock Entries'),
|
||||
help_text=_('Exclude parts with zero stock from the exported dataset'),
|
||||
)
|
||||
|
||||
|
||||
@@ -43,7 +49,7 @@ class PartStocktakeExporter(DataExportMixin, InvenTreePlugin):
|
||||
SLUG = 'inventree-stocktake-exporter'
|
||||
TITLE = _('Part Stocktake Exporter')
|
||||
DESCRIPTION = _('Exporter for part stocktake data')
|
||||
VERSION = '1.0.0'
|
||||
VERSION = '1.1.0'
|
||||
AUTHOR = _('InvenTree contributors')
|
||||
|
||||
ExportOptionsSerializer = PartStocktakeExportOptionsSerializer
|
||||
@@ -78,6 +84,9 @@ class PartStocktakeExporter(DataExportMixin, InvenTreePlugin):
|
||||
'pk',
|
||||
'name',
|
||||
'IPN',
|
||||
'active',
|
||||
'component',
|
||||
'assembly',
|
||||
'description',
|
||||
'category',
|
||||
'allocated_to_build_orders',
|
||||
@@ -124,12 +133,14 @@ class PartStocktakeExporter(DataExportMixin, InvenTreePlugin):
|
||||
export_pricing_data = context.get('export_pricing_data', True)
|
||||
include_external_items = context.get('export_include_external_items', False)
|
||||
include_variant_items = context.get('export_include_variant_items', False)
|
||||
exclude_zero_stock = context.get('export_exclude_zero_stock_entries', False)
|
||||
|
||||
data = super().export_data(
|
||||
queryset, serializer_class, headers, context, output, **kwargs
|
||||
)
|
||||
|
||||
if export_pricing_data:
|
||||
output_data = []
|
||||
|
||||
for row in data:
|
||||
quantity = Decimal(row.get('total_in_stock', 0))
|
||||
|
||||
@@ -142,8 +153,16 @@ class PartStocktakeExporter(DataExportMixin, InvenTreePlugin):
|
||||
if quantity < 0:
|
||||
quantity = Decimal(0)
|
||||
|
||||
pricing_min = row.get('pricing_min', None)
|
||||
pricing_max = row.get('pricing_max', None)
|
||||
if exclude_zero_stock:
|
||||
continue
|
||||
|
||||
if export_pricing_data:
|
||||
pricing_min = row.get('pricing_min', None) or row.get(
|
||||
'pricing_max', None
|
||||
)
|
||||
pricing_max = row.get('pricing_max', None) or row.get(
|
||||
'pricing_min', None
|
||||
)
|
||||
|
||||
if pricing_min is not None:
|
||||
pricing_min = Decimal(pricing_min)
|
||||
@@ -157,4 +176,6 @@ class PartStocktakeExporter(DataExportMixin, InvenTreePlugin):
|
||||
pricing_max * quantity, rounding=10
|
||||
)
|
||||
|
||||
return data
|
||||
output_data.append(row)
|
||||
|
||||
return output_data
|
||||
|
||||
@@ -37,7 +37,7 @@ class StocktakeExporterTest(InvenTreeAPITestCase):
|
||||
'Minimum Unit Cost',
|
||||
'Maximum Total Cost',
|
||||
],
|
||||
excluded_cols=['Active', 'External Stock', 'Variant Stock'],
|
||||
excluded_cols=['External Stock', 'Variant Stock'],
|
||||
)
|
||||
|
||||
# Now, with additional parameters specific to the plugin
|
||||
@@ -60,7 +60,6 @@ class StocktakeExporterTest(InvenTreeAPITestCase):
|
||||
'External Stock',
|
||||
'Variant Stock',
|
||||
],
|
||||
excluded_cols=['Active'],
|
||||
)
|
||||
|
||||
# Finally, exclude pricing data entirely
|
||||
|
||||
Reference in New Issue
Block a user