mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Sales order barcode allocate (#6072)
* Bug fix for BarcodePOReceive endpoint - Existing scan must match "stockitem" to raise an error * bug fix: barcode.js - Handle new return data from barcode scan endpoint * Add barcode endpoint for allocating stock to sales order * Improve logic for preventing over allocation of stock item to sales order * Test for sufficient quantity * Bump API version * Bug fix and extra check * Cleanup unit tests * Add unit testing for new endpoint * Add blank page for app sales orders docs * Add docs for new barcode features in app * Fix unit tests * Remove debug statement
This commit is contained in:
@ -1106,7 +1106,7 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
|
||||
return total
|
||||
|
||||
def get_sales_order_allocations(self, active=True):
|
||||
def get_sales_order_allocations(self, active=True, **kwargs):
|
||||
"""Return a queryset for SalesOrderAllocations against this StockItem, with optional filters.
|
||||
|
||||
Arguments:
|
||||
@ -1114,6 +1114,12 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
"""
|
||||
query = self.sales_order_allocations.all()
|
||||
|
||||
if filter_allocations := kwargs.get('filter_allocations', None):
|
||||
query = query.filter(**filter_allocations)
|
||||
|
||||
if exclude_allocations := kwargs.get('exclude_allocations', None):
|
||||
query = query.exclude(**exclude_allocations)
|
||||
|
||||
if active is True:
|
||||
query = query.filter(
|
||||
line__order__status__in=SalesOrderStatusGroups.OPEN,
|
||||
@ -1128,9 +1134,9 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
|
||||
return query
|
||||
|
||||
def sales_order_allocation_count(self, active=True):
|
||||
def sales_order_allocation_count(self, active=True, **kwargs):
|
||||
"""Return the total quantity allocated to SalesOrders."""
|
||||
query = self.get_sales_order_allocations(active=active)
|
||||
query = self.get_sales_order_allocations(active=active, **kwargs)
|
||||
query = query.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||
|
||||
total = query['q']
|
||||
|
Reference in New Issue
Block a user