Show current price date range as hover text, for products grid

This commit is contained in:
Lance Edgar 2021-04-07 12:29:33 -05:00
parent 4cf61a92cf
commit 6c5377fadc

View file

@ -296,6 +296,7 @@ class ProductView(MasterView):
g.set_filter('regular_price', self.RegularPrice.price, label="Regular Price") g.set_filter('regular_price', self.RegularPrice.price, label="Regular Price")
g.set_label('current_price', "Cur. 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( g.set_joiner('current_price', lambda q: q.outerjoin(
self.CurrentPrice, self.CurrentPrice.uuid == model.Product.current_price_uuid)) self.CurrentPrice, self.CurrentPrice.uuid == model.Product.current_price_uuid))
g.set_sorter('current_price', self.CurrentPrice.price) g.set_sorter('current_price', self.CurrentPrice.price)
@ -326,7 +327,6 @@ class ProductView(MasterView):
g.set_type('upc', 'gpc') g.set_type('upc', 'gpc')
g.set_renderer('regular_price', self.render_price) 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_hand', self.render_on_hand)
g.set_renderer('on_order', self.render_on_order) 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 "$ {:0.2f} / {}".format(price.pack_price, price.pack_multiple)
return "" 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): def add_price_history_link(self, text, typ):
if not self.rattail_config.versioning_enabled(): if not self.rattail_config.versioning_enabled():
return text return text