Add products row grid for misc. org table views

This commit is contained in:
Lance Edgar 2021-09-25 15:27:43 -04:00
parent ec5ff8a788
commit 0dc9793772
6 changed files with 236 additions and 18 deletions

View file

@ -58,6 +58,23 @@ class BrandView(MasterView):
'confirmed',
]
has_rows = True
model_row_class = model.Product
row_labels = {
'upc': "UPC",
}
row_grid_columns = [
'upc',
'description',
'size',
'department',
'vendor',
'regular_price',
'current_price',
]
def configure_grid(self, g):
super(BrandView, self).configure_grid(g)
@ -70,6 +87,32 @@ class BrandView(MasterView):
# confirmed
g.set_type('confirmed', 'boolean')
def get_row_data(self, brand):
return self.Session.query(model.Product)\
.filter(model.Product.brand == brand)
def get_parent(self, product):
return product.brand
def configure_row_grid(self, g):
super(BrandView, self).configure_row_grid(g)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
g.set_renderer('regular_price', self.render_price)
g.set_renderer('current_price', self.render_price)
g.set_sort_defaults('upc')
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def row_view_action_url(self, product, i):
return self.request.route_url('products.view', uuid=product.uuid)
def get_merge_data(self, brand):
product_count = self.Session.query(model.Product)\
.filter(model.Product.brand == brand)\

View file

@ -63,6 +63,23 @@ class DepartmentView(MasterView):
'employees',
]
has_rows = True
model_row_class = model.Product
row_labels = {
'upc': "UPC",
}
row_grid_columns = [
'upc',
'brand',
'description',
'size',
'vendor',
'regular_price',
'current_price',
]
def configure_grid(self, g):
super(DepartmentView, self).configure_grid(g)
g.filters['name'].default_active = True
@ -156,6 +173,32 @@ class DepartmentView(MasterView):
count, department), 'error')
raise self.redirect(self.get_action_url('view', department))
def get_row_data(self, department):
return self.Session.query(model.Product)\
.filter(model.Product.department == department)
def get_parent(self, product):
return product.department
def configure_row_grid(self, g):
super(DepartmentView, self).configure_row_grid(g)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
g.set_renderer('regular_price', self.render_price)
g.set_renderer('current_price', self.render_price)
g.set_sort_defaults('upc')
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def row_view_action_url(self, product, i):
return self.request.route_url('products.view', uuid=product.uuid)
def list_by_vendor(self):
"""
View list of departments by vendor

View file

@ -51,12 +51,60 @@ class FamilyView(MasterView):
'name',
]
has_rows = True
model_row_class = model.Product
row_labels = {
'upc': "UPC",
}
row_grid_columns = [
'upc',
'brand',
'description',
'size',
'department',
'vendor',
'regular_price',
'current_price',
]
def configure_grid(self, g):
super(FamilyView, self).configure_grid(g)
g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains'
g.set_sort_defaults('code')
g.set_link('code')
g.set_link('name')
def get_row_data(self, family):
return self.Session.query(model.Product)\
.filter(model.Product.family == family)
def get_parent(self, product):
return product.family
def configure_row_grid(self, g):
super(FamilyView, self).configure_row_grid(g)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
g.set_renderer('regular_price', self.render_price)
g.set_renderer('current_price', self.render_price)
g.set_sort_defaults('upc')
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def row_view_action_url(self, product, i):
return self.request.route_url('products.view', uuid=product.uuid)
# TODO: deprecate / remove this
FamiliesView = FamilyView

View file

@ -171,6 +171,9 @@ class ProductView(MasterView):
super(ProductView, self).__init__(request)
self.print_labels = request.rattail_config.getbool('tailbone', 'products.print_labels', default=False)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
def query(self, session):
user = self.request.user
if user and user not in session:
@ -453,24 +456,11 @@ class ProductView(MasterView):
return ""
return "${:0.2f}".format(cost.unit_cost)
def render_price(self, product, column):
price = product[column]
if price:
if not product.not_for_sale:
if price.price is not None and price.pack_price is not None:
if price.multiple > 1:
return HTML.literal("$ {:0.2f} / {}  ($ {:0.2f} / {})".format(
price.price, price.multiple,
price.pack_price, price.pack_multiple))
return HTML.literal("$ {:0.2f}  ($ {:0.2f} / {})".format(
price.price, price.pack_price, price.pack_multiple))
if price.price is not None:
if price.multiple is not None and price.multiple > 1:
return "$ {:0.2f} / {}".format(price.price, price.multiple)
return "$ {:0.2f}".format(price.price)
if price.pack_price is not None:
return "$ {:0.2f} / {}".format(price.pack_price, price.pack_multiple)
return ""
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def render_current_price_for_grid(self, product, field):
text = self.render_price(product, field)

View file

@ -50,6 +50,24 @@ class ReportCodeView(MasterView):
'name',
]
has_rows = True
model_row_class = model.Product
row_labels = {
'upc': "UPC",
}
row_grid_columns = [
'upc',
'brand',
'description',
'size',
'department',
'vendor',
'regular_price',
'current_price',
]
def configure_grid(self, g):
super(ReportCodeView, self).configure_grid(g)
g.filters['name'].default_active = True
@ -58,6 +76,32 @@ class ReportCodeView(MasterView):
g.set_link('code')
g.set_link('name')
def get_row_data(self, reportcode):
return self.Session.query(model.Product)\
.filter(model.Product.report_code == reportcode)
def get_parent(self, product):
return product.report_code
def configure_row_grid(self, g):
super(ReportCodeView, self).configure_row_grid(g)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
g.set_renderer('regular_price', self.render_price)
g.set_renderer('current_price', self.render_price)
g.set_sort_defaults('upc')
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def row_view_action_url(self, product, i):
return self.request.route_url('products.view', uuid=product.uuid)
# TODO: deprecate / remove this
ReportCodesView = ReportCodeView

View file

@ -46,6 +46,12 @@ class SubdepartmentView(MasterView):
'department',
]
form_fields = [
'number',
'name',
'department',
]
mergeable = True
merge_additive_fields = [
'product_count',
@ -57,6 +63,23 @@ class SubdepartmentView(MasterView):
'department_number',
]
has_rows = True
model_row_class = model.Product
row_labels = {
'upc': "UPC",
}
row_grid_columns = [
'upc',
'brand',
'description',
'size',
'vendor',
'regular_price',
'current_price',
]
def configure_grid(self, g):
super(SubdepartmentView, self).configure_grid(g)
@ -98,6 +121,33 @@ class SubdepartmentView(MasterView):
Session.delete(removing)
def get_row_data(self, subdepartment):
return self.Session.query(model.Product)\
.filter(model.Product.subdepartment == subdepartment)
def get_parent(self, product):
return product.subdepartment
def configure_row_grid(self, g):
super(SubdepartmentView, self).configure_row_grid(g)
app = self.get_rattail_app()
self.handler = app.get_products_handler()
g.set_renderer('regular_price', self.render_price)
g.set_renderer('current_price', self.render_price)
g.set_sort_defaults('upc')
def render_price(self, product, field):
if not product.not_for_sale:
price = product[field]
if price:
return self.handler.render_price(price)
def row_view_action_url(self, product, i):
return self.request.route_url('products.view', uuid=product.uuid)
# TODO: deprecate / remove this
SubdepartmentsView = SubdepartmentView