diff --git a/tailbone/views/batch/newproduct.py b/tailbone/views/batch/newproduct.py index d58357d0..bd46ad52 100644 --- a/tailbone/views/batch/newproduct.py +++ b/tailbone/views/batch/newproduct.py @@ -26,6 +26,8 @@ Views for new product batches from rattail.db import model +from deform import widget as dfwidget + from tailbone.views.batch import BatchMasterView @@ -47,11 +49,17 @@ class NewProductBatchView(BatchMasterView): configurable = True has_input_file_templates = True + labels = { + 'type2_lookup': "Type-2 UPC Lookups", + } + form_fields = [ 'id', 'input_filename', 'description', 'notes', + 'type2_lookup', + 'params', 'created', 'created_by', 'rowcount', @@ -127,7 +135,7 @@ class NewProductBatchView(BatchMasterView): ] def configure_form(self, f): - super(NewProductBatchView, self).configure_form(f) + super().configure_form(f) # input_filename if self.creating: @@ -136,6 +144,34 @@ class NewProductBatchView(BatchMasterView): f.set_readonly('input_filename') f.set_renderer('input_filename', self.render_downloadable_file) + # type2_lookup + if self.creating: + values = [ + ('', "(use default behavior)"), + ('always', "Always try Type-2 lookup, when applicable"), + ('never', "Never try Type-2 lookup"), + ] + f.set_widget('type2_lookup', dfwidget.SelectWidget(values=values)) + f.set_default('type2_lookup', '') + else: + f.remove('type2_lookup') + + def save_create_form(self, form): + batch = super().save_create_form(form) + + if 'type2_lookup' in form: + type2_lookup = form.validated['type2_lookup'] + if type2_lookup == 'always': + type2_lookup = True + elif type2_lookup == 'never': + type2_lookup = False + else: + type2_lookup = None + if type2_lookup is not None: + batch.set_param('type2_lookup', type2_lookup) + + return batch + def configure_row_grid(self, g): super(NewProductBatchView, self).configure_row_grid(g)