Catch and show error, if one happens when making batch from product query
This commit is contained in:
parent
e19119194d
commit
ee65d08d81
|
@ -40,7 +40,7 @@ from rattail.db import model, api, auth, Session as RattailSession
|
|||
from rattail.gpc import GPC
|
||||
from rattail.threads import Thread
|
||||
from rattail.exceptions import LabelPrintingError
|
||||
from rattail.util import load_object, pretty_quantity, OrderedDict
|
||||
from rattail.util import load_object, pretty_quantity, OrderedDict, simple_error
|
||||
from rattail.batch import get_batch_handler
|
||||
from rattail.time import localtime, make_utc
|
||||
|
||||
|
@ -1693,14 +1693,29 @@ class ProductView(MasterView):
|
|||
user = session.query(model.User).get(user_uuid)
|
||||
assert user
|
||||
params['created_by'] = user
|
||||
try:
|
||||
batch = handler.make_batch(session, **params)
|
||||
batch.products = products.with_session(session).all()
|
||||
handler.do_populate(batch, user, progress=progress)
|
||||
|
||||
except Exception as error:
|
||||
session.rollback()
|
||||
log.exception("failed to make '%s' batch with params: %s",
|
||||
handler.batch_key, params)
|
||||
session.close()
|
||||
if progress:
|
||||
progress.session.load()
|
||||
progress.session['error'] = True
|
||||
progress.session['error_msg'] = "Failed to make '{}' batch: {}".format(
|
||||
handler.batch_key, simple_error(error))
|
||||
progress.session.save()
|
||||
|
||||
else:
|
||||
session.commit()
|
||||
session.refresh(batch)
|
||||
session.close()
|
||||
|
||||
if progress:
|
||||
progress.session.load()
|
||||
progress.session['complete'] = True
|
||||
progress.session['success_url'] = self.get_batch_view_url(batch)
|
||||
|
|
Loading…
Reference in a new issue