From 760fbc57bc546db735ee02f1c2a7dd11643be9a8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 2 Dec 2021 14:40:51 -0600 Subject: [PATCH] Expose the Sale Price and TPR Price for product views in addition to Current Price --- tailbone/templates/products/view.mako | 4 ++ tailbone/views/products.py | 62 +++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tailbone/templates/products/view.mako b/tailbone/templates/products/view.mako index 0d0e4e5f..d42c04b9 100644 --- a/tailbone/templates/products/view.mako +++ b/tailbone/templates/products/view.mako @@ -191,6 +191,10 @@ ${form.render_field_readonly('regular_price')} ${form.render_field_readonly('current_price')} ${form.render_field_readonly('current_price_ends')} + ${form.render_field_readonly('sale_price')} + ${form.render_field_readonly('sale_price_ends')} + ${form.render_field_readonly('tpr_price')} + ${form.render_field_readonly('tpr_price_ends')} ${form.render_field_readonly('suggested_price')} ${form.render_field_readonly('deposit_link')} ${form.render_field_readonly('tax')} diff --git a/tailbone/views/products.py b/tailbone/views/products.py index a59df32f..40414cf8 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -93,6 +93,8 @@ class ProductView(MasterView): 'tax1': "Tax 1", 'tax2': "Tax 2", 'tax3': "Tax 3", + 'tpr_price': "TPR Price", + 'tpr_price_ends': "TPR Price Ends", } grid_columns = [ @@ -131,6 +133,10 @@ class ProductView(MasterView): 'regular_price', 'current_price', 'current_price_ends', + 'sale_price', + 'sale_price_ends', + 'tpr_price', + 'tpr_price_ends', 'vendor', 'cost', 'deposit_link', @@ -167,6 +173,8 @@ class ProductView(MasterView): # same, but for prices RegularPrice = orm.aliased(model.ProductPrice) CurrentPrice = orm.aliased(model.ProductPrice) + SalePrice = orm.aliased(model.ProductPrice) + TPRPrice = orm.aliased(model.ProductPrice) def __init__(self, request): super(ProductView, self).__init__(request) @@ -321,6 +329,16 @@ class ProductView(MasterView): g.set_sorter('current_price', self.CurrentPrice.price) g.set_filter('current_price', self.CurrentPrice.price, label="Current Price") + # tpr_price + g.set_joiner('tpr_price', lambda q: q.outerjoin( + self.TPRPrice, self.TPRPrice.uuid == model.Product.tpr_price_uuid)) + g.set_filter('tpr_price', self.TPRPrice.price) + + # sale_price + g.set_joiner('sale_price', lambda q: q.outerjoin( + self.SalePrice, self.SalePrice.uuid == model.Product.sale_price_uuid)) + g.set_filter('sale_price', self.SalePrice.price) + # suggested_price g.set_renderer('suggested_price', self.render_grid_suggested_price) @@ -427,6 +445,34 @@ class ProductView(MasterView): f.set_readonly('current_price_ends') f.set_renderer('current_price_ends', self.render_current_price_ends) + # sale_price + if self.creating: + f.remove_field('sale_price') + else: + f.set_readonly('sale_price') + f.set_renderer('sale_price', self.render_price) + + # sale_price_ends + if self.creating: + f.remove_field('sale_price_ends') + else: + f.set_readonly('sale_price_ends') + f.set_renderer('sale_price_ends', self.render_sale_price_ends) + + # tpr_price + if self.creating: + f.remove_field('tpr_price') + else: + f.set_readonly('tpr_price') + f.set_renderer('tpr_price', self.render_price) + + # tpr_price_ends + if self.creating: + f.remove_field('tpr_price_ends') + else: + f.set_readonly('tpr_price_ends') + f.set_renderer('tpr_price_ends', self.render_tpr_price_ends) + # vendor if self.creating: f.remove_field('vendor') @@ -1011,6 +1057,22 @@ class ProductView(MasterView): return "" return raw_datetime(self.request.rattail_config, value) + def render_sale_price_ends(self, product, field): + if not product.sale_price: + return + ends = product.sale_price.ends + if not ends: + return + return raw_datetime(self.rattail_config, ends) + + def render_tpr_price_ends(self, product, field): + if not product.tpr_price: + return + ends = product.tpr_price.ends + if not ends: + return + return raw_datetime(self.rattail_config, ends) + def render_inventory_on_hand(self, product, field): if not product.inventory: return ""