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.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,19 +1693,34 @@ 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
|
||||||
batch = handler.make_batch(session, **params)
|
try:
|
||||||
batch.products = products.with_session(session).all()
|
batch = handler.make_batch(session, **params)
|
||||||
handler.do_populate(batch, user, progress=progress)
|
batch.products = products.with_session(session).all()
|
||||||
|
handler.do_populate(batch, user, progress=progress)
|
||||||
|
|
||||||
session.commit()
|
except Exception as error:
|
||||||
session.refresh(batch)
|
session.rollback()
|
||||||
session.close()
|
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()
|
||||||
|
|
||||||
progress.session.load()
|
else:
|
||||||
progress.session['complete'] = True
|
session.commit()
|
||||||
progress.session['success_url'] = self.get_batch_view_url(batch)
|
session.refresh(batch)
|
||||||
progress.session['success_msg'] = 'Batch has been created: {}'.format(batch)
|
session.close()
|
||||||
progress.session.save()
|
|
||||||
|
if progress:
|
||||||
|
progress.session.load()
|
||||||
|
progress.session['complete'] = True
|
||||||
|
progress.session['success_url'] = self.get_batch_view_url(batch)
|
||||||
|
progress.session['success_msg'] = 'Batch has been created: {}'.format(batch)
|
||||||
|
progress.session.save()
|
||||||
|
|
||||||
def get_batch_view_url(self, batch):
|
def get_batch_view_url(self, batch):
|
||||||
if batch.batch_key == 'labels':
|
if batch.batch_key == 'labels':
|
||||||
|
|
Loading…
Reference in a new issue