Allow restricting to supported vendors only, for Receiving

This commit is contained in:
Lance Edgar 2022-05-15 16:45:31 -05:00
parent e3b1be5835
commit cff4942769
2 changed files with 57 additions and 16 deletions

View file

@ -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 &quot;supported&quot; vendor; otherwise they may choose &quot;any&quot; 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;">

View file

@ -311,6 +311,24 @@ class ReceivingBatchView(PurchasingBatchView):
# configure vendor field
app = self.get_rattail_app()
vendor_handler = app.get_vendor_handler()
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:
# user may choose *any* available vendor
use_dropdown = vendor_handler.choice_uses_dropdown()
if use_dropdown:
vendors = self.Session.query(model.Vendor)\
@ -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',