Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc fixes/imp #55

Merged
merged 8 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions shopfloor/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def __init__(self, message, log_entry_url):
self.rest_json_info = {"log_entry_url": log_entry_url}


class ShopfloorServiceUserErrorException(
ShopfloorServiceDispatchException, exceptions.UserError
):
"""User error wrapped exception."""


class ShopfloorServiceValidationErrorException(
ShopfloorServiceDispatchException, exceptions.ValidationError
):
"""Validation error wrapped exception."""


class BaseShopfloorService(AbstractComponent):
"""Base class for REST services"""

Expand Down Expand Up @@ -55,20 +67,45 @@ def _db_logging_active(self):
def _dispatch_with_db_logging(self, method_name, _id=None, params=None):
try:
result = super().dispatch(method_name, _id=_id, params=params)
except Exception as err:
tb = traceback.format_exc()
self.env.cr.rollback()
with registry(self.env.cr.dbname).cursor() as cr:
env = self.env(cr=cr)
log_entry = self._log_call_in_db(env, request, _id, params, error=tb)
log_entry_url = self._get_log_entry_url(log_entry)
raise ShopfloorServiceDispatchException(str(err), log_entry_url) from err

except exceptions.UserError as orig_exception:
self._dispatch_exception(
ShopfloorServiceUserErrorException,
orig_exception,
_id=_id,
params=params,
)
except exceptions.ValidationError as orig_exception:
self._dispatch_exception(
ShopfloorServiceValidationErrorException,
orig_exception,
_id=_id,
params=params,
)
except Exception as orig_exception:
self._dispatch_exception(
ShopfloorServiceDispatchException,
orig_exception,
_id=_id,
params=params,
)
log_entry = self._log_call_in_db(self.env, request, _id, params, result=result)
log_entry_url = self._get_log_entry_url(log_entry)
result["log_entry_url"] = log_entry_url
return result

def _dispatch_exception(
self, exception_klass, orig_exception, _id=None, params=None
):
tb = traceback.format_exc()
self.env.cr.rollback()
with registry(self.env.cr.dbname).cursor() as cr:
env = self.env(cr=cr)
log_entry = self._log_call_in_db(env, request, _id, params, error=tb)
log_entry_url = self._get_log_entry_url(log_entry)
# UserError and alike have `name` attribute to store the msg
exc_msg = getattr(orig_exception, "name", str(orig_exception))
raise exception_klass(exc_msg, log_entry_url) from orig_exception

def _get_log_entry_url(self, entry):
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
url_params = {
Expand Down
3 changes: 3 additions & 0 deletions shopfloor_mobile/static/wms/src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ ul.packaging span:first-child {
.notifications p:last-child {
margin-bottom: 0;
}
.notifications > .v-alert.error a {
color: white;
}

.searchform > .v-input:first-child {
margin-top: 0;
Expand Down
2 changes: 1 addition & 1 deletion shopfloor_mobile/static/wms/src/scenario/zone_picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const template_mobile = `
:card_color="utils.colors.color_for('screen_step_todo')"
class="mt-2"
/>
<div class="no-line-found" v-if="state.data.move_line">
<div class="no-line-found" v-if="_.isEmpty(state.data.move_line)">
<!-- In theory this should not happen.
Handled only because something seems wrong backend side
and we might get here w/ no line info. -->
Expand Down