diff --git a/rattail/autocomplete/products.py b/rattail/autocomplete/products.py index 781089c9bc40d627f4ef4f9537dfc51a20bc8d93..aa10de1d15356ba0e7d3ef6fb127cbbe76ec1fa1 100644 --- a/rattail/autocomplete/products.py +++ b/rattail/autocomplete/products.py @@ -56,8 +56,11 @@ class ProductAutocompleter(Autocompleter): .options(orm.joinedload(model.Product.brand)) def restrict_autocomplete_query(self, session, query, **kwargs): + model = self.model + # do not show "deleted" items by default query = query.filter(model.Product.deleted == False) + return query def filter_autocomplete_query(self, session, query, term): diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index e24873617df25532a369b763595b523a430c1a96..97f2ddc6123409200f69c2ef801fe52ff2314fda 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -386,6 +386,68 @@ class CustomerOrderBatchHandler(BatchHandler): "{}.custom_product_autocomplete() " "method.".format(__class__.__name__)) + def get_product_info(self, batch, product, **kwargs): + """ + Return a data dict containing misc. info pertaining to the + given product, for the order batch. + """ + products = self.app.get_products_handler() + info = { + 'uuid': product.uuid, + 'upc': six.text_type(product.upc), + 'upc_pretty': product.upc.pretty(), + 'unit_price_display': products.render_price(product.regular_price), + 'full_description': product.full_description, + 'image_url': products.get_image_url(product), + 'uom_choices': self.uom_choices_for_product(product), + } + + key = self.config.product_key() + if key == 'upc': + info['key'] = info['upc_pretty'] + else: + info['key'] = getattr(product, key, info['upc_pretty']) + + return info + + def uom_choices_for_product(self, product): + """ + Return a list of UOM choices for the given product. + """ + choices = [] + + # Each + if not product or not product.weighed: + unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH] + choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH, + 'value': unit_name}) + + # Pound + if not product or product.weighed: + unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_POUND] + choices.append({ + 'key': self.enum.UNIT_OF_MEASURE_POUND, + 'value': unit_name, + }) + + # Case + case_text = None + case_size = self.get_case_size_for_product(product) + if case_size is None: + case_text = "{} (× ?? {})".format( + self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE], + unit_name) + elif case_size > 1: + case_text = "{} (× {} {})".format( + self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE], + self.app.render_quantity(case_size), + unit_name) + if case_text: + choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE, + 'value': case_text}) + + return choices + def why_not_add_product(self, product, batch): """ This method can inspect the given product, and batch, to