Skip to content

Commit

Permalink
Merge pull request #49 from simahawk/13.0-shopfloor
Browse files Browse the repository at this point in the history
Misc fix / imp
  • Loading branch information
simahawk authored Aug 26, 2020
2 parents 0ebac5d + f6432af commit 5e3e4a5
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 9 deletions.
8 changes: 7 additions & 1 deletion shopfloor/models/stock_quant_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models
from odoo import _, api, exceptions, fields, models


class StockQuantPackage(models.Model):
Expand Down Expand Up @@ -37,3 +37,9 @@ def _compute_reserved_move_lines(self):
# destination_planned_move_line_ids

# filter out done/cancel lines

@api.constrains("name")
def _constrain_name_unique(self):
for rec in self:
if self.search_count([("name", "=", rec.name), ("id", "!=", rec.id)]):
raise exceptions.UserError(_("Package name must be unique!"))
37 changes: 33 additions & 4 deletions shopfloor/services/service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import traceback

from werkzeug.urls import url_encode, url_join

from odoo import _, exceptions, registry
from odoo.exceptions import MissingError
from odoo.http import request
Expand All @@ -15,6 +19,15 @@ def to_float(val):
return None


class ShopfloorServiceDispatchException(Exception):

rest_json_info = {}

def __init__(self, message, log_entry_url):
super().__init__(message)
self.rest_json_info = {"log_entry_url": log_entry_url}


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

Expand Down Expand Up @@ -43,14 +56,30 @@ 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)
self._log_call_in_db(env, request, _id, params, error=err)
raise
self._log_call_in_db(self.env, request, _id, params, result=result)
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

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 _get_log_entry_url(self, entry):
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
url_params = {
"action": self.env.ref("shopfloor.action_shopfloor_log").id,
"view_type": "form",
"model": entry._name,
"id": entry.id,
}
url = "/web?#%s" % url_encode(url_params)
return url_join(base_url, url)

@property
def _log_call_header_strip(self):
return ("Cookie", "Api-Key")
Expand Down Expand Up @@ -79,7 +108,7 @@ def _log_call_in_db(self, env, _request, _id, params, result=None, error=None):
)
if not values:
return
env["shopfloor.log"].sudo().create(values)
return env["shopfloor.log"].sudo().create(values)

def _get(self, _id):
domain = expression.normalize_domain(self._get_base_search_domain())
Expand Down
1 change: 1 addition & 0 deletions shopfloor/services/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def _response_schema(self, data_schema=None, next_states=None):
"required": False,
"schema": {"body": {"type": "string", "required": True}},
},
"log_entry_url": {"type": "string", "required": False},
}
if not data_schema:
data_schema = {}
Expand Down
2 changes: 1 addition & 1 deletion shopfloor/services/zone_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _scan_source_location(self, zone_location, picking_type, location):
move_line = self.env["stock.move.line"].search(domain)
if len(move_line) == 1:
return move_line
raise False
return False

def _scan_source_package(self, zone_location, picking_type, package, order):
move_lines = self._find_location_move_lines(
Expand Down
1 change: 1 addition & 0 deletions shopfloor/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@
from . import test_zone_picking_unload_single
from . import test_zone_picking_unload_all
from . import test_zone_picking_unload_set_destination
from . import test_misc
20 changes: 20 additions & 0 deletions shopfloor/tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from odoo import exceptions
from odoo.tests.common import SavepointCase


class MiscTestCase(SavepointCase):
tracking_disable = True

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(cls.env.context, tracking_disable=cls.tracking_disable)
)

def test_package_name_unique(self):
create = self.env["stock.quant.package"].create
create({"name": "GOOD_NAME"})
with self.assertRaises(exceptions.UserError) as exc:
create({"name": "GOOD_NAME"})
self.assertEqual(exc.exception.name, "Package name must be unique!")
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Vue.component("user-information", {
template: `
<v-alert :type="alert_type" tile>
<p v-for="line in message_lines" v-if="line" v-text="line"/>
<p v-if="support_url">
<a :href="support_url" v-text="message.support_url_text" />
</p>
</v-alert>
`,
computed: {
Expand All @@ -14,6 +17,9 @@ Vue.component("user-information", {
const msg = _.result(this.message, "body");
return msg ? msg.split("\n") : [];
},
support_url: function() {
return _.result(this.message, "support_url", "");
},
},
});

Expand Down
3 changes: 2 additions & 1 deletion shopfloor_mobile/static/wms/src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ ul.packaging span:first-child {
padding-bottom: 5px;
}

.notifications > .v-alert:last-child {
.notifications > .v-alert:last-child,
.notifications p:last-child {
margin-bottom: 0;
}

Expand Down
3 changes: 2 additions & 1 deletion shopfloor_mobile/static/wms/src/scenario/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@ export var ScenarioBaseMixin = {
if (error.description) {
parts.push("\n" + error.description);
}
parts.push("\nURL: " + error.response.url);
this.set_message({
body: parts.join(" "),
message_type: "error",
support_url: error.log_entry_url,
support_url_text: "View / share log entry",
});
},
_state_bind_events: function() {
Expand Down
7 changes: 6 additions & 1 deletion shopfloor_mobile/static/wms/src/scenario/zone_picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,15 @@ export var ZonePicking = Vue.component("zone-picking", {
},
manual_select_picking_type_fields: function() {
return [
{path: "lines_count", renderer: this.render_lines_count},
{
path: "lines_count",
renderer: this.render_lines_count,
display_no_value: true,
},
{
path: "priority_lines_count",
renderer: this.render_priority_lines_count,
display_no_value: true,
},
];
},
Expand Down

0 comments on commit 5e3e4a5

Please sign in to comment.