Refactor vendor invoice batch views to use master3
This commit is contained in:
parent
97c5e97ccb
commit
33931b4bf2
|
@ -63,7 +63,7 @@
|
|||
|
||||
<%def name="refresh_button()">
|
||||
% if master.viewing and master.batch_refreshable(batch) and request.has_perm('{}.refresh'.format(permission_prefix)):
|
||||
<button type="button" id="refresh-data">Refresh data</button>
|
||||
<button type="button" id="refresh-data">Refresh Data</button>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ class BatchMasterView(MasterView):
|
|||
def get_execute_title(self, batch):
|
||||
if hasattr(self.handler, 'get_execute_title'):
|
||||
return self.handler.get_execute_title(batch)
|
||||
return "Execute this batch"
|
||||
return "Execute Batch"
|
||||
|
||||
def prefill(self):
|
||||
"""
|
||||
|
|
135
tailbone/views/vendors/invoices.py
vendored
135
tailbone/views/vendors/invoices.py
vendored
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2017 Lance Edgar
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -29,10 +29,11 @@ from __future__ import unicode_literals, absolute_import
|
|||
from rattail.db import model, api
|
||||
from rattail.vendors.invoices import iter_invoice_parsers, require_invoice_parser
|
||||
|
||||
import formalchemy
|
||||
# import formalchemy
|
||||
import colander
|
||||
from deform import widget as dfwidget
|
||||
|
||||
from tailbone.db import Session
|
||||
from tailbone.views.batch import FileBatchMasterView2 as FileBatchMasterView
|
||||
from tailbone.views.batch import FileBatchMasterView3 as FileBatchMasterView
|
||||
|
||||
|
||||
class VendorInvoicesView(FileBatchMasterView):
|
||||
|
@ -45,11 +46,27 @@ class VendorInvoicesView(FileBatchMasterView):
|
|||
url_prefix = '/vendors/invoices'
|
||||
|
||||
grid_columns = [
|
||||
'id',
|
||||
'vendor',
|
||||
'invoice_date',
|
||||
'purchase_order_number',
|
||||
'filename',
|
||||
'created',
|
||||
'created_by',
|
||||
'executed',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
'id',
|
||||
'vendor',
|
||||
'filename',
|
||||
'parser_key',
|
||||
'purchase_order_number',
|
||||
'invoice_date',
|
||||
'created',
|
||||
'created_by',
|
||||
'executed',
|
||||
'executed_by',
|
||||
]
|
||||
|
||||
row_grid_columns = [
|
||||
|
@ -70,56 +87,78 @@ class VendorInvoicesView(FileBatchMasterView):
|
|||
|
||||
def configure_grid(self, g):
|
||||
super(VendorInvoicesView, self).configure_grid(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)
|
||||
|
||||
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")
|
||||
# vendor
|
||||
g.set_joiner('vendor', lambda q: q.join(model.Vendor))
|
||||
g.set_filter('vendor', model.Vendor.name,
|
||||
default_active=True,
|
||||
default_verb='contains')
|
||||
g.set_sorter('vendor', model.Vendor.name)
|
||||
g.set_link('vendor')
|
||||
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.vendor.readonly(),
|
||||
fs.filename,
|
||||
fs.parser_key,
|
||||
fs.purchase_order_number,
|
||||
fs.invoice_date.readonly(),
|
||||
fs.created,
|
||||
fs.created_by,
|
||||
fs.executed,
|
||||
fs.executed_by,
|
||||
])
|
||||
# invoice_date
|
||||
g.set_link('invoice_date')
|
||||
|
||||
# purchase_order_number
|
||||
g.set_link('purchase_order_number')
|
||||
|
||||
# filename
|
||||
g.set_link('filename')
|
||||
|
||||
# created
|
||||
g.set_link('created', False)
|
||||
|
||||
# executed
|
||||
g.set_link('executed', False)
|
||||
|
||||
def configure_form(self, f):
|
||||
super(VendorInvoicesView, self).configure_form(f)
|
||||
|
||||
# vendor
|
||||
if self.creating:
|
||||
f.remove_field('vendor')
|
||||
else:
|
||||
f.set_readonly('vendor')
|
||||
|
||||
# purchase_order_number
|
||||
f.set_label('purchase_order_number', self.handler.po_number_title)
|
||||
# f.set_validator('purchase_order_number', self.validate_po_number)
|
||||
|
||||
# filename
|
||||
f.set_label('filename', "Invoice File")
|
||||
|
||||
# invoice_date
|
||||
if self.creating:
|
||||
f.remove_field('invoice_date')
|
||||
else:
|
||||
f.set_readonly('invoice_date')
|
||||
|
||||
# parser_key
|
||||
if self.creating:
|
||||
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(label="File Type",
|
||||
renderer=formalchemy.fields.SelectFieldRenderer,
|
||||
options=parser_options)
|
||||
del fs.vendor
|
||||
del fs.invoice_date
|
||||
|
||||
parser_values = [(p.key, p.display) for p in parsers]
|
||||
parser_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('parser_key', dfwidget.SelectWidget(values=parser_values))
|
||||
f.set_label('parser_key', "File Type")
|
||||
else:
|
||||
del fs.parser_key
|
||||
f.remove_field('parser_key')
|
||||
|
||||
def validate_po_number(self, value, field):
|
||||
"""
|
||||
Let the invoice handler in effect determine if the user-provided
|
||||
purchase order number is valid.
|
||||
"""
|
||||
parser_key = field.parent.parser_key.value
|
||||
if not parser_key:
|
||||
raise formalchemy.ValidationError("Cannot validate PO number until File Type is chosen")
|
||||
parser = require_invoice_parser(parser_key)
|
||||
vendor = api.get_vendor(Session(), parser.vendor_key)
|
||||
try:
|
||||
self.handler.validate_po_number(value, vendor)
|
||||
except ValueError as error:
|
||||
raise formalchemy.ValidationError(unicode(error))
|
||||
# TODO: this is not needed for now, and this whole thing should be merged
|
||||
# with the Purchasing Batch system anyway...
|
||||
# def validate_po_number(self, value, field):
|
||||
# """
|
||||
# Let the invoice handler in effect determine if the user-provided
|
||||
# purchase order number is valid.
|
||||
# """
|
||||
# parser_key = field.parent.parser_key.value
|
||||
# if not parser_key:
|
||||
# raise formalchemy.ValidationError("Cannot validate PO number until File Type is chosen")
|
||||
# parser = require_invoice_parser(parser_key)
|
||||
# vendor = api.get_vendor(self.Session(), parser.vendor_key)
|
||||
# try:
|
||||
# self.handler.validate_po_number(value, vendor)
|
||||
# except ValueError as error:
|
||||
# raise formalchemy.ValidationError(unicode(error))
|
||||
|
||||
def get_batch_kwargs(self, batch):
|
||||
kwargs = super(VendorInvoicesView, self).get_batch_kwargs(batch)
|
||||
|
@ -128,7 +167,7 @@ class VendorInvoicesView(FileBatchMasterView):
|
|||
|
||||
def init_batch(self, batch):
|
||||
parser = require_invoice_parser(batch.parser_key)
|
||||
vendor = api.get_vendor(Session(), parser.vendor_key)
|
||||
vendor = api.get_vendor(self.Session(), parser.vendor_key)
|
||||
if not vendor:
|
||||
self.request.session.flash("No vendor setting found in database for key: {}".format(parser.vendor_key))
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue