Add some more support for product inventory and status
This commit is contained in:
parent
e4b2cd638a
commit
d3bc1abb57
|
@ -37,7 +37,7 @@ from rattail.db import model, api, auth, Session as RattailSession
|
||||||
from rattail.gpc import GPC
|
from rattail.gpc import GPC
|
||||||
from rattail.threads import Thread
|
from rattail.threads import Thread
|
||||||
from rattail.exceptions import LabelPrintingError
|
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
|
from rattail.batch import get_batch_handler
|
||||||
|
|
||||||
import wtforms
|
import wtforms
|
||||||
|
@ -90,6 +90,10 @@ class ProductsView(MasterView):
|
||||||
'current_price',
|
'current_price',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
labels = {
|
||||||
|
'status_code': "Status",
|
||||||
|
}
|
||||||
|
|
||||||
# These aliases enable the grid queries to filter products which may be
|
# These aliases enable the grid queries to filter products which may be
|
||||||
# purchased from *any* vendor, and yet sort by only the "preferred" vendor
|
# purchased from *any* vendor, and yet sort by only the "preferred" vendor
|
||||||
# (since that's what shows up in the grid column).
|
# (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.current_price))\
|
||||||
# .options(orm.joinedload(model.Product.vendor))
|
# .options(orm.joinedload(model.Product.vendor))
|
||||||
|
|
||||||
|
query = query.outerjoin(model.ProductInventory)
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
|
@ -175,6 +181,7 @@ class ProductsView(MasterView):
|
||||||
g.sorters['department'] = g.make_sorter(model.Department.name)
|
g.sorters['department'] = g.make_sorter(model.Department.name)
|
||||||
g.sorters['subdepartment'] = g.make_sorter(model.Subdepartment.name)
|
g.sorters['subdepartment'] = g.make_sorter(model.Subdepartment.name)
|
||||||
g.sorters['vendor'] = g.make_sorter(model.Vendor.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_active = True
|
||||||
g.filters['upc'].default_verb = 'equal'
|
g.filters['upc'].default_verb = 'equal'
|
||||||
|
@ -211,8 +218,10 @@ class ProductsView(MasterView):
|
||||||
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('current_price', self.render_price)
|
||||||
g.set_renderer('cost', self.render_cost)
|
g.set_renderer('cost', self.render_cost)
|
||||||
|
g.set_renderer('on_hand', self.render_on_hand)
|
||||||
|
|
||||||
g.set_link('upc')
|
g.set_link('upc')
|
||||||
|
g.set_link('item_id')
|
||||||
g.set_link('description')
|
g.set_link('description')
|
||||||
|
|
||||||
g.set_label('upc', "UPC")
|
g.set_label('upc', "UPC")
|
||||||
|
@ -245,7 +254,13 @@ class ProductsView(MasterView):
|
||||||
cost = product.cost
|
cost = product.cost
|
||||||
if not cost:
|
if not cost:
|
||||||
return ""
|
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):
|
def template_kwargs_index(self, **kwargs):
|
||||||
if self.print_labels:
|
if self.print_labels:
|
||||||
|
@ -289,6 +304,8 @@ class ProductsView(MasterView):
|
||||||
fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer, readonly=True)
|
fs.regular_price.set(renderer=forms.renderers.PriceFieldRenderer, readonly=True)
|
||||||
fs.current_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.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,
|
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))
|
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",
|
fs.append(fa.Field('inventory_on_hand', readonly=True, label="On Hand",
|
||||||
|
@ -330,6 +347,7 @@ class ProductsView(MasterView):
|
||||||
fs.not_for_sale,
|
fs.not_for_sale,
|
||||||
fs.ingredients,
|
fs.ingredients,
|
||||||
fs.notes,
|
fs.notes,
|
||||||
|
fs.status_code,
|
||||||
fs.discontinued,
|
fs.discontinued,
|
||||||
fs.deleted,
|
fs.deleted,
|
||||||
fs.last_sold,
|
fs.last_sold,
|
||||||
|
|
Loading…
Reference in a new issue