Refactor vendor invoice batch views to use BatchMasterView.
This commit is contained in:
parent
c83a3e6eb0
commit
7ac4af5f34
|
@ -1,3 +0,0 @@
|
||||||
## -*- coding: utf-8 -*-
|
|
||||||
<%inherit file="/batch/create.mako" />
|
|
||||||
${parent.body()}
|
|
|
@ -1,3 +0,0 @@
|
||||||
## -*- coding: utf-8 -*-
|
|
||||||
<%inherit file="/batch/edit.mako" />
|
|
||||||
${parent.body()}
|
|
|
@ -1,3 +0,0 @@
|
||||||
## -*- coding: utf-8 -*-
|
|
||||||
<%inherit file="/batch/index.mako" />
|
|
||||||
${parent.body()}
|
|
|
@ -1,3 +0,0 @@
|
||||||
## -*- coding: utf-8 -*-
|
|
||||||
<%inherit file="/batch/row.view.mako" />
|
|
||||||
${parent.body()}
|
|
|
@ -1,3 +0,0 @@
|
||||||
## -*- coding: utf-8 -*-
|
|
||||||
<%inherit file="/batch/view.mako" />
|
|
||||||
${parent.body()}
|
|
|
@ -66,7 +66,7 @@ class BatchMasterView(MasterView):
|
||||||
rows_viewable = True
|
rows_viewable = True
|
||||||
rows_creatable = False
|
rows_creatable = False
|
||||||
rows_editable = False
|
rows_editable = False
|
||||||
rows_deletable = False
|
rows_deletable = True
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(BatchMasterView, self).__init__(request)
|
super(BatchMasterView, self).__init__(request)
|
||||||
|
|
2
tailbone/views/vendors/catalogs.py
vendored
2
tailbone/views/vendors/catalogs.py
vendored
|
@ -49,7 +49,6 @@ class VendorCatalogsView(FileBatchMasterView):
|
||||||
model_class = model.VendorCatalog
|
model_class = model.VendorCatalog
|
||||||
batch_row_class = model.VendorCatalogRow
|
batch_row_class = model.VendorCatalogRow
|
||||||
batch_handler_class = VendorCatalogHandler
|
batch_handler_class = VendorCatalogHandler
|
||||||
# route_prefix = 'vendorcatalogs'
|
|
||||||
url_prefix = '/vendors/catalogs'
|
url_prefix = '/vendors/catalogs'
|
||||||
|
|
||||||
def get_parsers(self):
|
def get_parsers(self):
|
||||||
|
@ -155,5 +154,4 @@ class VendorCatalogsView(FileBatchMasterView):
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
|
|
||||||
VendorCatalogsView.defaults(config)
|
VendorCatalogsView.defaults(config)
|
||||||
|
|
181
tailbone/views/vendors/invoices.py
vendored
181
tailbone/views/vendors/invoices.py
vendored
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2015 Lance Edgar
|
# Copyright © 2010-2016 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,43 +24,35 @@
|
||||||
Views for maintaining vendor invoices
|
Views for maintaining vendor invoices
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model, api
|
||||||
from rattail.db.api import get_setting, get_vendor
|
|
||||||
from rattail.db.batch.vendorinvoice import VendorInvoice, VendorInvoiceRow
|
|
||||||
from rattail.db.batch.vendorinvoice.handler import VendorInvoiceHandler
|
from rattail.db.batch.vendorinvoice.handler import VendorInvoiceHandler
|
||||||
from rattail.vendors.invoices import iter_invoice_parsers, require_invoice_parser
|
from rattail.vendors.invoices import iter_invoice_parsers, require_invoice_parser
|
||||||
from rattail.util import load_object
|
|
||||||
|
|
||||||
import formalchemy
|
import formalchemy
|
||||||
|
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
from tailbone.views.batch import FileBatchGrid, FileBatchCrud, BatchRowGrid, BatchRowCrud, defaults
|
from tailbone.views.batch import FileBatchMasterView
|
||||||
|
|
||||||
|
|
||||||
class VendorInvoiceGrid(FileBatchGrid):
|
class VendorInvoicesView(FileBatchMasterView):
|
||||||
"""
|
"""
|
||||||
Grid view for vendor invoices.
|
Master view for vendor invoice batches.
|
||||||
"""
|
"""
|
||||||
batch_class = VendorInvoice
|
model_class = model.VendorInvoice
|
||||||
batch_display = "Vendor Invoice"
|
batch_row_class = model.VendorInvoiceRow
|
||||||
route_prefix = 'vendors.invoices'
|
batch_handler_class = VendorInvoiceHandler
|
||||||
|
url_prefix = '/vendors/invoices'
|
||||||
|
|
||||||
def join_map_extras(self):
|
def get_instance_title(self, batch):
|
||||||
return {'vendor': lambda q: q.join(model.Vendor)}
|
return unicode(batch.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):
|
def configure_grid(self, g):
|
||||||
|
g.joiners['vendor'] = lambda q: q.join(model.Vendor)
|
||||||
|
g.filters['vendor'] = g.make_filter('vendor', model.Vendor.name,
|
||||||
|
default_active=True, default_verb='contains')
|
||||||
|
g.sorters['vendor'] = g.make_sorter(model.Vendor.name)
|
||||||
g.configure(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.created,
|
g.created,
|
||||||
|
@ -71,39 +63,42 @@ class VendorInvoiceGrid(FileBatchGrid):
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
|
def configure_fieldset(self, fs):
|
||||||
|
fs.purchase_order_number.set(label=self.handler.po_number_title)
|
||||||
|
fs.purchase_order_number.set(validate=self.validate_po_number)
|
||||||
|
fs.filename.set(label="Invoice File")
|
||||||
|
|
||||||
class VendorInvoiceCrud(FileBatchCrud):
|
if self.creating:
|
||||||
"""
|
parsers = sorted(iter_invoice_parsers(), key=lambda p: p.display)
|
||||||
CRUD view for vendor invoices.
|
parser_options = [(p.display, p.key) for p in parsers]
|
||||||
"""
|
parser_options.insert(0, ("(please choose)", ''))
|
||||||
batch_class = VendorInvoice
|
fs.parser_key.set(label="File Type",
|
||||||
batch_handler_class = VendorInvoiceHandler
|
renderer=formalchemy.fields.SelectFieldRenderer,
|
||||||
route_prefix = 'vendors.invoices'
|
options=parser_options)
|
||||||
|
|
||||||
batch_display = "Vendor Invoice"
|
fs.configure(
|
||||||
flash = {'create': "New vendor invoice has been uploaded.",
|
include=[
|
||||||
'update': "Vendor invoice has been updated.",
|
fs.filename,
|
||||||
'delete': "Vendor invoice has been deleted."}
|
fs.parser_key,
|
||||||
|
fs.purchase_order_number,
|
||||||
|
])
|
||||||
|
|
||||||
def get_handler(self):
|
else:
|
||||||
"""
|
fs.configure(
|
||||||
Returns a `BatchHandler` instance for the view.
|
include=[
|
||||||
|
fs.vendor.readonly(),
|
||||||
Derived classes may override this, but if you only need to replace the
|
fs.filename,
|
||||||
handler (i.e. and not the view logic) then you can instead subclass
|
fs.purchase_order_number,
|
||||||
:class:`rattail.db.batch.vendorinvoice.handler.VendorInvoiceHandler`
|
fs.invoice_date.readonly(),
|
||||||
and create a setting named "rattail.batch.vendorinvoice.handler" in the
|
fs.created,
|
||||||
database, the value of which should be a spec string pointed at your
|
fs.created_by,
|
||||||
custom handler.
|
fs.executed,
|
||||||
"""
|
fs.executed_by,
|
||||||
handler = get_setting(Session, 'rattail.batch.vendorinvoice.handler')
|
])
|
||||||
if not handler:
|
batch = fs.model
|
||||||
handler = self.request.rattail_config.get('rattail.batch', 'vendorinvoice.handler')
|
if not batch.executed:
|
||||||
if handler:
|
del fs.executed
|
||||||
handler = load_object(handler)(self.request.rattail_config)
|
del fs.executed_by
|
||||||
if not handler:
|
|
||||||
handler = super(VendorInvoiceCrud, self).get_handler()
|
|
||||||
return handler
|
|
||||||
|
|
||||||
def validate_po_number(self, value, field):
|
def validate_po_number(self, value, field):
|
||||||
"""
|
"""
|
||||||
|
@ -114,65 +109,24 @@ class VendorInvoiceCrud(FileBatchCrud):
|
||||||
if not parser_key:
|
if not parser_key:
|
||||||
raise formalchemy.ValidationError("Cannot validate PO number until File Type is chosen")
|
raise formalchemy.ValidationError("Cannot validate PO number until File Type is chosen")
|
||||||
parser = require_invoice_parser(parser_key)
|
parser = require_invoice_parser(parser_key)
|
||||||
vendor = get_vendor(Session(), parser.vendor_key)
|
vendor = api.get_vendor(Session(), parser.vendor_key)
|
||||||
try:
|
try:
|
||||||
self.handler.validate_po_number(value, vendor)
|
self.handler.validate_po_number(value, vendor)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
raise formalchemy.ValidationError(unicode(error))
|
raise formalchemy.ValidationError(unicode(error))
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
|
||||||
parsers = sorted(iter_invoice_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.purchase_order_number.set(label=self.handler.po_number_title)
|
|
||||||
fs.purchase_order_number.set(validate=self.validate_po_number)
|
|
||||||
|
|
||||||
fs.configure(
|
|
||||||
include=[
|
|
||||||
fs.vendor.readonly(),
|
|
||||||
fs.filename.label("Invoice File"),
|
|
||||||
fs.parser_key.label("File Type"),
|
|
||||||
fs.purchase_order_number,
|
|
||||||
fs.invoice_date.readonly(),
|
|
||||||
fs.created,
|
|
||||||
fs.created_by,
|
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
|
||||||
])
|
|
||||||
if self.creating:
|
|
||||||
del fs.vendor
|
|
||||||
del fs.invoice_date
|
|
||||||
else:
|
|
||||||
del fs.parser_key
|
|
||||||
|
|
||||||
def init_batch(self, batch):
|
def init_batch(self, batch):
|
||||||
parser = require_invoice_parser(batch.parser_key)
|
parser = require_invoice_parser(batch.parser_key)
|
||||||
vendor = get_vendor(Session, parser.vendor_key)
|
vendor = api.get_vendor(Session(), parser.vendor_key)
|
||||||
if not vendor:
|
if not vendor:
|
||||||
self.request.session.flash("No vendor setting found in database for key: {0}".format(parser.vendor_key))
|
self.request.session.flash("No vendor setting found in database for key: {}".format(parser.vendor_key))
|
||||||
return False
|
return False
|
||||||
batch.vendor = vendor
|
batch.vendor = vendor
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def configure_row_grid(self, g):
|
||||||
class VendorInvoiceRowGrid(BatchRowGrid):
|
g.filters['upc'].label = "UPC"
|
||||||
"""
|
g.filters['brand_name'].label = "Brand"
|
||||||
Grid view for vendor invoice rows.
|
|
||||||
"""
|
|
||||||
row_class = VendorInvoiceRow
|
|
||||||
route_prefix = 'vendors.invoices'
|
|
||||||
|
|
||||||
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(
|
g.configure(
|
||||||
include=[
|
include=[
|
||||||
g.sequence,
|
g.sequence,
|
||||||
|
@ -188,24 +142,17 @@ class VendorInvoiceRowGrid(BatchRowGrid):
|
||||||
],
|
],
|
||||||
readonly=True)
|
readonly=True)
|
||||||
|
|
||||||
def tr_class(self, row, i):
|
def row_grid_row_attrs(self, row, i):
|
||||||
if row.status_code in ((row.STATUS_NOT_IN_PURCHASE,
|
attrs = {}
|
||||||
row.STATUS_NOT_IN_INVOICE,
|
if row.status_code in (row.STATUS_NOT_IN_PURCHASE,
|
||||||
row.STATUS_DIFFERS_FROM_PURCHASE)):
|
row.STATUS_NOT_IN_INVOICE,
|
||||||
return 'notice'
|
row.STATUS_DIFFERS_FROM_PURCHASE):
|
||||||
|
attrs['class_'] = 'notice'
|
||||||
if row.status_code in (row.STATUS_NOT_IN_DB,
|
if row.status_code in (row.STATUS_NOT_IN_DB,
|
||||||
row.STATUS_COST_NOT_IN_DB):
|
row.STATUS_COST_NOT_IN_DB):
|
||||||
return 'warning'
|
attrs['class_'] = 'warning'
|
||||||
|
return attrs
|
||||||
|
|
||||||
class VendorInvoiceRowCrud(BatchRowCrud):
|
|
||||||
row_class = VendorInvoiceRow
|
|
||||||
route_prefix = 'vendors.invoices'
|
|
||||||
batch_display = "Vendor Invoice"
|
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
"""
|
VendorInvoicesView.defaults(config)
|
||||||
Add configuration for the vendor invoice views.
|
|
||||||
"""
|
|
||||||
defaults(config, VendorInvoiceGrid, VendorInvoiceCrud, VendorInvoiceRowGrid, VendorInvoiceRowCrud, '/vendors/invoices/')
|
|
||||||
|
|
Loading…
Reference in a new issue