Add support for inactivity_months field for delete product batch

This commit is contained in:
Lance Edgar 2021-03-09 11:44:56 -06:00
parent 059b24fac7
commit 7532dc5117
2 changed files with 49 additions and 19 deletions

View file

@ -45,6 +45,19 @@ class DeleteProductBatchView(BatchMasterView):
bulk_deletable = True
rows_bulk_deletable = True
form_fields = [
'id',
'description',
'notes',
'inactivity_months',
'created',
'created_by',
'rowcount',
'status_code',
'executed',
'executed_by',
]
row_grid_columns = [
'sequence',
'upc',

View file

@ -1608,6 +1608,7 @@ class ProductView(MasterView):
if self.request.method == 'POST':
if form.validate(newstyle=True):
data = form.validated
fully_validated = True
# collect general params
batch_key = data['batch_type']
@ -1617,27 +1618,32 @@ class ProductView(MasterView):
# collect batch-type-specific params
pform = params_forms.get(batch_key)
if pform and pform.validate(newstyle=True):
pdata = pform.validated
for field in pform.schema:
param_name = pform.schema[field.name].param_name
params[param_name] = pdata[field.name]
if pform:
if pform.validate(newstyle=True):
pdata = pform.validated
for field in pform.schema:
param_name = pform.schema[field.name].param_name
params[param_name] = pdata[field.name]
else:
fully_validated = False
# TODO: should this be done elsewhere?
for name in params:
if params[name] is colander.null:
params[name] = None
if fully_validated:
handler = supported[batch_key]
products = self.get_products_for_batch(batch_key)
progress = self.make_progress('products.batch')
thread = Thread(target=self.make_batch_thread,
args=(handler, self.request.user.uuid, products, params, progress))
thread.start()
return self.render_progress(progress, {
'cancel_url': self.get_index_url(),
'cancel_msg': "Batch creation was canceled.",
})
# TODO: should this be done elsewhere?
for name in params:
if params[name] is colander.null:
params[name] = None
handler = supported[batch_key]
products = self.get_products_for_batch(batch_key)
progress = self.make_progress('products.batch')
thread = Thread(target=self.make_batch_thread,
args=(handler, self.request.user.uuid, products, params, progress))
thread.start()
return self.render_progress(progress, {
'cancel_url': self.get_index_url(),
'cancel_msg': "Batch creation was canceled.",
})
return self.render_to_response('batch', {
'form': form,
@ -1668,6 +1674,17 @@ class ProductView(MasterView):
colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'),
)
def make_batch_params_schema_delproduct(self):
"""
Return params schema for making a "delete products" batch.
"""
return colander.SchemaNode(
colander.Mapping(),
colander.SchemaNode(colander.Integer(), name='inactivity_months',
# TODO: probably should be configurable
default=18),
)
def make_batch_thread(self, handler, user_uuid, products, params, progress):
"""
Threat target for making a batch from current products query.