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:
parent
d9e5eff23d
commit
3b54ab3e0b
|
@ -1,7 +1,7 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<%inherit file="/base.mako" />
|
<%inherit file="/base.mako" />
|
||||||
|
|
||||||
<%def name="title()">Products: Create Batch</%def>
|
<%def name="title()">Create Batch</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%def name="context_menu_items()">
|
||||||
<li>${h.link_to("Back to Products", url('products'))}</li>
|
<li>${h.link_to("Back to Products", url('products'))}</li>
|
||||||
|
|
|
@ -49,6 +49,11 @@ class PricingBatchView(BatchMasterView):
|
||||||
rows_editable = True
|
rows_editable = True
|
||||||
rows_bulk_deletable = True
|
rows_bulk_deletable = True
|
||||||
|
|
||||||
|
labels = {
|
||||||
|
'min_diff_threshold': "Min $ Diff",
|
||||||
|
'min_diff_percent': "Min % Diff",
|
||||||
|
}
|
||||||
|
|
||||||
grid_columns = [
|
grid_columns = [
|
||||||
'id',
|
'id',
|
||||||
'description',
|
'description',
|
||||||
|
@ -65,6 +70,7 @@ class PricingBatchView(BatchMasterView):
|
||||||
'id',
|
'id',
|
||||||
'description',
|
'description',
|
||||||
'min_diff_threshold',
|
'min_diff_threshold',
|
||||||
|
'min_diff_percent',
|
||||||
'calculate_for_manual',
|
'calculate_for_manual',
|
||||||
'notes',
|
'notes',
|
||||||
'created',
|
'created',
|
||||||
|
@ -124,6 +130,11 @@ class PricingBatchView(BatchMasterView):
|
||||||
'status_text',
|
'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):
|
def configure_row_grid(self, g):
|
||||||
super(PricingBatchView, self).configure_row_grid(g)
|
super(PricingBatchView, self).configure_row_grid(g)
|
||||||
|
|
||||||
|
|
|
@ -954,11 +954,13 @@ class ProductsView(MasterView):
|
||||||
"""
|
"""
|
||||||
supported = self.get_supported_batches()
|
supported = self.get_supported_batches()
|
||||||
batch_options = []
|
batch_options = []
|
||||||
for key, spec in list(supported.items()):
|
for key, info in list(supported.items()):
|
||||||
handler = load_object(spec)(self.rattail_config)
|
handler = load_object(info['spec'])(self.rattail_config)
|
||||||
handler.spec = spec
|
handler.spec = info['spec']
|
||||||
|
handler.option_key = key
|
||||||
|
handler.option_title = info.get('title', handler.get_model_title())
|
||||||
supported[key] = handler
|
supported[key] = handler
|
||||||
batch_options.append((key, handler.get_model_title()))
|
batch_options.append((key, handler.option_title))
|
||||||
|
|
||||||
schema = colander.SchemaNode(
|
schema = colander.SchemaNode(
|
||||||
colander.Mapping(),
|
colander.Mapping(),
|
||||||
|
@ -983,15 +985,19 @@ class ProductsView(MasterView):
|
||||||
params_forms[key] = forms.Form(schema=schema, request=self.request)
|
params_forms[key] = forms.Form(schema=schema, request=self.request)
|
||||||
|
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
controls = self.request.POST.items()
|
if form.validate(newstyle=True):
|
||||||
data = form.validate(controls)
|
data = form.validated
|
||||||
|
|
||||||
|
# collect general params
|
||||||
batch_key = data['batch_type']
|
batch_key = data['batch_type']
|
||||||
params = {
|
params = {
|
||||||
'description': data['description'],
|
'description': data['description'],
|
||||||
'notes': data['notes']}
|
'notes': data['notes']}
|
||||||
|
|
||||||
|
# collect batch-type-specific params
|
||||||
pform = params_forms.get(batch_key)
|
pform = params_forms.get(batch_key)
|
||||||
if pform:
|
if pform and pform.validate(newstyle=True):
|
||||||
pdata = pform.validate(controls)
|
pdata = pform.validated
|
||||||
for field in pform.schema:
|
for field in pform.schema:
|
||||||
param_name = pform.schema[field.name].param_name
|
param_name = pform.schema[field.name].param_name
|
||||||
params[param_name] = pdata[field.name]
|
params[param_name] = pdata[field.name]
|
||||||
|
@ -1001,8 +1007,7 @@ class ProductsView(MasterView):
|
||||||
if params[name] is colander.null:
|
if params[name] is colander.null:
|
||||||
params[name] = None
|
params[name] = None
|
||||||
|
|
||||||
handler = get_batch_handler(self.rattail_config, batch_key,
|
handler = supported[batch_key]
|
||||||
default=supported[batch_key].spec)
|
|
||||||
products = self.get_effective_data()
|
products = self.get_effective_data()
|
||||||
progress = SessionProgress(self.request, 'products.batch')
|
progress = SessionProgress(self.request, 'products.batch')
|
||||||
thread = Thread(target=self.make_batch_thread,
|
thread = Thread(target=self.make_batch_thread,
|
||||||
|
@ -1013,11 +1018,11 @@ class ProductsView(MasterView):
|
||||||
'cancel_msg': "Batch creation was canceled.",
|
'cancel_msg': "Batch creation was canceled.",
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return self.render_to_response('batch', {
|
||||||
'form': form,
|
'form': form,
|
||||||
'dform': form.make_deform_form(), # TODO: hacky? at least is explicit..
|
'dform': form.make_deform_form(), # TODO: hacky? at least is explicit..
|
||||||
'params_forms': params_forms,
|
'params_forms': params_forms,
|
||||||
}
|
})
|
||||||
|
|
||||||
def make_batch_params_schema_pricing(self):
|
def make_batch_params_schema_pricing(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1025,7 +1030,12 @@ class ProductsView(MasterView):
|
||||||
"""
|
"""
|
||||||
return colander.SchemaNode(
|
return colander.SchemaNode(
|
||||||
colander.Mapping(),
|
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'),
|
colander.SchemaNode(colander.Boolean(), name='calculate_for_manual'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue