Add some custom display logic for "current price" in pricing batch
This commit is contained in:
parent
6a8f64a9e8
commit
6925c460c5
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -27,8 +27,9 @@ Views for pricing batches
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
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
|
from tailbone.views.batch import BatchMasterView
|
||||||
|
|
||||||
|
@ -199,6 +200,8 @@ class PricingBatchView(BatchMasterView):
|
||||||
g.set_type('new_price', 'currency')
|
g.set_type('new_price', 'currency')
|
||||||
g.set_type('price_diff', 'currency')
|
g.set_type('price_diff', 'currency')
|
||||||
|
|
||||||
|
g.set_renderer('current_price', self.render_current_price)
|
||||||
|
|
||||||
def render_vendor_id(self, row, field):
|
def render_vendor_id(self, row, field):
|
||||||
vendor_id = row.vendor.id if row.vendor else None
|
vendor_id = row.vendor.id if row.vendor else None
|
||||||
if not vendor_id:
|
if not vendor_id:
|
||||||
|
@ -206,12 +209,42 @@ class PricingBatchView(BatchMasterView):
|
||||||
return vendor_id
|
return vendor_id
|
||||||
|
|
||||||
def row_grid_extra_class(self, row, i):
|
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,
|
if row.status_code in (row.STATUS_PRODUCT_NOT_FOUND,
|
||||||
row.STATUS_CANNOT_CALCULATE_PRICE,
|
row.STATUS_CANNOT_CALCULATE_PRICE,
|
||||||
row.STATUS_PRICE_BREACHES_SRP):
|
row.STATUS_PRICE_BREACHES_SRP):
|
||||||
return 'warning'
|
extra_class = 'warning'
|
||||||
if row.status_code in (row.STATUS_PRICE_INCREASE, row.STATUS_PRICE_DECREASE):
|
elif row.status_code in (row.STATUS_PRICE_INCREASE,
|
||||||
return 'notice'
|
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):
|
def configure_row_form(self, f):
|
||||||
super(PricingBatchView, self).configure_row_form(f)
|
super(PricingBatchView, self).configure_row_form(f)
|
||||||
|
|
Loading…
Reference in a new issue