Catch and show error, if one happens when making batch from product query

This commit is contained in:
Lance Edgar 2021-03-19 10:38:56 -05:00
parent e19119194d
commit ee65d08d81

View file

@ -40,7 +40,7 @@ from rattail.db import model, api, auth, Session as RattailSession
from rattail.gpc import GPC from rattail.gpc import GPC
from rattail.threads import Thread from rattail.threads import Thread
from rattail.exceptions import LabelPrintingError 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.batch import get_batch_handler
from rattail.time import localtime, make_utc from rattail.time import localtime, make_utc
@ -1693,14 +1693,29 @@ class ProductView(MasterView):
user = session.query(model.User).get(user_uuid) user = session.query(model.User).get(user_uuid)
assert user assert user
params['created_by'] = user params['created_by'] = user
try:
batch = handler.make_batch(session, **params) batch = handler.make_batch(session, **params)
batch.products = products.with_session(session).all() batch.products = products.with_session(session).all()
handler.do_populate(batch, user, progress=progress) 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.commit()
session.refresh(batch) session.refresh(batch)
session.close() session.close()
if progress:
progress.session.load() progress.session.load()
progress.session['complete'] = True progress.session['complete'] = True
progress.session['success_url'] = self.get_batch_view_url(batch) progress.session['success_url'] = self.get_batch_view_url(batch)