From 6943298ee0555e5b8e1f41387613e7b793c86ef6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 12 Jul 2014 16:02:54 -0700 Subject: [PATCH] Add product report codes to the UI. --- setup.py | 2 +- tailbone/templates/reportcodes/crud.mako | 13 +++ tailbone/templates/reportcodes/index.mako | 12 +++ tailbone/views/__init__.py | 6 +- tailbone/views/products.py | 11 ++- tailbone/views/reportcodes.py | 112 ++++++++++++++++++++++ 6 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 tailbone/templates/reportcodes/crud.mako create mode 100644 tailbone/templates/reportcodes/index.mako create mode 100644 tailbone/views/reportcodes.py diff --git a/setup.py b/setup.py index 2d71de97..30787d8c 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ requires = [ 'pyramid_exclog', # 0.6 'pyramid_simpleform', # 0.6.1 'pyramid_tm', # 0.3 - 'rattail[db]>=0.3.18', # 0.3.18 + u'rattail[db]>=0.3.32', # 0.3.32 'transaction', # 1.2.0 'waitress', # 0.8.1 'WebHelpers', # 1.3 diff --git a/tailbone/templates/reportcodes/crud.mako b/tailbone/templates/reportcodes/crud.mako new file mode 100644 index 00000000..84e5db43 --- /dev/null +++ b/tailbone/templates/reportcodes/crud.mako @@ -0,0 +1,13 @@ +## -*- coding: utf-8 -*- +<%inherit file="/crud.mako" /> + +<%def name="context_menu_items()"> +
  • ${h.link_to(u"Back to Report Codes", url(u'reportcodes'))}
  • + % if form.readonly: +
  • ${h.link_to(u"Edit this Report Code", url(u'reportcode.update', uuid=form.fieldset.model.uuid))}
  • + % elif form.updating: +
  • ${h.link_to(u"View this Report Code", url(u'reportcode.read', uuid=form.fieldset.model.uuid))}
  • + % endif + + +${parent.body()} diff --git a/tailbone/templates/reportcodes/index.mako b/tailbone/templates/reportcodes/index.mako new file mode 100644 index 00000000..c2d1391e --- /dev/null +++ b/tailbone/templates/reportcodes/index.mako @@ -0,0 +1,12 @@ +## -*- coding: utf-8 -*- +<%inherit file="/grid.mako" /> + +<%def name="title()">Report Codes + +<%def name="context_menu_items()"> + % if request.has_perm(u'reportcodes.create'): +
  • ${h.link_to(u"Create a new Report Code", url(u'reportcode.create'))}
  • + % endif + + +${parent.body()} diff --git a/tailbone/views/__init__.py b/tailbone/views/__init__.py index 2da18b69..adc82ac6 100644 --- a/tailbone/views/__init__.py +++ b/tailbone/views/__init__.py @@ -1,9 +1,8 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2012 Lance Edgar +# Copyright © 2010-2014 Lance Edgar # # This file is part of Rattail. # @@ -63,6 +62,7 @@ def includeme(config): config.include('tailbone.views.people') config.include('tailbone.views.products') config.include('tailbone.views.progress') + config.include(u'tailbone.views.reportcodes') config.include('tailbone.views.roles') config.include('tailbone.views.stores') config.include('tailbone.views.subdepartments') diff --git a/tailbone/views/products.py b/tailbone/views/products.py index 16878034..efa208db 100644 --- a/tailbone/views/products.py +++ b/tailbone/views/products.py @@ -1,9 +1,8 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2012 Lance Edgar +# Copyright © 2010-2014 Lance Edgar # # This file is part of Rattail. # @@ -102,6 +101,8 @@ class ProductsGrid(SearchableAlchemyGridView): 'subdepartment': lambda q: q.outerjoin(Subdepartment, Subdepartment.uuid == Product.subdepartment_uuid), + u'report_code': + lambda q: q.outerjoin(model.ReportCode), 'regular_price': lambda q: q.outerjoin(ProductPrice, ProductPrice.uuid == Product.regular_price_uuid), @@ -146,6 +147,7 @@ class ProductsGrid(SearchableAlchemyGridView): brand=self.filter_ilike(Brand.name), family=self.filter_ilike(model.Family.name), department=self.filter_ilike(Department.name), + report_code=self.filter_ilike(model.ReportCode.name), subdepartment=self.filter_ilike(Subdepartment.name), vendor=self.filter_ilike(Vendor.name), vendor_any=self.filter_ilike(self.VendorAny.name), @@ -257,8 +259,9 @@ class ProductCrud(CrudView): fs.description, fs.size, fs.department, - fs.family, fs.subdepartment, + fs.family, + fs.report_code, fs.regular_price, fs.current_price, ]) diff --git a/tailbone/views/reportcodes.py b/tailbone/views/reportcodes.py new file mode 100644 index 00000000..74347af0 --- /dev/null +++ b/tailbone/views/reportcodes.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2014 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Rattail. If not, see . +# +################################################################################ + +""" +Report Code Views +""" + +from tailbone.views import SearchableAlchemyGridView, CrudView + +from rattail.db import model + + +class ReportCodesGrid(SearchableAlchemyGridView): + + mapped_class = model.ReportCode + config_prefix = u'reportcodes' + sort = u'name' + + def filter_map(self): + return self.make_filter_map( + exact=[u'code'], + ilike=[u'name']) + + def filter_config(self): + return self.make_filter_config( + include_filter_name=True, + filter_type_name=u'lk') + + def sort_map(self): + return self.make_sort_map(u'code', u'name') + + def grid(self): + g = self.make_grid() + g.configure( + include=[ + g.code, + g.name, + ], + readonly=True) + if self.request.has_perm(u'reportcodes.read'): + g.viewable = True + g.view_route_name = u'reportcode.read' + if self.request.has_perm(u'reportcodes.update'): + g.editable = True + g.edit_route_name = u'reportcode.update' + if self.request.has_perm(u'reportcodes.delete'): + g.deletable = True + g.delete_route_name = u'reportcode.delete' + return g + + +class ReportCodeCrud(CrudView): + + mapped_class = model.ReportCode + home_route = u'reportcodes' + + def fieldset(self, model): + fs = self.make_fieldset(model) + fs.configure( + include=[ + fs.code, + fs.name, + ]) + return fs + + +def add_routes(config): + config.add_route(u'reportcodes', u'/reportcodes') + config.add_route(u'reportcode.create', u'/reportcodes/new') + config.add_route(u'reportcode.read', u'/reportcodes/{uuid}') + config.add_route(u'reportcode.update', u'/reportcodes/{uuid}/edit') + config.add_route(u'reportcode.delete', u'/reportcodes/{uuid}/delete') + + +def includeme(config): + add_routes(config) + + config.add_view(ReportCodesGrid, route_name=u'reportcodes', + renderer=u'/reportcodes/index.mako', + permission=u'reportcodes.list') + + config.add_view(ReportCodeCrud, attr=u'create', route_name=u'reportcode.create', + renderer=u'/reportcodes/crud.mako', + permission=u'reportcodes.create') + config.add_view(ReportCodeCrud, attr=u'read', route_name=u'reportcode.read', + renderer=u'/reportcodes/crud.mako', + permission=u'reportcodes.read') + config.add_view(ReportCodeCrud, attr=u'update', route_name=u'reportcode.update', + renderer=u'/reportcodes/crud.mako', + permission=u'reportcodes.update') + config.add_view(ReportCodeCrud, attr=u'delete', route_name=u'reportcode.delete', + permission=u'reportcodes.delete')