Let cases and/or units be (dis)allowed for new custorder

at least this sets the stage, probably more tweaks needed to fully
support the idea
This commit is contained in:
Lance Edgar 2022-03-29 18:17:42 -05:00
parent 358f571f48
commit 50db7437f5
2 changed files with 48 additions and 15 deletions

View file

@ -98,6 +98,24 @@ class CustomerOrderBatchHandler(BatchHandler):
'new_orders.allow_contact_info_create', 'new_orders.allow_contact_info_create',
default=False) 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): def allow_unknown_product(self):
""" """
Returns a boolean indicating whether "unknown" products are Returns a boolean indicating whether "unknown" products are
@ -530,15 +548,17 @@ class CustomerOrderBatchHandler(BatchHandler):
choices = [] choices = []
# Each # Each
unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH] if self.allow_unit_orders():
choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH, unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH]
'value': unit_name}) choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH,
'value': unit_name})
# Case # Case
case_text = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE] if self.allow_case_orders():
if case_text: case_text = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE]
choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE, if case_text:
'value': case_text}) choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE,
'value': case_text})
return choices return choices
@ -547,7 +567,14 @@ class CustomerOrderBatchHandler(BatchHandler):
Return a list of UOM choices for the given product. Return a list of UOM choices for the given product.
""" """
products_handler = self.app.get_products_handler() 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): def why_not_add_product(self, product, batch):
""" """

View file

@ -685,19 +685,25 @@ class ProductsHandler(GenericHandler):
""" """
choices = [] 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 # Each
if not product or not product.weighed: if not product or not product.weighed:
unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH] unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH]
choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH, choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH,
'value': unit_name}) 'value': unit_name})
# Pound # # Pound
if not product or product.weighed: # if not product or product.weighed:
unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_POUND] # unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_POUND]
choices.append({ # choices.append({
'key': self.enum.UNIT_OF_MEASURE_POUND, # 'key': self.enum.UNIT_OF_MEASURE_POUND,
'value': unit_name, # 'value': unit_name,
}) # })
# Case # Case
case_text = None case_text = None