mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-11 07:24:15 +00:00
Sales Order Allocation Improvements (#4556)
* Do not remove sales order allocations when returning an item against a return order * Also do not clear allocations when returning manually * stock item display tweaks * Add extra column to sales order allocation table * Improve methods for introspecting sales order allocations for stockitems * Only display "active" sales order allocations on a stock item detail page - All allocations are still visible in the allocation table * Can't have available quantity if you're not available tap's side of nose
This commit is contained in:
@ -33,7 +33,8 @@ from InvenTree.fields import (InvenTreeModelMoneyField, InvenTreeNotesField,
|
||||
InvenTreeURLField)
|
||||
from InvenTree.models import (InvenTreeAttachment, InvenTreeBarcodeMixin,
|
||||
InvenTreeTree, extract_int)
|
||||
from InvenTree.status_codes import StockHistoryCode, StockStatus
|
||||
from InvenTree.status_codes import (SalesOrderStatus, StockHistoryCode,
|
||||
StockStatus)
|
||||
from part import models as PartModels
|
||||
from plugin.events import trigger_event
|
||||
from plugin.models import MetadataMixin
|
||||
@ -1013,7 +1014,6 @@ class StockItem(InvenTreeBarcodeMixin, MetadataMixin, common.models.MetaMixin, M
|
||||
location=location
|
||||
)
|
||||
|
||||
self.clearAllocations()
|
||||
self.customer = None
|
||||
self.belongs_to = None
|
||||
self.sales_order = None
|
||||
@ -1059,9 +1059,33 @@ class StockItem(InvenTreeBarcodeMixin, MetadataMixin, common.models.MetaMixin, M
|
||||
|
||||
return total
|
||||
|
||||
def sales_order_allocation_count(self):
|
||||
def get_sales_order_allocations(self, active=True):
|
||||
"""Return a queryset for SalesOrderAllocations against this StockItem, with optional filters.
|
||||
|
||||
Arguments:
|
||||
active: Filter by 'active' status of the allocation
|
||||
"""
|
||||
query = self.sales_order_allocations.all()
|
||||
|
||||
if active is True:
|
||||
query = query.filter(
|
||||
line__order__status__in=SalesOrderStatus.OPEN,
|
||||
shipment__shipment_date=None
|
||||
)
|
||||
elif active is False:
|
||||
query = query.exclude(
|
||||
line__order__status__in=SalesOrderStatus.OPEN
|
||||
).exclude(
|
||||
shipment__shipment_date=None
|
||||
)
|
||||
|
||||
return query
|
||||
|
||||
def sales_order_allocation_count(self, active=True):
|
||||
"""Return the total quantity allocated to SalesOrders."""
|
||||
query = self.sales_order_allocations.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||
|
||||
query = self.get_sales_order_allocations(active=active)
|
||||
query = query.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||
|
||||
total = query['q']
|
||||
|
||||
|
Reference in New Issue
Block a user