diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 0d3b50ebbcabed7d22f365e0863bea4119d123e4..87c4ce375f1513f94fc03463eb290907f09250e1 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -98,6 +98,24 @@ class CustomerOrderBatchHandler(BatchHandler): 'new_orders.allow_contact_info_create', default=False) + def allow_case_orders(self): + """ + Returns a boolean indicating whether "case" orders are + allowed. + """ + return self.config.getbool('rattail.custorders', + 'allow_case_orders', + default=False) + + def allow_unit_orders(self): + """ + Returns a boolean indicating whether "unit" orders are + allowed. + """ + return self.config.getbool('rattail.custorders', + 'allow_unit_orders', + default=False) + def allow_unknown_product(self): """ Returns a boolean indicating whether "unknown" products are @@ -530,15 +548,17 @@ class CustomerOrderBatchHandler(BatchHandler): choices = [] # Each - 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}) + if self.allow_unit_orders(): + 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}) # Case - case_text = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE] - if case_text: - choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE, - 'value': case_text}) + if self.allow_case_orders(): + case_text = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE] + if case_text: + choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE, + 'value': case_text}) return choices @@ -547,7 +567,14 @@ class CustomerOrderBatchHandler(BatchHandler): Return a list of UOM choices for the given product. """ products_handler = self.app.get_products_handler() - return products_handler.get_uom_choices(product) + choices = products_handler.get_uom_choices(product) + if not self.allow_case_orders(): + choices = [choice for choice in choices + if choice['key'] != self.enum.UNIT_OF_MEASURE_CASE] + if not self.allow_unit_orders(): + choices = [choice for choice in choices + if choice['key'] != self.enum.UNIT_OF_MEASURE_EACH] + return choices def why_not_add_product(self, product, batch): """ diff --git a/rattail/products.py b/rattail/products.py index 5c6ba4c70125fe9dd4d1275b60661b26b86dfae2..f7e93512e86327053c51b04e9f35786b11e808fb 100644 --- a/rattail/products.py +++ b/rattail/products.py @@ -685,19 +685,25 @@ class ProductsHandler(GenericHandler): """ choices = [] + # TODO: not sure how generically useful this method even is? i + # think it is only used when making a new custorder so far.. + + # TODO: for instance "pound" vs. "each" is really just 2 ways + # of saying "unit" - and does not consider i18n etc. + # 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, - }) + # # 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