Refactor how batch editing is done; don't include rows for that sometimes
Various other fixes also..for sake of new purchase batches
This commit is contained in:
parent
da8ef9ebd8
commit
7454e611c5
|
@ -3,6 +3,23 @@
|
||||||
|
|
||||||
<%def name="title()">Edit ${model_title}: ${instance_title}</%def>
|
<%def name="title()">Edit ${model_title}: ${instance_title}</%def>
|
||||||
|
|
||||||
|
<%def name="head_tags()">
|
||||||
|
${parent.head_tags()}
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
|
||||||
|
$('form').submit(function() {
|
||||||
|
var submit = $(this).find('input[type="submit"]');
|
||||||
|
if (submit.length) {
|
||||||
|
submit.button('disable').button('option', 'label', "Saving, please wait...");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%def name="context_menu_items()">
|
||||||
<li>${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}</li>
|
<li>${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}</li>
|
||||||
% if master.viewable and request.has_perm('{}.view'.format(permission_prefix)):
|
% if master.viewable and request.has_perm('{}.view'.format(permission_prefix)):
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
% if master.rows_deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)):
|
% if master.rows_deletable and instance_deletable and request.has_perm('{}.delete'.format(permission_prefix)):
|
||||||
<li>${h.link_to("Delete this {}".format(model_title), action_url('delete', instance))}</li>
|
<li>${h.link_to("Delete this {}".format(model_title), action_url('delete', instance))}</li>
|
||||||
% endif
|
% endif
|
||||||
% if master.rows_creatable and request.has_perm('{}.create'.format(permission_prefix)):
|
% if rows_creatable and request.has_perm('{}.create'.format(permission_prefix)):
|
||||||
<li>${h.link_to("Create a new {}".format(model_title), url('{}.create'.format(route_prefix)))}</li>
|
<li>${h.link_to("Create a new {}".format(model_title), url('{}.create'.format(route_prefix)))}</li>
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -50,10 +50,16 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
|
% if master.edit_with_rows:
|
||||||
${form.render(buttons=capture(buttons))|n}
|
${form.render(buttons=capture(buttons))|n}
|
||||||
</div><!-- form-wrapper -->
|
% else:
|
||||||
|
${form.render()|n}
|
||||||
|
% endif
|
||||||
|
</div>
|
||||||
|
|
||||||
${rows_grid.render_complete(allow_save_defaults=False, tools=capture(self.grid_tools))|n}
|
% if master.edit_with_rows:
|
||||||
|
${rows_grid.render_complete(allow_save_defaults=False, tools=capture(self.grid_tools))|n}
|
||||||
|
% endif
|
||||||
|
|
||||||
<div id="execution-options-dialog" style="display: none;">
|
<div id="execution-options-dialog" style="display: none;">
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
${parent.head_tags()}
|
${parent.head_tags()}
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
$('#order-form').click(function() {
|
$('#order-form').click(function() {
|
||||||
% if vendor_cost_count > 199:
|
% if vendor_cost_count > 199:
|
||||||
if (! confirm("This vendor has ${'{:,d}'.format(vendor_cost_count)} cost records.\n\n" +
|
if (! confirm("This vendor has ${'{:,d}'.format(vendor_cost_count)} cost records.\n\n" +
|
||||||
|
@ -14,14 +15,15 @@
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
$(this).button('disable').button('option', 'label', "Working, please wait...");
|
$(this).button('disable').button('option', 'label', "Working, please wait...");
|
||||||
location.href = '${url('purchases.batch.order_form', uuid=instance.uuid)}';
|
location.href = '${url('purchases.batch.order_form', uuid=batch.uuid)}';
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
<%def name="leading_buttons()">
|
<%def name="leading_buttons()">
|
||||||
% if not instance.executed and request.has_perm('purchases.batch.order_form'):
|
% if not batch.complete and not batch.executed and request.has_perm('purchases.batch.order_form'):
|
||||||
<button type="button" id="order-form">View as Order Form</button>
|
<button type="button" id="order-form">View as Order Form</button>
|
||||||
% endif
|
% endif
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -68,6 +68,7 @@ class BatchMasterView(MasterView):
|
||||||
rows_downloadable = True
|
rows_downloadable = True
|
||||||
refreshable = True
|
refreshable = True
|
||||||
refresh_after_create = False
|
refresh_after_create = False
|
||||||
|
edit_with_rows = True
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(BatchMasterView, self).__init__(request)
|
super(BatchMasterView, self).__init__(request)
|
||||||
|
@ -296,6 +297,7 @@ class BatchMasterView(MasterView):
|
||||||
if batch.executed:
|
if batch.executed:
|
||||||
return self.redirect(self.get_action_url('view', batch))
|
return self.redirect(self.get_action_url('view', batch))
|
||||||
|
|
||||||
|
if self.edit_with_rows:
|
||||||
grid = self.make_row_grid(batch=batch)
|
grid = self.make_row_grid(batch=batch)
|
||||||
|
|
||||||
# If user just refreshed the page with a reset instruction, issue a
|
# If user just refreshed the page with a reset instruction, issue a
|
||||||
|
@ -312,7 +314,7 @@ class BatchMasterView(MasterView):
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
if form.validate():
|
if form.validate():
|
||||||
self.save_edit_form(form)
|
self.save_edit_form(form)
|
||||||
self.request.session.flash("{0} {1} has been updated.".format(
|
self.request.session.flash("{} has been updated: {}".format(
|
||||||
self.get_model_title(), self.get_instance_title(batch)))
|
self.get_model_title(), self.get_instance_title(batch)))
|
||||||
return self.redirect_after_edit(batch)
|
return self.redirect_after_edit(batch)
|
||||||
|
|
||||||
|
@ -322,16 +324,23 @@ class BatchMasterView(MasterView):
|
||||||
'instance_deletable': self.deletable_instance(batch),
|
'instance_deletable': self.deletable_instance(batch),
|
||||||
'form': form,
|
'form': form,
|
||||||
'batch': batch,
|
'batch': batch,
|
||||||
'rows_grid': grid,
|
|
||||||
'execute_title': self.get_execute_title(batch),
|
'execute_title': self.get_execute_title(batch),
|
||||||
'execute_enabled': self.executable(batch),
|
'execute_enabled': self.executable(batch),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
context['rendered_execution_options'] = self.render_execution_options(batch)
|
context['rendered_execution_options'] = self.render_execution_options(batch)
|
||||||
|
|
||||||
return self.render_to_response('edit', context)
|
return self.render_to_response('edit', context)
|
||||||
|
|
||||||
|
def rows_creatable_for(self, batch):
|
||||||
|
"""
|
||||||
|
Only allow creating new rows on a batch if it hasn't yet been executed.
|
||||||
|
"""
|
||||||
|
return not batch.executed
|
||||||
|
|
||||||
def create_row(self):
|
def create_row(self):
|
||||||
"""
|
"""
|
||||||
Only allow creating a new row if the batch hasn't yet been executed.
|
Only allow creating a new row if the batch hasn't yet been executed.
|
||||||
|
@ -344,6 +353,8 @@ class BatchMasterView(MasterView):
|
||||||
|
|
||||||
def make_default_row_grid_tools(self, batch):
|
def make_default_row_grid_tools(self, batch):
|
||||||
if self.rows_creatable and not batch.executed:
|
if self.rows_creatable and not batch.executed:
|
||||||
|
permission_prefix = self.get_permission_prefix()
|
||||||
|
if self.request.has_perm('{}.create_row'.format(permission_prefix)):
|
||||||
link = tags.link_to("Create a new {}".format(self.get_row_model_title()),
|
link = tags.link_to("Create a new {}".format(self.get_row_model_title()),
|
||||||
self.get_action_url('create_row', batch))
|
self.get_action_url('create_row', batch))
|
||||||
return HTML.tag('p', c=link)
|
return HTML.tag('p', c=link)
|
||||||
|
@ -358,12 +369,13 @@ class BatchMasterView(MasterView):
|
||||||
|
|
||||||
def redirect_after_edit(self, batch):
|
def redirect_after_edit(self, batch):
|
||||||
"""
|
"""
|
||||||
Redirect back to edit batch page after editing a batch, unless the
|
If refresh flag is set, do that; otherwise go (back) to view/edit page.
|
||||||
refresh flag is set, in which case do that.
|
|
||||||
"""
|
"""
|
||||||
if self.request.params.get('refresh') == 'true':
|
if self.request.params.get('refresh') == 'true':
|
||||||
return self.redirect(self.get_action_url('refresh', batch))
|
return self.redirect(self.get_action_url('refresh', batch))
|
||||||
return self.redirect(self.request.current_route_url())
|
if self.edit_with_rows:
|
||||||
|
return self.redirect(self.get_action_url('edit', batch))
|
||||||
|
return self.redirect(self.get_action_url('view', batch))
|
||||||
|
|
||||||
def delete_instance(self, batch):
|
def delete_instance(self, batch):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1078,6 +1078,7 @@ class MasterView(View):
|
||||||
'instance_title': self.get_row_instance_title(row),
|
'instance_title': self.get_row_instance_title(row),
|
||||||
'instance_editable': self.row_editable(row),
|
'instance_editable': self.row_editable(row),
|
||||||
'instance_deletable': self.row_deletable(row),
|
'instance_deletable': self.row_deletable(row),
|
||||||
|
'rows_creatable': self.rows_creatable and self.rows_creatable_for(parent),
|
||||||
'model_title': self.get_row_model_title(),
|
'model_title': self.get_row_model_title(),
|
||||||
'model_title_plural': self.get_row_model_title_plural(),
|
'model_title_plural': self.get_row_model_title_plural(),
|
||||||
'parent_model_title': self.get_model_title(),
|
'parent_model_title': self.get_model_title(),
|
||||||
|
@ -1088,6 +1089,13 @@ class MasterView(View):
|
||||||
'action_url': self.get_row_action_url,
|
'action_url': self.get_row_action_url,
|
||||||
'form': form})
|
'form': form})
|
||||||
|
|
||||||
|
def rows_creatable_for(self, instance):
|
||||||
|
"""
|
||||||
|
Returns boolean indicating whether or not the given instance should
|
||||||
|
allow new rows to be added to it.
|
||||||
|
"""
|
||||||
|
return True
|
||||||
|
|
||||||
def edit_row(self):
|
def edit_row(self):
|
||||||
"""
|
"""
|
||||||
View for editing an existing model record.
|
View for editing an existing model record.
|
||||||
|
|
|
@ -51,6 +51,7 @@ class PurchaseBatchView(BatchMasterView):
|
||||||
url_prefix = '/purchases/batches'
|
url_prefix = '/purchases/batches'
|
||||||
rows_creatable = True
|
rows_creatable = True
|
||||||
rows_editable = True
|
rows_editable = True
|
||||||
|
edit_with_rows = False
|
||||||
|
|
||||||
def _preconfigure_grid(self, g):
|
def _preconfigure_grid(self, g):
|
||||||
super(PurchaseBatchView, self)._preconfigure_grid(g)
|
super(PurchaseBatchView, self)._preconfigure_grid(g)
|
||||||
|
@ -65,6 +66,10 @@ class PurchaseBatchView(BatchMasterView):
|
||||||
default_active=True, default_verb='contains')
|
default_active=True, default_verb='contains')
|
||||||
g.sorters['buyer'] = g.make_sorter(model.Person.display_name)
|
g.sorters['buyer'] = g.make_sorter(model.Person.display_name)
|
||||||
|
|
||||||
|
if self.request.has_perm('purchases.batch.execute'):
|
||||||
|
g.filters['complete'].default_active = True
|
||||||
|
g.filters['complete'].default_verb = 'is_true'
|
||||||
|
|
||||||
g.date_ordered.set(label="Ordered")
|
g.date_ordered.set(label="Ordered")
|
||||||
|
|
||||||
def configure_grid(self, g):
|
def configure_grid(self, g):
|
||||||
|
@ -82,26 +87,31 @@ class PurchaseBatchView(BatchMasterView):
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
def _preconfigure_fieldset(self, fs):
|
||||||
super(PurchaseBatchView, self)._preconfigure_fieldset(fs)
|
super(PurchaseBatchView, self)._preconfigure_fieldset(fs)
|
||||||
|
fs.vendor.set(renderer=forms.renderers.VendorFieldRenderer)
|
||||||
|
fs.buyer.set(renderer=forms.renderers.EmployeeFieldRenderer)
|
||||||
fs.po_number.set(label="PO Number")
|
fs.po_number.set(label="PO Number")
|
||||||
fs.po_total.set(label="PO Total")
|
fs.po_total.set(label="PO Total", readonly=True)
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
fs.configure(
|
fs.configure(
|
||||||
include=[
|
include=[
|
||||||
|
fs.id,
|
||||||
fs.store,
|
fs.store,
|
||||||
fs.vendor.with_renderer(forms.renderers.VendorFieldRenderer),
|
fs.vendor,
|
||||||
fs.buyer.with_renderer(forms.renderers.EmployeeFieldRenderer),
|
fs.buyer,
|
||||||
fs.date_ordered,
|
fs.date_ordered,
|
||||||
fs.po_number,
|
fs.po_number,
|
||||||
fs.po_total,
|
fs.po_total,
|
||||||
fs.created,
|
fs.created,
|
||||||
fs.created_by,
|
fs.created_by,
|
||||||
|
fs.complete,
|
||||||
fs.executed,
|
fs.executed,
|
||||||
fs.executed_by,
|
fs.executed_by,
|
||||||
])
|
])
|
||||||
|
|
||||||
if self.creating:
|
if self.creating:
|
||||||
del fs.po_total
|
del fs.po_total
|
||||||
|
del fs.complete
|
||||||
|
|
||||||
# default store may be configured
|
# default store may be configured
|
||||||
store = self.rattail_config.get('rattail', 'store')
|
store = self.rattail_config.get('rattail', 'store')
|
||||||
|
@ -119,6 +129,10 @@ class PurchaseBatchView(BatchMasterView):
|
||||||
# default order date is today
|
# default order date is today
|
||||||
fs.model.date_ordered = localtime(self.rattail_config).date()
|
fs.model.date_ordered = localtime(self.rattail_config).date()
|
||||||
|
|
||||||
|
elif self.editing:
|
||||||
|
fs.store.set(readonly=True)
|
||||||
|
fs.vendor.set(readonly=True)
|
||||||
|
|
||||||
def template_kwargs_view(self, **kwargs):
|
def template_kwargs_view(self, **kwargs):
|
||||||
kwargs = super(PurchaseBatchView, self).template_kwargs_view(**kwargs)
|
kwargs = super(PurchaseBatchView, self).template_kwargs_view(**kwargs)
|
||||||
vendor = kwargs['batch'].vendor
|
vendor = kwargs['batch'].vendor
|
||||||
|
|
Loading…
Reference in a new issue