From 6c5377fadc1f8c9db5d383079442b979e96ea427 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 7 Apr 2021 12:29:33 -0500 Subject: [PATCH] Show current price date range as hover text, for products grid --- tailbone/views/products.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 2642b4db..3a27de06 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -296,6 +296,7 @@ class ProductView(MasterView): g.set_filter('regular_price', self.RegularPrice.price, label="Regular Price") g.set_label('current_price', "Cur. Price") + g.set_renderer('current_price', self.render_current_price_for_grid) g.set_joiner('current_price', lambda q: q.outerjoin( self.CurrentPrice, self.CurrentPrice.uuid == model.Product.current_price_uuid)) g.set_sorter('current_price', self.CurrentPrice.price) @@ -326,7 +327,6 @@ class ProductView(MasterView): g.set_type('upc', 'gpc') g.set_renderer('regular_price', self.render_price) - g.set_renderer('current_price', self.render_price) g.set_renderer('on_hand', self.render_on_hand) g.set_renderer('on_order', self.render_on_order) @@ -472,6 +472,30 @@ class ProductView(MasterView): return "$ {:0.2f} / {}".format(price.pack_price, price.pack_multiple) return "" + def render_current_price_for_grid(self, product, field): + text = self.render_price(product, field) + + price = product.current_price + if price: + app = self.get_rattail_app() + + if price.starts: + starts = localtime(self.rattail_config, price.starts, from_utc=True) + starts = app.render_date(starts.date()) + else: + starts = "??" + + if price.ends: + ends = localtime(self.rattail_config, price.ends, from_utc=True) + ends = app.render_date(ends.date()) + else: + ends = "??" + + return HTML.tag('span', c=text, + title="{} thru {}".format(starts, ends)) + + return text + def add_price_history_link(self, text, typ): if not self.rattail_config.versioning_enabled(): return text