Add "min % diff" option for pricing batch from products query

refactor the "batch from query" a bit also, to allow for multiple batch type
options which represent the same underlying batch type.  (thought i needed
that, then realized i didn't, but seems safe to include.)
This commit is contained in:
Lance Edgar 2018-11-25 20:14:49 -06:00
parent d9e5eff23d
commit 3b54ab3e0b
3 changed files with 56 additions and 35 deletions

View file

@ -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()">
<li>${h.link_to("Back to Products", url('products'))}</li>

View file

@ -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)

View file

@ -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,15 +985,19 @@ 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)
if form.validate(newstyle=True):
data = form.validated
# collect general params
batch_key = data['batch_type']
params = {
'description': data['description'],
'notes': data['notes']}
# collect batch-type-specific params
pform = params_forms.get(batch_key)
if pform:
pdata = pform.validate(controls)
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]
@ -1001,8 +1007,7 @@ class ProductsView(MasterView):
if params[name] is colander.null:
params[name] = None
handler = get_batch_handler(self.rattail_config, batch_key,
default=supported[batch_key].spec)
handler = supported[batch_key]
products = self.get_effective_data()
progress = SessionProgress(self.request, 'products.batch')
thread = Thread(target=self.make_batch_thread,
@ -1013,11 +1018,11 @@ class ProductsView(MasterView):
'cancel_msg': "Batch creation was canceled.",
})
return {
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'),
)