Add some custom display logic for "current price" in pricing batch

This commit is contained in:
Lance Edgar 2020-02-07 18:12:44 -06:00
parent 6a8f64a9e8
commit 6925c460c5

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -27,8 +27,9 @@ Views for pricing batches
from __future__ import unicode_literals, absolute_import
from rattail.db import model
from rattail.time import localtime
from webhelpers2.html import tags
from webhelpers2.html import tags, HTML
from tailbone.views.batch import BatchMasterView
@ -199,6 +200,8 @@ class PricingBatchView(BatchMasterView):
g.set_type('new_price', 'currency')
g.set_type('price_diff', 'currency')
g.set_renderer('current_price', self.render_current_price)
def render_vendor_id(self, row, field):
vendor_id = row.vendor.id if row.vendor else None
if not vendor_id:
@ -206,12 +209,42 @@ class PricingBatchView(BatchMasterView):
return vendor_id
def row_grid_extra_class(self, row, i):
extra_class = None
# primary class comes from row status
if row.status_code in (row.STATUS_PRODUCT_NOT_FOUND,
row.STATUS_CANNOT_CALCULATE_PRICE,
row.STATUS_PRICE_BREACHES_SRP):
return 'warning'
if row.status_code in (row.STATUS_PRICE_INCREASE, row.STATUS_PRICE_DECREASE):
return 'notice'
extra_class = 'warning'
elif row.status_code in (row.STATUS_PRICE_INCREASE,
row.STATUS_PRICE_DECREASE):
extra_class = 'notice'
# but we want to indicate presence of current price also
if row.current_price:
extra_class = "{} has-current-price".format(extra_class or '')
return extra_class
def render_current_price(self, row, field):
value = row.current_price
if value is None:
return ""
if value < 0:
text = "(${:0,.2f})".format(0 - value)
else:
text = "${:0,.2f}".format(value)
if row.current_price_ends:
ends = localtime(self.rattail_config, row.current_price_ends, from_utc=True)
ends = "ends on {}".format(ends.date())
else:
ends = "never ends"
title = "{}, {}".format(
self.enum.PRICE_TYPE.get(row.current_price_type, "unknown type"),
ends)
return HTML.tag('span', title=title, c=text)
def configure_row_form(self, f):
super(PricingBatchView, self).configure_row_form(f)