New batch system! Hopefully nothing else broke...

Attempt number 5,176 at a decent batch system, we'll see.
This commit is contained in:
Lance Edgar 2015-01-19 00:52:40 -06:00
parent c4a19f279b
commit b05f30d9fe
15 changed files with 1213 additions and 32 deletions

34
tailbone/views/vendors/__init__.py vendored Normal file
View file

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2015 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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Views pertaining to vendors
"""
from __future__ import unicode_literals
from .core import VendorsGrid, VendorCrud, VendorsAutocomplete, add_routes
def includeme(config):
config.include('tailbone.views.vendors.core')
config.include('tailbone.views.vendors.catalogs')

158
tailbone/views/vendors/catalogs.py vendored Normal file
View file

@ -0,0 +1,158 @@
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2015 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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Views for maintaining vendor catalogs
"""
from __future__ import unicode_literals
from rattail.db import model
from rattail.db.api import get_vendor
from rattail.db.batch.vendorcatalog import VendorCatalogHandler
from rattail.vendors.catalogs import iter_catalog_parsers, require_catalog_parser
import formalchemy
from tailbone.db import Session
from tailbone.views.batch import FileBatchGrid, FileBatchCrud, BatchRowGrid, BatchRowCrud, defaults
class VendorCatalogGrid(FileBatchGrid):
"""
Grid view for vendor catalogs.
"""
batch_class = model.VendorCatalog
batch_display = "Vendor Catalog"
route_prefix = 'vendors.catalogs'
def join_map_extras(self):
return {'vendor': lambda q: q.join(model.Vendor)}
def filter_map_extras(self):
return {'vendor': self.filter_ilike(model.Vendor.name)}
def filter_config_extras(self):
return {'filter_type_vendor': 'lk',
'include_filter_vendor': True}
def sort_map_extras(self):
return {'vendor': self.sorter(model.Vendor.name)}
def configure_grid(self, g):
g.configure(
include=[
g.created,
g.created_by,
g.vendor,
g.effective,
g.filename,
g.executed,
],
readonly=True)
class VendorCatalogCrud(FileBatchCrud):
"""
CRUD view for vendor catalogs.
"""
batch_class = model.VendorCatalog
batch_handler_class = VendorCatalogHandler
route_prefix = 'vendors.catalogs'
batch_display = "Vendor Catalog"
flash = {'create': "New vendor catalog has been uploaded.",
'delete': "Vendor catalog has been deleted."}
def configure_fieldset(self, fs):
parsers = sorted(iter_catalog_parsers(), key=lambda p: p.display)
parser_options = [(p.display, p.key) for p in parsers]
parser_options.insert(0, ("(please choose)", ''))
fs.parser_key.set(renderer=formalchemy.fields.SelectFieldRenderer,
options=parser_options)
fs.configure(
include=[
fs.created,
fs.created_by,
fs.vendor,
fs.data_file.label("Catalog File"),
fs.filename,
fs.parser_key.label("File Type"),
fs.effective,
fs.executed,
fs.executed_by,
])
if self.creating:
del fs.vendor
del fs.effective
else:
del fs.parser_key
def init_batch(self, batch):
parser = require_catalog_parser(batch.parser_key)
batch.vendor = get_vendor(Session, parser.vendor_key)
class VendorCatalogRowGrid(BatchRowGrid):
"""
Grid view for vendor catalog rows.
"""
row_class = model.VendorCatalogRow
route_prefix = 'vendors.catalogs'
def filter_map_extras(self):
return {'ilike': ['upc', 'brand_name', 'description', 'size', 'vendor_code']}
def filter_config_extras(self):
return {'filter_label_upc': "UPC",
'filter_label_brand_name': "Brand"}
def configure_grid(self, g):
g.configure(
include=[
g.sequence,
g.upc.label("UPC"),
g.brand_name.label("Brand"),
g.description,
g.size,
g.vendor_code,
g.old_unit_cost.label("Old Cost"),
g.unit_cost.label("New Cost"),
g.unit_cost_diff.label("Diff."),
g.status_code,
],
readonly=True)
def tr_class(self, row, i):
if row.status_code in (row.STATUS_NEW_COST, row.STATUS_UPDATE_COST):
return 'notice'
if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
return 'warning'
class VendorCatalogRowCrud(BatchRowCrud):
row_class = model.VendorCatalogRow
route_prefix = 'vendors.catalogs'
def includeme(config):
defaults(config, VendorCatalogGrid, VendorCatalogCrud, VendorCatalogRowGrid, VendorCatalogRowCrud, '/vendors/catalogs/')

129
tailbone/views/vendors/core.py vendored Normal file
View file

@ -0,0 +1,129 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Vendor Views
"""
from tailbone.views import SearchableAlchemyGridView, CrudView, AutocompleteView
from tailbone.forms import AssociationProxyField, PersonFieldRenderer
from rattail.db.model import Vendor
class VendorsGrid(SearchableAlchemyGridView):
mapped_class = Vendor
config_prefix = 'vendors'
sort = 'name'
def filter_map(self):
return self.make_filter_map(exact=['id'], ilike=['name'])
def filter_config(self):
return self.make_filter_config(
include_filter_name=True,
filter_type_name='lk',
filter_label_id="ID")
def sort_map(self):
return self.make_sort_map('id', 'name')
def grid(self):
g = self.make_grid()
g.append(AssociationProxyField('contact'))
g.configure(
include=[
g.id.label("ID"),
g.name,
g.phone.label("Phone Number"),
g.email.label("Email Address"),
g.contact,
],
readonly=True)
if self.request.has_perm('vendors.read'):
g.viewable = True
g.view_route_name = 'vendor.read'
if self.request.has_perm('vendors.update'):
g.editable = True
g.edit_route_name = 'vendor.update'
if self.request.has_perm('vendors.delete'):
g.deletable = True
g.delete_route_name = 'vendor.delete'
return g
class VendorCrud(CrudView):
mapped_class = Vendor
home_route = 'vendors'
def fieldset(self, model):
fs = self.make_fieldset(model)
fs.append(AssociationProxyField('contact'))
fs.configure(
include=[
fs.id.label("ID"),
fs.name,
fs.special_discount,
fs.phone.label("Phone Number").readonly(),
fs.email.label("Email Address").readonly(),
fs.contact.with_renderer(PersonFieldRenderer).readonly(),
])
return fs
class VendorsAutocomplete(AutocompleteView):
mapped_class = Vendor
fieldname = 'name'
def add_routes(config):
config.add_route('vendors', '/vendors')
config.add_route('vendors.autocomplete', '/vendors/autocomplete')
config.add_route('vendor.create', '/vendors/new')
config.add_route('vendor.read', '/vendors/{uuid}')
config.add_route('vendor.update', '/vendors/{uuid}/edit')
config.add_route('vendor.delete', '/vendors/{uuid}/delete')
def includeme(config):
add_routes(config)
config.add_view(VendorsGrid, route_name='vendors',
renderer='/vendors/index.mako',
permission='vendors.list')
config.add_view(VendorsAutocomplete, route_name='vendors.autocomplete',
renderer='json', permission='vendors.list')
config.add_view(VendorCrud, attr='create', route_name='vendor.create',
renderer='/vendors/crud.mako',
permission='vendors.create')
config.add_view(VendorCrud, attr='read', route_name='vendor.read',
renderer='/vendors/crud.mako',
permission='vendors.read')
config.add_view(VendorCrud, attr='update', route_name='vendor.update',
renderer='/vendors/crud.mako',
permission='vendors.update')
config.add_view(VendorCrud, attr='delete', route_name='vendor.delete',
permission='vendors.delete')