From d3bc1abb57ae35b483de3793c8c86f7d98fbb45b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 19 Jul 2017 03:08:32 -0500 Subject: [PATCH] Add some more support for product inventory and status --- tailbone/views/products.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tailbone/views/products.py b/tailbone/views/products.py index b1863c9a..ff6019a8 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -37,7 +37,7 @@ from rattail.db import model, api, auth, Session as RattailSession from rattail.gpc import GPC from rattail.threads import Thread from rattail.exceptions import LabelPrintingError -from rattail.util import load_object +from rattail.util import load_object, pretty_quantity from rattail.batch import get_batch_handler import wtforms @@ -90,6 +90,10 @@ class ProductsView(MasterView): 'current_price', ] + labels = { + 'status_code': "Status", + } + # These aliases enable the grid queries to filter products which may be # purchased from *any* vendor, and yet sort by only the "preferred" vendor # (since that's what shows up in the grid column). @@ -122,6 +126,8 @@ class ProductsView(MasterView): # .options(orm.joinedload(model.Product.current_price))\ # .options(orm.joinedload(model.Product.vendor)) + query = query.outerjoin(model.ProductInventory) + return query def configure_grid(self, g): @@ -175,6 +181,7 @@ class ProductsView(MasterView): g.sorters['department'] = g.make_sorter(model.Department.name) g.sorters['subdepartment'] = g.make_sorter(model.Subdepartment.name) g.sorters['vendor'] = g.make_sorter(model.Vendor.name) + g.set_sorter('on_hand', model.ProductInventory.on_hand) g.filters['upc'].default_active = True g.filters['upc'].default_verb = 'equal' @@ -211,8 +218,10 @@ class ProductsView(MasterView): g.set_renderer('regular_price', self.render_price) g.set_renderer('current_price', self.render_price) g.set_renderer('cost', self.render_cost) + g.set_renderer('on_hand', self.render_on_hand) g.set_link('upc') + g.set_link('item_id') g.set_link('description') g.set_label('upc', "UPC") @@ -245,7 +254,13 @@ class ProductsView(MasterView): cost = product.cost if not cost: return "" - return "'${:0.2f}".format(cost.unit_cost) + return "${:0.2f}".format(cost.unit_cost) + + def render_on_hand(self, product, column): + inventory = product.inventory + if not inventory: + return "" + return pretty_quantity(inventory.on_hand) def template_kwargs_index(self, **kwargs): if self.print_labels: @@ -289,6 +304,8 @@ class ProductsView(MasterView): fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer, readonly=True) fs.current_price.set(renderer=forms.renderers.PriceFieldRenderer, readonly=True) fs.last_sold.set(readonly=True) + fs.status_code.set(label="Status") + fs.notes.set(renderer=fa.TextAreaFieldRenderer, size=(80, 10)) fs.append(fa.Field('current_price_ends', type=fa.types.DateTime, readonly=True, value=lambda p: p.current_price.ends if p.current_price else None)) fs.append(fa.Field('inventory_on_hand', readonly=True, label="On Hand", @@ -330,6 +347,7 @@ class ProductsView(MasterView): fs.not_for_sale, fs.ingredients, fs.notes, + fs.status_code, fs.discontinued, fs.deleted, fs.last_sold,