Show proper flags breakdown for products

also expose flag definitions, and tweak vendor views per renamed attributes
This commit is contained in:
Lance Edgar 2019-07-18 10:10:22 -05:00
parent feec4d9703
commit 1391dff932
3 changed files with 83 additions and 11 deletions

View file

@ -95,3 +95,11 @@ class CoreOfficeMasterView(MasterView):
text = "({}) {}".format(department.dept_no, department.dept_name) text = "({}) {}".format(department.dept_no, department.dept_name)
url = self.request.route_url('corepos.departments.view', dept_no=department.dept_no) url = self.request.route_url('corepos.departments.view', dept_no=department.dept_no)
return tags.link_to(text, url) return tags.link_to(text, url)
def render_corepos_vendor(self, obj, field):
vendor = getattr(obj, field)
if not vendor:
return ""
text = "({}) {}".format(vendor.abbreviation, vendor.name)
url = self.request.route_url('corepos.vendors.view', id=vendor.id)
return tags.link_to(text, url)

View file

@ -24,6 +24,8 @@
CORE-POS product views CORE-POS product views
""" """
from webhelpers2.html import HTML
from corepos.db import model as corepos from corepos.db import model as corepos
from .master import CoreOfficeMasterView from .master import CoreOfficeMasterView
@ -56,7 +58,7 @@ class ProductView(CoreOfficeMasterView):
'qttyEnforced': "Qty. Enforced", 'qttyEnforced': "Qty. Enforced",
'idEnforced': "ID Enforced", 'idEnforced': "ID Enforced",
'inUse': "In Use", 'inUse': "In Use",
'numflag': "Num. Flag", 'numflag': "Flags",
'subdept': "Subdept. No.", 'subdept': "Subdept. No.",
'default_vendor_id': "Default Vendor ID", 'default_vendor_id': "Default Vendor ID",
'current_origin_id': "Current Origin ID", 'current_origin_id': "Current Origin ID",
@ -79,8 +81,10 @@ class ProductView(CoreOfficeMasterView):
g.set_joiner('department', lambda q: q.outerjoin(corepos.Department)) g.set_joiner('department', lambda q: q.outerjoin(corepos.Department))
g.set_sorter('department', corepos.Department.dept_name) g.set_sorter('department', corepos.Department.dept_name)
g.set_joiner('vendor', lambda q: q.outerjoin(corepos.Vendor)) g.set_joiner('vendor', lambda q: q.outerjoin(corepos.Vendor,
g.set_sorter('vendor', corepos.Vendor.vendorName) corepos.Vendor.id == corepos.Product.default_vendor_id))
g.set_sorter('vendor', corepos.Vendor.name)
g.set_filter('vendor', corepos.Vendor.name)
g.filters['upc'].default_active = True g.filters['upc'].default_active = True
g.filters['upc'].default_verb = 'equal' g.filters['upc'].default_verb = 'equal'
@ -97,6 +101,10 @@ class ProductView(CoreOfficeMasterView):
def configure_form(self, f): def configure_form(self, f):
super(ProductView, self).configure_form(f) super(ProductView, self).configure_form(f)
f.set_renderer('vendor', self.render_corepos_vendor)
f.set_renderer('numflag', self.render_flags)
f.set_type('start_date', 'datetime_local') f.set_type('start_date', 'datetime_local')
f.set_type('end_date', 'datetime_local') f.set_type('end_date', 'datetime_local')
f.set_type('modified', 'datetime_local') f.set_type('modified', 'datetime_local')
@ -108,6 +116,49 @@ class ProductView(CoreOfficeMasterView):
f.set_type('cost', 'currency') f.set_type('cost', 'currency')
f.set_type('deposit', 'currency') f.set_type('deposit', 'currency')
def render_flags(self, product, field):
flags = product.numflag
if not flags:
return ""
# fetch all flags which are actually defined (supported)
supported = {}
for flag in self.Session.query(corepos.ProductFlag):
supported[flag.bit_number] = flag
# convert product's flag value to string of bits
bflags = bin(flags)[2:] # remove '0b' prefix
bflags = reversed(bflags) # make bit #1 first in string, etc.
# create list of items to show each "set" flag
items = []
for i, bit in enumerate(bflags, 1):
if bit == '1':
flag = supported.get(i)
if flag:
items.append(HTML.tag('li', c=flag.description))
else:
items.append(HTML.tag('li', c="(unsupported bit #{})".format(i)))
return HTML.tag('ul', c=items)
class ProductFlagView(CoreOfficeMasterView):
"""
Master view for product flags
"""
model_class = corepos.ProductFlag
model_title = "CORE-POS Product Flag"
url_prefix = '/core-pos/product-flags'
route_prefix = 'corepos.product_flags'
def configure_grid(self, g):
super(ProductFlagView, self).configure_grid(g)
g.set_link('bit_number')
g.set_link('description')
def includeme(config): def includeme(config):
ProductView.defaults(config) ProductView.defaults(config)
ProductFlagView.defaults(config)

View file

@ -37,22 +37,35 @@ class VendorView(CoreOfficeMasterView):
model_title = "CORE-POS Vendor" model_title = "CORE-POS Vendor"
url_prefix = '/core-pos/vendors' url_prefix = '/core-pos/vendors'
route_prefix = 'corepos.vendors' route_prefix = 'corepos.vendors'
creatable = True
editable = True
deletable = True
labels = { labels = {
'vendorID': "ID", 'id': "ID",
'vendorName': "Name",
'vendorAbbreviation': "Abbreviation",
'discountRate': "Discount Rate",
} }
grid_columns = [ grid_columns = [
'vendorID', 'id',
'vendorName', 'name',
'vendorAbbreviation', 'abbreviation',
'discountRate', 'discount_rate',
'contact', 'contact',
] ]
def configure_grid(self, g):
super(VendorView, self).configure_grid(g)
g.set_link('id')
g.set_link('name')
g.set_link('abbreviation')
def configure_form(self, f):
super(VendorView, self).configure_form(f)
if self.creating:
f.remove_field('contact')
def includeme(config): def includeme(config):
VendorView.defaults(config) VendorView.defaults(config)