first fistribution search class - inventory entry organization bug fixed
This commit is contained in:
0
apps/product/services/__init__.py
Normal file
0
apps/product/services/__init__.py
Normal file
40
apps/product/services/search/distribution_search.py
Normal file
40
apps/product/services/search/distribution_search.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from django.db.models import Q
|
||||
from apps.product.models import QuotaDistribution
|
||||
from django.db.models.functions import TruncDate
|
||||
|
||||
|
||||
class QuotaDistributionSearch:
|
||||
def __init__(self, query: str = None, start_date: str = None, end_date: str = None):
|
||||
self.query = (query or '').strip()
|
||||
self.start_date = start_date
|
||||
self.end_date = end_date
|
||||
|
||||
def search(self):
|
||||
""" multi term search & filter by date range """
|
||||
|
||||
queryset = QuotaDistribution.objects.all() # noqa
|
||||
|
||||
if self.start_date or self.end_date:
|
||||
queryset = queryset.annotate(date_only=TruncDate('create_date'))
|
||||
if self.start_date:
|
||||
queryset = queryset.filter(date_only__gte=self.start_date)
|
||||
if self.end_date:
|
||||
queryset = queryset.filter(date_only__lte=self.end_date)
|
||||
|
||||
# convert string to list of words
|
||||
if self.query:
|
||||
keywords = [word.strip() for word in self.query.split(',') if word.strip()]
|
||||
if keywords:
|
||||
combined_q = Q()
|
||||
for keyword in keywords:
|
||||
combined_q |= Q(assigner_organization__name__icontains=keyword)
|
||||
combined_q |= Q(assigned_organization__name__icontains=keyword)
|
||||
combined_q |= Q(distribution_id__icontains=keyword)
|
||||
combined_q |= Q(quota__quota_id__icontains=keyword)
|
||||
combined_q |= Q(quota__product__name__icontains=keyword)
|
||||
combined_q |= Q(quota__sale_type__icontains=keyword)
|
||||
combined_q |= Q(quota__group__icontains=keyword)
|
||||
|
||||
queryset = queryset.filter(combined_q)
|
||||
|
||||
return queryset.distinct()
|
||||
16
apps/product/services/services.py
Normal file
16
apps/product/services/services.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from apps.warehouse.models import InventoryEntry
|
||||
|
||||
|
||||
def get_products_in_warehouse(organization_id):
|
||||
""" get list of products from organization warehouse """
|
||||
|
||||
entries = InventoryEntry.objects.select_related(
|
||||
'distribution__quota__product'
|
||||
)
|
||||
|
||||
product_objects = [
|
||||
entry.distribution.quota.product for entry in entries
|
||||
]
|
||||
|
||||
return list(set(product_objects))
|
||||
|
||||
Reference in New Issue
Block a user