Add new 'receiving form' for purchase batches
This commit is contained in:
parent
468a84aa90
commit
6c3d221e98
5 changed files with 323 additions and 36 deletions
|
@ -335,6 +335,46 @@ class ProductsView(MasterView):
|
|||
'instance_title': self.get_instance_title(instance),
|
||||
'form': form})
|
||||
|
||||
def search(self):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
data = None
|
||||
upc = self.request.GET.get('upc', '').strip()
|
||||
upc = re.sub(r'\D', '', upc)
|
||||
if upc:
|
||||
product = api.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 = api.get_product_by_upc(Session(), upc)
|
||||
if product and (not product.deleted or self.request.has_perm('products.view_deleted')):
|
||||
data = {
|
||||
'uuid': product.uuid,
|
||||
'upc': unicode(product.upc),
|
||||
'upc_pretty': product.upc.pretty(),
|
||||
'full_description': product.full_description,
|
||||
'image_url': pod.get_image_url(self.rattail_config, product.upc),
|
||||
}
|
||||
uuid = self.request.GET.get('with_vendor_cost')
|
||||
if uuid:
|
||||
vendor = Session.query(model.Vendor).get(uuid)
|
||||
if not vendor:
|
||||
return {'error': "Vendor not found"}
|
||||
cost = product.cost_for_vendor(vendor)
|
||||
if cost:
|
||||
data['cost_found'] = True
|
||||
if int(cost.case_size) == cost.case_size:
|
||||
data['cost_case_size'] = int(cost.case_size)
|
||||
else:
|
||||
data['cost_case_size'] = '{:0.4f}'.format(cost.case_size)
|
||||
else:
|
||||
data['cost_found'] = False
|
||||
return {'product': data}
|
||||
|
||||
def get_supported_batches(self):
|
||||
return {
|
||||
'labels': 'rattail.batch.labels:LabelBatchHandler',
|
||||
|
@ -479,6 +519,11 @@ class ProductsView(MasterView):
|
|||
config.add_view(cls, attr='make_batch', route_name='products.create_batch',
|
||||
renderer='/products/batch.mako', permission='batches.create')
|
||||
|
||||
# search (by upc)
|
||||
config.add_route('products.search', '/products/search')
|
||||
config.add_view(cls, attr='search', route_name='products.search',
|
||||
renderer='json', permission='products.view')
|
||||
|
||||
cls._defaults(config)
|
||||
|
||||
|
||||
|
@ -535,34 +580,6 @@ class ProductsAutocomplete(AutocompleteView):
|
|||
return product.full_description
|
||||
|
||||
|
||||
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', '').strip()
|
||||
upc = re.sub(r'\D', '', upc)
|
||||
if upc:
|
||||
product = api.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 = api.get_product_by_upc(Session(), upc)
|
||||
if product:
|
||||
if product.deleted and not request.has_perm('products.view_deleted'):
|
||||
product = None
|
||||
else:
|
||||
product = {
|
||||
'uuid': product.uuid,
|
||||
'upc': unicode(product.upc or ''),
|
||||
'full_description': product.full_description,
|
||||
}
|
||||
return {'product': product}
|
||||
|
||||
|
||||
def print_labels(request):
|
||||
profile = request.params.get('profile')
|
||||
profile = Session.query(model.LabelProfile).get(profile) if profile else None
|
||||
|
@ -600,9 +617,5 @@ def includeme(config):
|
|||
config.add_view(print_labels, route_name='products.print_labels',
|
||||
renderer='json', permission='products.print_labels')
|
||||
|
||||
config.add_route('products.search', '/products/search')
|
||||
config.add_view(products_search, route_name='products.search',
|
||||
renderer='json', permission='products.list')
|
||||
|
||||
ProductsView.defaults(config)
|
||||
version_defaults(config, ProductVersionView, 'product')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue