Changeset - 50db7437f539
[Not reviewed]
0 2 0
Lance Edgar (lance) - 3 years ago 2022-03-29 18:17:42
lance@edbob.org
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
2 files changed with 48 insertions and 15 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -89,24 +89,42 @@ class CustomerOrderBatchHandler(BatchHandler):
 

	
 
    def allow_contact_info_creation(self):
 
        """
 
        Returns a boolean indicating whether the user is allowed to
 
        enter *new* contact info for the customer.  This setting
 
        should only be honored if :meth:`allow_contact_info_choice()`
 
        also returns true.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
                                   '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
 
        allowed on new orders.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
                                   'allow_unknown_product',
 
                                   default=False)
 

	
 
    def product_price_may_be_questionable(self):
 
        """
 
        Returns a boolean indicating whether "any" product's price may
 
@@ -521,42 +539,51 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        return info
 

	
 
    def uom_choices_for_row(self, row):
 
        """
 
        Return a list of UOM choices for the given batch row.
 
        """
 
        if row.product:
 
            return self.uom_choices_for_product(row.product)
 

	
 
        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
 

	
 
    def uom_choices_for_product(self, product):
 
        """
 
        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):
 
        """
 
        This method can inspect the given product, and batch, to
 
        determine if the product may be added to the batch as a new
 
        row.  Useful to e.g. prevent one customer from ordering too
 
        many things, etc.
 

	
 
        :returns: If there is a reason not to add the product, should
 
           return that reason as a string; otherwise ``None``.
 
        """
 

	
rattail/products.py
Show inline comments
 
@@ -676,37 +676,43 @@ class ProductsHandler(GenericHandler):
 
        if 'uom_choices' in fields:
 
            data['uom_choices'] = self.get_uom_choices(product)
 

	
 
        return data
 

	
 
    def get_uom_choices(self, product=None, **kwargs):
 
        """
 
        Return a list of UOM choices for the given product, or if no
 
        product specified then should return the default 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
 
        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
 
        case_size = None
 
        if product:
 
            case_size = self.get_case_size(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(
0 comments (0 inline, 0 general)