Add validation to PO number for vendor invoices.
This commit is contained in:
parent
e11a599f92
commit
e216ed9281
18
tailbone/views/vendors/invoices.py
vendored
18
tailbone/views/vendors/invoices.py
vendored
|
@ -105,18 +105,34 @@ class VendorInvoiceCrud(FileBatchCrud):
|
|||
handler = super(VendorInvoiceCrud, self).get_handler()
|
||||
return handler
|
||||
|
||||
def validate_po_number(self, value, field):
|
||||
"""
|
||||
Let the invoice handler in effect determine if the user-provided
|
||||
purchase order number is valid.
|
||||
"""
|
||||
parser = require_invoice_parser(field.parent.parser_key.value)
|
||||
vendor = get_vendor(Session(), parser.vendor_key)
|
||||
try:
|
||||
self.handler.validate_po_number(value, vendor)
|
||||
except ValueError as 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.label(self.handler.po_number_title),
|
||||
fs.purchase_order_number,
|
||||
fs.invoice_date.readonly(),
|
||||
fs.created,
|
||||
fs.created_by,
|
||||
|
|
Loading…
Reference in a new issue