Changeset - 6166b6e425a1
[Not reviewed]
0 3 0
Lance Edgar (lance) - 21 months ago 2023-01-11 15:35:56
lance@edbob.org
Add support for per-item default discounts, for new custorder
3 files changed with 58 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rattail/app.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2022 Lance Edgar
 
#  Copyright © 2010-2023 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -26,12 +26,13 @@ App Handler
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import os
 
# import re
 
import datetime
 
import decimal
 
import os
 
import shutil
 
import socket
 
import tempfile
 
import warnings
 
import logging
 
@@ -144,12 +145,32 @@ class AppHandler(object):
 
           returned.  Note that most apps have only one ("default"),
 
           but may have others defined.
 
        """
 
        from rattail.time import timezone
 
        return timezone(self.config, key)
 

	
 
    def json_friendly(self, value):
 
        """
 
        Coerce a Python value to one which is JSON-serializable.
 

	
 
        So, this does *not* return a JSON string, but rather a Python
 
        object which can then be safely converted via
 
        ``json.dumps()``.
 

	
 
        If the value is a container, it will be crawled recursively
 
        and all values it contains will be coerced.
 
        """
 
        if isinstance(value, dict):
 
            for key, val in six.iteritems(value):
 
                value[key] = self.json_friendly(val)
 

	
 
        elif isinstance(value, decimal.Decimal):
 
            value = float(value)
 

	
 
        return value
 

	
 
    def localtime(self, *args, **kwargs):
 
        """
 
        Produce or convert a timestamp in the default time zone.
 

	
 
        Default logic invokes :func:`rattail.time.localtime()` to
 
        obtain the timestamp.  All args and kwargs are passed directly
rattail/batch/custorder.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2022 Lance Edgar
 
#  Copyright © 2010-2023 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -54,12 +54,16 @@ class CustomerOrderBatchHandler(BatchHandler):
 
       creating a new order.
 
    """
 
    batch_model_class = model.CustomerOrderBatch
 
    has_custom_product_autocomplete = False
 
    nondigits_pattern = re.compile(r'\D')
 

	
 
    def __init__(self, config, **kwargs):
 
        super(CustomerOrderBatchHandler, self).__init__(config, **kwargs)
 
        self.custorder_handler = self.app.get_custorder_handler()
 

	
 
    def init_batch(self, batch, progress=None, **kwargs):
 
        """
 
        Assign the "local" store to the batch, if applicable.
 
        """
 
        session = self.app.get_session(batch)
 
        batch.store = self.config.get_store(session)
 
@@ -131,12 +135,21 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        allowed.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
                                   'allow_item_discounts',
 
                                   default=False)
 

	
 
    def allow_item_discounts_if_on_sale(self):
 
        """
 
        Returns boolean indicating whether per-item discounts are
 
        allowed when item is already on sale.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
                                   'allow_item_discounts_if_on_sale',
 
                                   default=False)
 

	
 
    def allow_past_item_reorder(self):
 
        """
 
        Returns boolean indicating whether to expose past items for
 
        re-order.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
@@ -515,12 +528,13 @@ class CustomerOrderBatchHandler(BatchHandler):
 
            'unit_price_display': products.render_price(product.regular_price),
 
            'department_name': product.department.name if product.department else None,
 
            'vendor_name': vendor.name if vendor else None,
 
            'url': products.get_url(product),
 
            'image_url': products.get_image_url(product),
 
            'uom_choices': self.uom_choices_for_product(product),
 
            'default_item_discount': self.get_default_item_discount(product),
 
        }
 

	
 
        # TODO: this was somewhat copied from
 
        # tailbone.views.products.render_price() - should make it part
 
        # of the products handler instead?
 
        sale_price = None
 
@@ -602,12 +616,20 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        many things, etc.
 

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

	
 
    def get_default_item_discount(self, product=None, **kwargs):
 
        """
 
        Returns default item discount available.  If product is given,
 
        the default may be specific to its department etc.
 
        """
 
        return self.custorder_handler.get_default_item_discount(
 
            product=product, **kwargs)
 

	
 
    def add_product(self, batch, product, order_quantity, order_uom,
 
                    **kwargs):
 
        """
 
        Add a new row to the batch, for the given product and order
 
        quantity.
 
        """
rattail/custorders.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2021 Lance Edgar
 
#  Copyright © 2010-2023 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -25,20 +25,32 @@ Customer Orders Handler
 

	
 
Please note this is different from the Customer Order Batch Handler.
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
import decimal
 

	
 
from rattail.app import GenericHandler
 

	
 

	
 
class CustomerOrderHandler(GenericHandler):
 
    """
 
    Base class and default implementation for customer order handlers.
 
    """
 

	
 
    def get_default_item_discount(self, product=None, **kwargs):
 
        """
 
        Returns default item discount available.  If product is given,
 
        the default may be specific to its department etc.
 
        """
 
        discount = self.config.get('rattail.custorders',
 
                                   'default_item_discount')
 
        if discount:
 
            return decimal.Decimal(discount)
 

	
 
    def resolve_person(self, pending, person, user, **kwargs):
 
        """
 
        Resolve a pending person for all customer orders.
 
        """
 
        for order in list(pending.custorder_records):
 
            order.person = person
0 comments (0 inline, 0 general)