Fix bugs when making inventory batch on mobile

This commit is contained in:
Lance Edgar 2018-02-01 14:28:24 -06:00
parent d35dc5582e
commit c74bce2fdb
3 changed files with 57 additions and 2 deletions

View file

@ -271,6 +271,38 @@ class BatchMasterView(MasterView):
# return this object to replace the original
return batch
# TODO: this is a totaly copy of save_create_form()
def save_mobile_create_form(self, form):
self.before_create(form)
with Session.no_autoflush:
# transfer form data to batch instance
form.fieldset.sync()
batch = form.fieldset.model
# current user is batch creator
batch.created_by = self.request.user or self.late_login_user()
# destroy initial batch and re-make using handler
kwargs = self.get_batch_kwargs(batch)
Session.expunge(batch)
batch = self.handler.make_batch(Session(), **kwargs)
Session.flush()
# TODO: this needs work yet surely...
# if batch has input data file, let handler properly establish that
filename = getattr(batch, 'filename', None)
if filename:
path = os.path.join(self.upload_dir, filename)
if os.path.exists(path):
self.handler.set_input_file(batch, path)
os.remove(path)
# return this object to replace the original
return batch
def get_batch_kwargs(self, batch, mobile=False):
"""
Return a kwargs dict for use with ``self.handler.make_batch()``, using