Add red highlight for SRP breach, for generic product batch

This commit is contained in:
Lance Edgar 2020-01-28 17:24:10 -06:00
parent 132b2b9ec7
commit b633c91b66

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar # Copyright © 2010-2020 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -30,6 +30,7 @@ from rattail.db import model
from rattail.util import OrderedDict from rattail.util import OrderedDict
import colander import colander
from webhelpers2.html import HTML
from tailbone import forms from tailbone import forms
from tailbone.views.batch import BatchMasterView from tailbone.views.batch import BatchMasterView
@ -156,6 +157,9 @@ class ProductBatchView(BatchMasterView):
g.set_type('current_price', 'currency') g.set_type('current_price', 'currency')
g.set_type('suggested_price', 'currency') g.set_type('suggested_price', 'currency')
# highlight red for SRP breaches
g.set_renderer('suggested_price', self.render_suggested_price)
def row_grid_extra_class(self, row, i): def row_grid_extra_class(self, row, i):
if row.status_code in (row.STATUS_MISSING_KEY, if row.status_code in (row.STATUS_MISSING_KEY,
row.STATUS_PRODUCT_NOT_FOUND): row.STATUS_PRODUCT_NOT_FOUND):
@ -174,6 +178,28 @@ class ProductBatchView(BatchMasterView):
f.set_renderer('family', self.render_family) f.set_renderer('family', self.render_family)
f.set_renderer('reportcode', self.render_report) f.set_renderer('reportcode', self.render_report)
f.set_type('regular_cost', 'currency')
f.set_type('current_cost', 'currency')
f.set_type('regular_price', 'currency')
f.set_type('current_price', 'currency')
f.set_type('suggested_price', 'currency')
# highlight red for SRP breaches
f.set_renderer('suggested_price', self.render_suggested_price)
def render_suggested_price(self, row, field):
price = getattr(row, field)
if not price:
return ""
text = "${:0,.2f}".format(price)
if row.regular_price and row.suggested_price and (
row.regular_price > row.suggested_price):
text = HTML.tag('span', style='color: red;', c=text)
return text
def get_execute_success_url(self, batch, result, **kwargs): def get_execute_success_url(self, batch, result, **kwargs):
if kwargs['action'] == 'make_label_batch': if kwargs['action'] == 'make_label_batch':
return self.request.route_url('labels.batch.view', uuid=result.uuid) return self.request.route_url('labels.batch.view', uuid=result.uuid)