Initial support for mobile ordering

plus various other changes required for that
This commit is contained in:
Lance Edgar 2017-08-02 12:08:23 -05:00
parent 5afa832684
commit 65c63dad3e
12 changed files with 289 additions and 30 deletions

View file

@ -354,6 +354,11 @@ class BatchMasterView(MasterView):
batch.complete = True
return self.redirect(self.get_index_url(mobile=True))
def mobile_mark_pending(self):
batch = self.get_instance()
batch.complete = False
return self.redirect(self.get_action_url('view', batch, mobile=True))
def rows_creatable_for(self, batch):
"""
Only allow creating new rows on a batch if it hasn't yet been executed.
@ -370,6 +375,24 @@ class BatchMasterView(MasterView):
return self.redirect(self.get_action_url('view', batch))
return super(BatchMasterView, self).create_row()
def mobile_create_row(self):
"""
Only allow creating a new row if the batch hasn't yet been executed.
"""
batch = self.get_instance()
if batch.executed:
self.request.session.flash("You cannot add new rows to a batch which has been executed")
return self.redirect(self.get_action_url('view', batch, mobile=True))
return super(BatchMasterView, self).mobile_create_row()
def before_create_row(self, form):
batch = self.get_instance()
row = form.fieldset.model
self.handler.add_row(batch, row)
def after_create_row(self, row):
self.handler.refresh_row(row)
def make_default_row_grid_tools(self, batch):
if self.rows_creatable and not batch.executed:
permission_prefix = self.get_permission_prefix()
@ -659,7 +682,8 @@ class BatchMasterView(MasterView):
"""
Batch rows are editable only until batch has been executed.
"""
return self.rows_editable and not row.batch.executed
batch = row.batch
return self.rows_editable and not batch.executed and not batch.complete
def row_edit_action_url(self, row, i):
if self.row_editable(row):
@ -989,6 +1013,11 @@ class BatchMasterView(MasterView):
config.add_view(cls, attr='mobile_mark_complete', route_name='mobile.{}.mark_complete'.format(route_prefix),
permission='{}.edit'.format(permission_prefix))
# mobile mark pending
config.add_route('mobile.{}.mark_pending'.format(route_prefix), '/mobile{}/{{{}}}/mark-pending'.format(url_prefix, model_key))
config.add_view(cls, attr='mobile_mark_pending', route_name='mobile.{}.mark_pending'.format(route_prefix),
permission='{}.edit'.format(permission_prefix))
# execute batch
config.add_route('{}.execute'.format(route_prefix), '{}/{{uuid}}/execute'.format(url_prefix))