Let handler restrict available invoice parser options
This commit is contained in:
parent
67c1adcc75
commit
23d38604c4
|
@ -30,7 +30,6 @@ import six
|
|||
|
||||
from rattail.db import model, api
|
||||
from rattail.time import localtime
|
||||
from rattail.vendors.invoices import iter_invoice_parsers
|
||||
|
||||
import colander
|
||||
from deform import widget as dfwidget
|
||||
|
@ -219,6 +218,7 @@ class PurchasingBatchView(BatchMasterView):
|
|||
|
||||
def configure_form(self, f):
|
||||
super(PurchasingBatchView, self).configure_form(f)
|
||||
model = self.model
|
||||
batch = f.model_instance
|
||||
today = localtime(self.rattail_config).date()
|
||||
use_buefy = self.get_use_buefy()
|
||||
|
@ -324,12 +324,23 @@ class PurchasingBatchView(BatchMasterView):
|
|||
|
||||
# invoice_parser_key
|
||||
if self.creating:
|
||||
parsers = sorted(iter_invoice_parsers(), key=lambda p: p.display)
|
||||
kwargs = {}
|
||||
|
||||
if 'vendor_uuid' in self.request.matchdict:
|
||||
vendor = self.Session.query(model.Vendor).get(
|
||||
self.request.matchdict['vendor_uuid'])
|
||||
if vendor:
|
||||
kwargs['vendor'] = vendor
|
||||
|
||||
parsers = self.handler.get_supported_invoice_parsers(**kwargs)
|
||||
parser_values = [(p.key, p.display) for p in parsers]
|
||||
parser_values.insert(0, ('', "(please choose)"))
|
||||
if len(parsers) == 1:
|
||||
f.set_default('invoice_parser_key', parsers[0].key)
|
||||
|
||||
if use_buefy:
|
||||
f.set_widget('invoice_parser_key', dfwidget.SelectWidget(values=parser_values))
|
||||
else:
|
||||
parser_values.insert(0, ('', "(please choose)"))
|
||||
f.set_widget('invoice_parser_key', forms.widgets.JQuerySelectWidget(values=parser_values))
|
||||
else:
|
||||
f.remove_field('invoice_parser_key')
|
||||
|
|
Loading…
Reference in a new issue