Allow restricting to supported vendors only, for Receiving
This commit is contained in:
parent
e3b1be5835
commit
cff4942769
|
@ -3,9 +3,13 @@
|
|||
|
||||
<%def name="form_content()">
|
||||
|
||||
<h3 class="block is-size-3">Supported Workflows</h3>
|
||||
<h3 class="block is-size-3">Workflows</h3>
|
||||
<div class="block" style="padding-left: 2rem;">
|
||||
|
||||
<p class="block">
|
||||
Users can only choose from the workflows enabled below.
|
||||
</p>
|
||||
|
||||
<b-field>
|
||||
<b-checkbox name="rattail.batch.purchase.allow_receiving_from_scratch"
|
||||
v-model="simpleSettings['rattail.batch.purchase.allow_receiving_from_scratch']"
|
||||
|
@ -53,6 +57,20 @@
|
|||
|
||||
</div>
|
||||
|
||||
<h3 class="block is-size-3">Vendors</h3>
|
||||
<div class="block" style="padding-left: 2rem;">
|
||||
|
||||
<b-field message="If set, user must choose a "supported" vendor; otherwise they may choose "any" vendor.">
|
||||
<b-checkbox name="rattail.batch.purchase.supported_vendors_only"
|
||||
v-model="simpleSettings['rattail.batch.purchase.supported_vendors_only']"
|
||||
native-value="true"
|
||||
@input="settingsNeedSaved = true">
|
||||
Only allow batch for "supported" vendors
|
||||
</b-checkbox>
|
||||
</b-field>
|
||||
|
||||
</div>
|
||||
|
||||
<h3 class="block is-size-3">Display</h3>
|
||||
<div class="block" style="padding-left: 2rem;">
|
||||
|
||||
|
|
|
@ -311,26 +311,44 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
# configure vendor field
|
||||
app = self.get_rattail_app()
|
||||
vendor_handler = app.get_vendor_handler()
|
||||
use_dropdown = vendor_handler.choice_uses_dropdown()
|
||||
if use_dropdown:
|
||||
vendors = self.Session.query(model.Vendor)\
|
||||
.order_by(model.Vendor.id)
|
||||
vendor_values = [(vendor.uuid, "({}) {}".format(vendor.id, vendor.name))
|
||||
if self.rattail_config.getbool('rattail.batch', 'purchase.supported_vendors_only'):
|
||||
# only show vendors for which we have dedicated invoice parsers
|
||||
vendors = {}
|
||||
for parser in self.batch_handler.get_supported_invoice_parsers():
|
||||
if parser.vendor_key:
|
||||
vendor = vendor_handler.get_vendor(self.Session(),
|
||||
parser.vendor_key)
|
||||
if vendor:
|
||||
vendors[vendor.uuid] = vendor
|
||||
vendors = sorted(vendors.values(), key=lambda v: v.name)
|
||||
vendor_values = [(vendor.uuid, vendor_handler.render_vendor(vendor))
|
||||
for vendor in vendors]
|
||||
if use_buefy:
|
||||
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
|
||||
else:
|
||||
form.set_widget('vendor', forms.widgets.JQuerySelectWidget(values=vendor_values))
|
||||
else:
|
||||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor'])
|
||||
if vendor:
|
||||
vendor_display = six.text_type(vendor)
|
||||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
form.set_widget('vendor', forms.widgets.JQueryAutocompleteWidget(
|
||||
field_display=vendor_display, service_url=vendors_url))
|
||||
# user may choose *any* available vendor
|
||||
use_dropdown = vendor_handler.choice_uses_dropdown()
|
||||
if use_dropdown:
|
||||
vendors = self.Session.query(model.Vendor)\
|
||||
.order_by(model.Vendor.id)
|
||||
vendor_values = [(vendor.uuid, "({}) {}".format(vendor.id, vendor.name))
|
||||
for vendor in vendors]
|
||||
if use_buefy:
|
||||
form.set_widget('vendor', dfwidget.SelectWidget(values=vendor_values))
|
||||
else:
|
||||
form.set_widget('vendor', forms.widgets.JQuerySelectWidget(values=vendor_values))
|
||||
else:
|
||||
vendor_display = ""
|
||||
if self.request.method == 'POST':
|
||||
if self.request.POST.get('vendor'):
|
||||
vendor = self.Session.query(model.Vendor).get(self.request.POST['vendor'])
|
||||
if vendor:
|
||||
vendor_display = six.text_type(vendor)
|
||||
vendors_url = self.request.route_url('vendors.autocomplete')
|
||||
form.set_widget('vendor', forms.widgets.JQueryAutocompleteWidget(
|
||||
field_display=vendor_display, service_url=vendors_url))
|
||||
form.set_validator('vendor', self.valid_vendor_uuid)
|
||||
|
||||
# configure workflow field
|
||||
|
@ -1876,7 +1894,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
config = self.rattail_config
|
||||
return [
|
||||
|
||||
# supported workflows
|
||||
# workflows
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.allow_receiving_from_scratch',
|
||||
'type': bool},
|
||||
|
@ -1893,6 +1911,11 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
'option': 'purchase.allow_truck_dump_receiving',
|
||||
'type': bool},
|
||||
|
||||
# vendors
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.supported_vendors_only',
|
||||
'type': bool},
|
||||
|
||||
# display
|
||||
{'section': 'rattail.batch',
|
||||
'option': 'purchase.receiving.show_ordered_column_in_grid',
|
||||
|
|
Loading…
Reference in a new issue