Expose, honor "allow future" setting for vendor catalog batch

This commit is contained in:
Lance Edgar 2022-01-08 12:19:35 -06:00
parent 88b3279e63
commit 2ce7c93aeb
2 changed files with 51 additions and 8 deletions

View file

@ -3,6 +3,19 @@
<%def name="form_content()">
${self.input_file_templates_section()}
<h3 class="block is-size-3">Options</h3>
<div class="block" style="padding-left: 2rem;">
<b-field>
<b-checkbox name="rattail.batch.vendor_catalog.allow_future"
v-model="simpleSettings['rattail.batch.vendor_catalog.allow_future']"
@input="settingsNeedSaved = true">
Allow "future" cost changes
</b-checkbox>
</b-field>
</div>
</%def>

View file

@ -54,13 +54,15 @@ class VendorCatalogView(FileBatchMasterView):
route_prefix = 'vendorcatalogs'
url_prefix = '/vendors/catalogs'
template_prefix = '/batch/vendorcatalog'
editable = False
bulk_deletable = True
results_executable = True
rows_bulk_deletable = True
has_input_file_templates = True
configurable = True
labels = {
'vendor_id': "Vendor ID",
'parser_key': "Parser",
}
grid_columns = [
@ -172,7 +174,9 @@ class VendorCatalogView(FileBatchMasterView):
if not use_buefy:
values.insert(0, ('', "(please choose)"))
f.set_widget('parser_key', dfwidget.SelectWidget(values=values))
f.set_label('parser_key', "File Type")
else:
f.set_readonly('parser_key')
f.set_renderer('parser_key', self.render_parser_key)
# vendor
f.set_renderer('vendor', self.render_vendor)
@ -203,11 +207,23 @@ class VendorCatalogView(FileBatchMasterView):
else:
f.set_readonly('vendor')
# effective
if self.creating:
f.remove('effective')
else:
f.set_readonly('effective')
if self.batch_handler.allow_future():
# effective
f.set_type('effective', 'date_jquery')
else: # future not allowed
f.remove('future',
'effective')
def render_parser_key(self, batch, field):
key = getattr(batch, field)
if not key:
return
app = self.get_rattail_app()
vendor_handler = app.get_vendor_handler()
parser = vendor_handler.get_catalog_parser(key)
return parser.display
def template_kwargs_create(self, **kwargs):
use_buefy = self.get_use_buefy()
@ -254,7 +270,9 @@ class VendorCatalogView(FileBatchMasterView):
kwargs['vendor_id'] = batch.vendor_id
if batch.vendor_name:
kwargs['vendor_name'] = batch.vendor_name
kwargs['future'] = batch.future
if self.batch_handler.allow_future():
kwargs['future'] = batch.future
kwargs['effective'] = batch.effective
return kwargs
def configure_row_grid(self, g):
@ -316,6 +334,18 @@ class VendorCatalogView(FileBatchMasterView):
return kwargs
def configure_get_simple_settings(self):
settings = super(VendorCatalogView, self).configure_get_simple_settings() or []
settings.extend([
# key field
{'section': 'rattail.batch',
'option': 'vendor_catalog.allow_future',
'type': bool},
])
return settings
# TODO: deprecate / remove this
VendorCatalogsView = VendorCatalogView