Added products.search
route/view.
This is for simple AJAX uses.
This commit is contained in:
parent
ba5dc6ab02
commit
685b391dd2
|
@ -47,6 +47,7 @@ from rattail.db.model import (
|
||||||
Product, ProductPrice, ProductCost, ProductCode,
|
Product, ProductPrice, ProductCost, ProductCode,
|
||||||
Brand, Vendor, Department, Subdepartment, LabelProfile)
|
Brand, Vendor, Department, Subdepartment, LabelProfile)
|
||||||
from rattail.gpc import GPC
|
from rattail.gpc import GPC
|
||||||
|
from rattail.db.api import get_product_by_upc
|
||||||
|
|
||||||
from ..db import Session
|
from ..db import Session
|
||||||
from ..forms import AutocompleteFieldRenderer, GPCFieldRenderer, PriceFieldRenderer
|
from ..forms import AutocompleteFieldRenderer, GPCFieldRenderer, PriceFieldRenderer
|
||||||
|
@ -250,6 +251,30 @@ class ProductCrud(CrudView):
|
||||||
return fs
|
return fs
|
||||||
|
|
||||||
|
|
||||||
|
def products_search(request):
|
||||||
|
"""
|
||||||
|
Locate a product(s) by UPC.
|
||||||
|
|
||||||
|
Eventually this should be more generic, or at least offer more fields for
|
||||||
|
search. For now it operates only on the ``Product.upc`` field.
|
||||||
|
"""
|
||||||
|
|
||||||
|
product = None
|
||||||
|
upc = request.GET.get('upc')
|
||||||
|
if upc:
|
||||||
|
product = get_product_by_upc(Session, upc)
|
||||||
|
if not product:
|
||||||
|
# Try again, assuming caller did not include check digit.
|
||||||
|
upc = GPC(upc, calc_check_digit='upc')
|
||||||
|
product = get_product_by_upc(Session, upc)
|
||||||
|
if product:
|
||||||
|
product = {
|
||||||
|
'uuid': product.uuid,
|
||||||
|
'full_description': product.full_description,
|
||||||
|
}
|
||||||
|
return {'product': product}
|
||||||
|
|
||||||
|
|
||||||
def print_labels(request):
|
def print_labels(request):
|
||||||
profile = request.params.get('profile')
|
profile = request.params.get('profile')
|
||||||
profile = Session.query(LabelProfile).get(profile) if profile else None
|
profile = Session.query(LabelProfile).get(profile) if profile else None
|
||||||
|
@ -346,6 +371,7 @@ class CreateProductsBatch(ProductsGrid):
|
||||||
|
|
||||||
def add_routes(config):
|
def add_routes(config):
|
||||||
config.add_route('products', '/products')
|
config.add_route('products', '/products')
|
||||||
|
config.add_route('products.search', '/products/search')
|
||||||
config.add_route('products.print_labels', '/products/labels')
|
config.add_route('products.print_labels', '/products/labels')
|
||||||
config.add_route('products.create_batch', '/products/batch')
|
config.add_route('products.create_batch', '/products/batch')
|
||||||
config.add_route('product.create', '/products/new')
|
config.add_route('product.create', '/products/new')
|
||||||
|
@ -376,3 +402,5 @@ def includeme(config):
|
||||||
permission='products.update')
|
permission='products.update')
|
||||||
config.add_view(ProductCrud, attr='delete', route_name='product.delete',
|
config.add_view(ProductCrud, attr='delete', route_name='product.delete',
|
||||||
permission='products.delete')
|
permission='products.delete')
|
||||||
|
config.add_view(products_search, route_name='products.search',
|
||||||
|
renderer='json', permission='products.list')
|
||||||
|
|
Loading…
Reference in a new issue