fix for history admin crashing when company is null
This commit is contained in:
@@ -14,7 +14,7 @@ from rest_framework import status
|
||||
from companies.factories import CompanyFactory
|
||||
from products.factories import ProductFactory, ActiveProductFactory
|
||||
from products.models import Product
|
||||
from products.utils import find_related_products_v3
|
||||
# from products.utils import find_related_products_v3
|
||||
|
||||
from core.factories import CustomUserFactory
|
||||
from core.utils import get_tokens_for_user
|
||||
@@ -1159,6 +1159,7 @@ class AdminProductViewSetTest(APITestCase):
|
||||
self.assertEquals(response.status_code, 204)
|
||||
|
||||
|
||||
'''
|
||||
class FindRelatedProductsTest(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -1195,7 +1196,7 @@ class FindRelatedProductsTest(APITestCase):
|
||||
|
||||
# assert result
|
||||
self.assertTrue(len(results) == len(expected_instances))
|
||||
|
||||
'''
|
||||
|
||||
class PurchaseEmailTest(APITestCase):
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ def extract_search_filters(result_set):
|
||||
return filter_dict
|
||||
|
||||
|
||||
def find_related_products_v7(description, tags, attributes, category):
|
||||
def get_related_products(description, tags, attributes, category):
|
||||
products_qs = Product.objects.filter(
|
||||
description=description,
|
||||
tags__in=tags,
|
||||
@@ -94,7 +94,7 @@ def find_related_products_v7(description, tags, attributes, category):
|
||||
)[:6]
|
||||
return products_qs
|
||||
|
||||
|
||||
'''
|
||||
def find_related_products_v3(keyword):
|
||||
"""
|
||||
Ranked product search
|
||||
@@ -111,9 +111,9 @@ def find_related_products_v3(keyword):
|
||||
).filter(rank__gt=0.05) # removed order_by because its lost in casting
|
||||
|
||||
return set(products_qs)
|
||||
'''
|
||||
|
||||
|
||||
def find_related_products_v6(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
def ranked_product_search(keyword, shipping_cost=None, discount=None, category=None, tags=None, price_min=None,price_max=None):
|
||||
"""
|
||||
Ranked product search
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ from products.serializers import ProductSerializer, TagFilterSerializer, SearchR
|
||||
from companies.models import Company
|
||||
from stats.models import StatsLog
|
||||
from back_latienda.permissions import IsCreator, IsSiteAdmin, ReadOnly
|
||||
from .utils import extract_search_filters, find_related_products_v6, product_loader, find_related_products_v7
|
||||
from .utils import extract_search_filters, ranked_product_search, product_loader, get_related_products
|
||||
from utils.tag_serializers import TaggitSerializer
|
||||
from utils.tag_filters import ProductTagFilter, ProductOrderFilter
|
||||
|
||||
@@ -59,7 +59,7 @@ class ProductViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
# TODO: find the most similar products
|
||||
product = self.get_object()
|
||||
qs = find_related_products_v7(product.description, product.tags.all(), product.attributes.all(), product.category)
|
||||
qs = get_related_products(product.description, product.tags.all(), product.attributes.all(), product.category)
|
||||
serializer = self.serializer_class(qs, many=True)
|
||||
return Response(data=serializer.data)
|
||||
|
||||
@@ -195,7 +195,7 @@ def product_search(request):
|
||||
# split query string into single words
|
||||
chunks = q.split(' ')
|
||||
for chunk in chunks:
|
||||
product_set, min_price, max_price = find_related_products_v6(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||
product_set, min_price, max_price = ranked_product_search(chunk, shipping_cost, discount, category, tags, price_min, price_max)
|
||||
# update price values
|
||||
if product_set:
|
||||
if prices['min'] is None or min_price['price__min'] < prices['min']:
|
||||
|
||||
Reference in New Issue
Block a user