Allow batch execution to require options on a per-batch basis

plus some other changes i think..
This commit is contained in:
Lance Edgar 2017-08-16 23:27:27 -05:00
parent 98ca378302
commit 3477637c74
5 changed files with 26 additions and 15 deletions

View file

@ -7,7 +7,7 @@
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.batch.js'))}
<script type="text/javascript">
var has_execution_options = ${'true' if master.has_execution_options else 'false'};
var has_execution_options = ${'true' if master.has_execution_options(batch) else 'false'};
$(function() {
@ -69,7 +69,7 @@
<div id="execution-options-dialog" style="display: none;">
${h.form(url('{}.execute'.format(route_prefix), uuid=batch.uuid), name='batch-execution')}
% if master.has_execution_options:
% if master.has_execution_options(batch):
${rendered_execution_options|n}
% endif
${h.end_form()}

View file

@ -5,7 +5,7 @@
${parent.extra_javascript()}
<script type="text/javascript">
var has_execution_options = ${'true' if master.has_execution_options else 'false'};
var has_execution_options = ${'true' if master.has_execution_options(batch) else 'false'};
$(function() {
@ -61,7 +61,7 @@ ${parent.body()}
be aggregated and treated as a single data source, during execution.
</p>
<br />
% if master.has_execution_options:
% if master.has_execution_options(batch):
${rendered_execution_options|n}
% endif
${h.end_form()}

View file

@ -7,7 +7,7 @@
${h.javascript_link(request.static_url('tailbone:static/js/tailbone.batch.js'))}
<script type="text/javascript">
var has_execution_options = ${'true' if master.has_execution_options else 'false'};
var has_execution_options = ${'true' if master.has_execution_options(batch) else 'false'};
$(function() {
% if master.has_worksheet:
@ -89,7 +89,7 @@ ${rows_grid|n}
${h.form(url('{}.execute'.format(route_prefix), uuid=batch.uuid), name='batch-execution')}
${h.csrf_token(request)}
% if master.has_execution_options:
% if master.has_execution_options(batch):
${rendered_execution_options|n}
% endif
${h.end_form()}

View file

@ -109,7 +109,7 @@ class BatchMasterView(MasterView):
kwargs['handler'] = self.handler
kwargs['execute_title'] = self.get_execute_title(batch)
kwargs['execute_enabled'] = self.instance_executable(batch)
if kwargs['execute_enabled'] and self.has_execution_options:
if kwargs['execute_enabled'] and self.has_execution_options(batch):
kwargs['rendered_execution_options'] = self.render_execution_options(batch)
return kwargs
@ -118,7 +118,7 @@ class BatchMasterView(MasterView):
def template_kwargs_index(self, **kwargs):
kwargs['execute_enabled'] = self.instance_executable(None)
if kwargs['execute_enabled'] and self.has_execution_options:
if kwargs['execute_enabled'] and self.has_execution_options():
kwargs['rendered_execution_options'] = self.render_execution_options()
return kwargs
@ -350,7 +350,7 @@ class BatchMasterView(MasterView):
if self.edit_with_rows:
context['rows_grid'] = grid
if context['execute_enabled'] and self.has_execution_options:
if context['execute_enabled'] and self.has_execution_options(batch):
context['rendered_execution_options'] = self.render_execution_options(batch)
return self.render_to_response('edit', context)
@ -474,8 +474,7 @@ class BatchMasterView(MasterView):
# TODO: deprecate/remove this
return self.handler.refreshable and not batch.executed
@property
def has_execution_options(self):
def has_execution_options(self, batch=None):
return bool(self.execution_options_schema)
# TODO
@ -750,7 +749,7 @@ class BatchMasterView(MasterView):
if self.request.method == 'POST':
kwargs = {}
if self.has_execution_options:
if self.has_execution_options(batch):
form = self.make_execution_options_form(batch)
assert form.validate() # TODO
kwargs.update(form.data)
@ -833,7 +832,7 @@ class BatchMasterView(MasterView):
if self.request.method == 'POST':
kwargs = {}
if self.has_execution_options:
if self.has_execution_options():
form = self.make_execution_options_form()
if not form.validate():
raise RuntimeError("Execution options form did not validate")

View file

@ -52,8 +52,10 @@ class InventoryBatchView(BatchMasterView):
default_handler_spec = 'rattail.batch.inventory:InventoryBatchHandler'
route_prefix = 'batch.inventory'
url_prefix = '/batch/inventory'
index_title = "Inventory"
creatable = False
mobile_creatable = True
mobile_rows_creatable = True
grid_columns = [
'id',
@ -147,6 +149,7 @@ class InventoryBatchView(BatchMasterView):
])
if not self.creating:
fs.mode.set(readonly=True)
fs.reason_code.set(readonly=True)
def row_editable(self, row):
return self.mutable_batch(row.batch)
@ -246,12 +249,15 @@ class InventoryBatchView(BatchMasterView):
"""
self.viewing = True
row = self.get_row_instance()
parent = self.get_parent(row)
form = self.make_mobile_row_form(row)
context = {
'row': row,
'instance': row,
'instance_title': self.get_row_instance_title(row),
'parent_model_title': self.get_model_title(),
'parent_title': self.get_instance_title(parent),
'parent_url': self.get_action_url('view', parent, mobile=True),
'product_image_url': pod.get_image_url(self.rattail_config, row.upc),
'form': form,
}
@ -273,6 +279,13 @@ class InventoryBatchView(BatchMasterView):
return self.render_to_response('view_row', context, mobile=True)
def get_row_instance_title(self, row):
if row.upc:
return row.upc.pretty()
if row.item_id:
return row.item_id
return "row {}".format(row.sequence)
def configure_row_grid(self, g):
super(InventoryBatchView, self).configure_row_grid(g)
@ -345,12 +358,11 @@ class InventoryBatchView(BatchMasterView):
route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix()
permission_prefix = cls.get_permission_prefix()
row_permission_prefix = cls.get_row_permission_prefix()
# mobile - make new row from UPC
config.add_route('mobile.{}.row_from_upc'.format(route_prefix), '/mobile{}/{{{}}}/row-from-upc'.format(url_prefix, model_key))
config.add_view(cls, attr='mobile_row_from_upc', route_name='mobile.{}.row_from_upc'.format(route_prefix),
permission='{}.create'.format(row_permission_prefix))
permission='{}.create_row'.format(permission_prefix))
# extra perms for creating batches per "mode"
config.add_tailbone_permission(permission_prefix, '{}.create.replace'.format(permission_prefix),