Allow populate of new pricing batch from products w/ "SRP breach"

This commit is contained in:
Lance Edgar 2020-01-23 10:48:21 -06:00
parent 842882e766
commit e9533727db

View file

@ -53,6 +53,7 @@ class PricingBatchView(BatchMasterView):
labels = {
'min_diff_threshold': "Min $ Diff",
'min_diff_percent': "Min % Diff",
'auto_generate_from_srp_breach': "Automatic (from SRP Breach)",
}
grid_columns = [
@ -74,6 +75,7 @@ class PricingBatchView(BatchMasterView):
'min_diff_threshold',
'min_diff_percent',
'calculate_for_manual',
'auto_generate_from_srp_breach',
'notes',
'created',
'created_by',
@ -153,11 +155,36 @@ class PricingBatchView(BatchMasterView):
f.set_readonly('input_filename')
f.set_renderer('input_filename', self.render_downloadable_file)
# auto_generate_from_srp_breach
if self.creating:
f.set_type('auto_generate_from_srp_breach', 'boolean')
else:
f.remove_field('auto_generate_from_srp_breach')
# note, the input file is normally required, but should *not* be if the
# user wants to auto-generate the new batch
if self.request.method == 'POST':
if self.request.POST.get('auto_generate_from_srp_breach') == 'true':
f.set_required('input_filename', False)
def get_batch_kwargs(self, batch, mobile=False):
kwargs = super(PricingBatchView, self).get_batch_kwargs(batch, mobile=mobile)
kwargs['min_diff_threshold'] = batch.min_diff_threshold
kwargs['min_diff_percent'] = batch.min_diff_percent
kwargs['calculate_for_manual'] = batch.calculate_for_manual
# are we auto-generating from SRP breach?
if self.request.POST.get('auto_generate_from_srp_breach') == 'true':
# assign batch param
params = kwargs.get('params', {})
params['auto_generate_from_srp_breach'] = True
kwargs['params'] = params
# provide default description
if not kwargs.get('description'):
kwargs['description'] = "auto-generated from SRP breach"
return kwargs
def configure_row_grid(self, g):