Changeset - 66d79107705e
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-11-27 19:07:33
lance@edbob.org
Add some sale pricing logic for custorder batch
1 file changed with 22 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -27,24 +27,25 @@ Handler for "customer order" batches
 
from __future__ import unicode_literals, absolute_import, division
 

	
 
import re
 
import decimal
 

	
 
import six
 
import sqlalchemy as sa
 
from sqlalchemy import orm
 

	
 
from rattail.db import model
 
from rattail.batch import BatchHandler
 
from rattail.util import OrderedDict
 
from rattail.time import localtime
 

	
 

	
 
class CustomerOrderBatchHandler(BatchHandler):
 
    """
 
    Handler for all "customer order" batches, regardless of "mode".  The
 
    handler must inspect the
 
    :attr:`~rattail.db.model.batch.custorder.CustomerOrderBatch.mode` attribute
 
    of each batch it deals with, in order to determine which logic to apply.
 

	
 
    .. attribute:: has_custom_product_autocomplete
 

	
 
       If true, this flag indicates that the handler provides custom
 
@@ -464,28 +465,48 @@ class CustomerOrderBatchHandler(BatchHandler):
 
            'description': product.description,
 
            'size': product.size,
 
            'full_description': product.full_description,
 
            'case_quantity': self.app.render_quantity(self.get_case_size_for_product(product)),
 
            '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),
 
        }
 

	
 
        # TODO: this was somewhat copied from
 
        # tailbone.views.products.render_price() - should make it part
 
        # of the products handler instead?
 
        sale_price = None
 
        if not product.not_for_sale:
 
            sale_price = product.current_price
 
            if sale_price:
 
                if sale_price.price:
 
                    info['sale_price'] = float(sale_price.price)
 
                info['sale_price_display'] = products.render_price(sale_price)
 
                sale_ends = sale_price.ends
 
                if sale_ends:
 
                    sale_ends = localtime(self.config, sale_ends, from_utc=True).date()
 
                    info['sale_ends'] = six.text_type(sale_ends)
 
                    info['sale_ends_display'] = self.app.render_date(sale_ends)
 

	
 
        case_price = None
 
        if product.regular_price and product.regular_price is not None:
 
            case_size = self.get_case_size_for_product(product)
 
            case_price = (case_size or 1) * product.regular_price.price
 
            # use sale price if there is one, else normal unit price
 
            unit_price = product.regular_price.price
 
            if sale_price:
 
                unit_price = sale_price.price
 
            case_price = (case_size or 1) * unit_price
 
            case_price = case_price.quantize(decimal.Decimal('0.01'))
 
        info['case_price'] = six.text_type(case_price) if case_price is not None else None
 
        info['case_price_display'] = self.app.render_currency(case_price)
 

	
 
        key = self.config.product_key()
 
        if key == 'upc':
 
            info['key'] = info['upc_pretty']
 
        else:
 
            info['key'] = getattr(product, key, info['upc_pretty'])
 

	
 
        return info
 

	
0 comments (0 inline, 0 general)