Cleanup views for CORE departments a bit

esp. show link to tax rate
This commit is contained in:
Lance Edgar 2023-10-11 18:37:41 -05:00
parent 076860bfcd
commit cfb416578c
2 changed files with 43 additions and 7 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2022 Lance Edgar # Copyright © 2010-2023 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -39,6 +39,7 @@ class DepartmentView(CoreOfficeMasterView):
route_prefix = 'corepos.departments' route_prefix = 'corepos.departments'
labels = { labels = {
'tax_rate_id': "Tax Rate ID",
'see_id': "See ID", 'see_id': "See ID",
'modified_by_id': "Modified by ID", 'modified_by_id': "Modified by ID",
} }
@ -46,7 +47,7 @@ class DepartmentView(CoreOfficeMasterView):
grid_columns = [ grid_columns = [
'number', 'number',
'name', 'name',
'tax', 'tax_rate',
'food_stampable', 'food_stampable',
'limit', 'limit',
'minimum', 'minimum',
@ -60,11 +61,16 @@ class DepartmentView(CoreOfficeMasterView):
] ]
def configure_grid(self, g): def configure_grid(self, g):
super(DepartmentView, self).configure_grid(g) super().configure_grid(g)
# number
g.set_link('number')
g.set_sort_defaults('number')
g.filters['number'].default_active = True g.filters['number'].default_active = True
g.filters['number'].default_verb = 'equal' g.filters['number'].default_verb = 'equal'
# name
g.set_link('name')
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
@ -72,15 +78,37 @@ class DepartmentView(CoreOfficeMasterView):
g.set_label('food_stampable', "FS") g.set_label('food_stampable', "FS")
g.filters['food_stampable'].label = "Food Stampable" g.filters['food_stampable'].label = "Food Stampable"
# currency fields
g.set_type('limit', 'currency')
g.set_type('minimum', 'currency')
# modified
g.set_type('modified', 'datetime_local') g.set_type('modified', 'datetime_local')
g.set_sort_defaults('number') # margin
g.set_renderer('margin', self.render_margin)
g.set_link('number') def render_margin(self, dept, field):
g.set_link('name') margin = getattr(dept, field)
if margin is None:
return
app = self.get_rattail_app()
return app.render_percent(100 * margin)
def configure_form(self, f): def configure_form(self, f):
super(DepartmentView, self).configure_form(f) super().configure_form(f)
# tax_rate
f.set_renderer('tax_rate', self.render_corepos_tax_rate)
# currency fields
f.set_type('limit', 'currency')
f.set_type('minimum', 'currency')
# margin
f.set_renderer('margin', self.render_margin)
# modified
f.set_type('modified', 'datetime_local') f.set_type('modified', 'datetime_local')
def core_office_object_url(self, office_url, department): def core_office_object_url(self, office_url, department):

View file

@ -89,6 +89,14 @@ class CoreMasterView(MasterView):
number=department_number) number=department_number)
return tags.link_to(text, url) return tags.link_to(text, url)
def render_corepos_tax_rate(self, obj, field):
taxrate = getattr(obj, field)
if not taxrate:
return
text = str(taxrate)
url = self.request.route_url('corepos.taxrates.view', id=taxrate.id)
return tags.link_to(text, url)
def render_corepos_vendor(self, obj, field): def render_corepos_vendor(self, obj, field):
vendor = getattr(obj, field) vendor = getattr(obj, field)
if not vendor: if not vendor: