diff --git a/tailbone/templates/products/batch.mako b/tailbone/templates/products/batch.mako
index 97b23035..a66d0486 100644
--- a/tailbone/templates/products/batch.mako
+++ b/tailbone/templates/products/batch.mako
@@ -1,7 +1,7 @@
## -*- coding: utf-8; -*-
<%inherit file="/base.mako" />
-<%def name="title()">Products: Create Batch%def>
+<%def name="title()">Create Batch%def>
<%def name="context_menu_items()">
${h.link_to("Back to Products", url('products'))}
diff --git a/tailbone/views/batch/pricing.py b/tailbone/views/batch/pricing.py
index a0fc4011..c3913a8c 100644
--- a/tailbone/views/batch/pricing.py
+++ b/tailbone/views/batch/pricing.py
@@ -49,6 +49,11 @@ class PricingBatchView(BatchMasterView):
rows_editable = True
rows_bulk_deletable = True
+ labels = {
+ 'min_diff_threshold': "Min $ Diff",
+ 'min_diff_percent': "Min % Diff",
+ }
+
grid_columns = [
'id',
'description',
@@ -65,6 +70,7 @@ class PricingBatchView(BatchMasterView):
'id',
'description',
'min_diff_threshold',
+ 'min_diff_percent',
'calculate_for_manual',
'notes',
'created',
@@ -124,6 +130,11 @@ class PricingBatchView(BatchMasterView):
'status_text',
]
+ def configure_form(self, f):
+ super(PricingBatchView, self).configure_form(f)
+
+ f.set_type('min_diff_threshold', 'currency')
+
def configure_row_grid(self, g):
super(PricingBatchView, self).configure_row_grid(g)
diff --git a/tailbone/views/products.py b/tailbone/views/products.py
index 0d49401b..c5f85b9a 100644
--- a/tailbone/views/products.py
+++ b/tailbone/views/products.py
@@ -954,11 +954,13 @@ class ProductsView(MasterView):
"""
supported = self.get_supported_batches()
batch_options = []
- for key, spec in list(supported.items()):
- handler = load_object(spec)(self.rattail_config)
- handler.spec = spec
+ for key, info in list(supported.items()):
+ handler = load_object(info['spec'])(self.rattail_config)
+ handler.spec = info['spec']
+ handler.option_key = key
+ handler.option_title = info.get('title', handler.get_model_title())
supported[key] = handler
- batch_options.append((key, handler.get_model_title()))
+ batch_options.append((key, handler.option_title))
schema = colander.SchemaNode(
colander.Mapping(),
@@ -983,41 +985,44 @@ class ProductsView(MasterView):
params_forms[key] = forms.Form(schema=schema, request=self.request)
if self.request.method == 'POST':
- controls = self.request.POST.items()
- data = form.validate(controls)
- batch_key = data['batch_type']
- params = {
- 'description': data['description'],
- 'notes': data['notes']}
- pform = params_forms.get(batch_key)
- if pform:
- pdata = pform.validate(controls)
- for field in pform.schema:
- param_name = pform.schema[field.name].param_name
- params[param_name] = pdata[field.name]
+ if form.validate(newstyle=True):
+ data = form.validated
- # TODO: should this be done elsewhere?
- for name in params:
- if params[name] is colander.null:
- params[name] = None
+ # collect general params
+ batch_key = data['batch_type']
+ params = {
+ 'description': data['description'],
+ 'notes': data['notes']}
- handler = get_batch_handler(self.rattail_config, batch_key,
- default=supported[batch_key].spec)
- products = self.get_effective_data()
- progress = SessionProgress(self.request, '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.",
- })
+ # 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]
- return {
+ # 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_effective_data()
+ progress = SessionProgress(self.request, '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,
'dform': form.make_deform_form(), # TODO: hacky? at least is explicit..
'params_forms': params_forms,
- }
+ })
def make_batch_params_schema_pricing(self):
"""
@@ -1025,7 +1030,12 @@ class ProductsView(MasterView):
"""
return colander.SchemaNode(
colander.Mapping(),
- colander.SchemaNode(colander.Decimal(), name='min_diff_threshold', quant='1.00', missing=colander.null),
+ colander.SchemaNode(colander.Decimal(), name='min_diff_threshold',
+ quant='1.00', missing=colander.null,
+ title="Min $ Diff"),
+ colander.SchemaNode(colander.Decimal(), name='min_diff_percent',
+ quant='1.00', missing=colander.null,
+ title="Min % Diff"),
colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'),
)