diff --git a/stock_measuring_device/__manifest__.py b/stock_measuring_device/__manifest__.py
index d5be9ba5e..e7e43e589 100644
--- a/stock_measuring_device/__manifest__.py
+++ b/stock_measuring_device/__manifest__.py
@@ -15,7 +15,7 @@
"product_packaging_dimension",
"product_packaging_type_required",
"product_dimension",
- # For the pop-up message to tell the user to refresh.
+ # To refresh wizard screen or pop-up message on the wizard
"web_notify",
"web_ir_actions_act_view_reload",
],
diff --git a/stock_measuring_device/models/measuring_device.py b/stock_measuring_device/models/measuring_device.py
index 1ba9b6ed9..f23875954 100644
--- a/stock_measuring_device/models/measuring_device.py
+++ b/stock_measuring_device/models/measuring_device.py
@@ -40,7 +40,7 @@ class MeasuringDevice(models.Model):
return work_ctx.component(usage=self.device_type)
def open_wizard(self):
- return {
+ res = {
"name": _("Measurement Wizard"),
"res_model": "measuring.wizard",
"type": "ir.actions.act_window",
@@ -54,6 +54,12 @@ class MeasuringDevice(models.Model):
"no_breadcrumbs": True,
},
}
+ if self._is_being_used():
+ pack = self.env["product.packaging"].search(
+ [("measuring_device_id", "=", self.id)], limit=1
+ )
+ res["context"]["default_product_id"] = pack.product_id.id
+ return res
def _is_being_used(self):
self.ensure_one()
@@ -87,7 +93,7 @@ class MeasuringDevice(models.Model):
_logger.warning("No wizard line found for this measure.")
packaging.write(measures)
else:
- measures.update({"scan_requested": False})
+ measures.update({"scan_requested": False, "is_measured": True})
wizard_line.write(measures)
self._get_measuring_device().post_update_packaging_measures(
diff --git a/stock_measuring_device/models/product_packaging.py b/stock_measuring_device/models/product_packaging.py
index 2f7aa612c..753a029e2 100644
--- a/stock_measuring_device/models/product_packaging.py
+++ b/stock_measuring_device/models/product_packaging.py
@@ -16,6 +16,7 @@ class ProductPackaging(models.Model):
string="Measuring device which will scan the package",
help="Technical field set when an operator uses the device "
"to scan this package",
+ index=True,
)
def _measuring_device_assign(self, device):
diff --git a/stock_measuring_device/static/src/js/measuring_wizard.js b/stock_measuring_device/static/src/js/measuring_wizard.js
new file mode 100644
index 000000000..bd9fc40c4
--- /dev/null
+++ b/stock_measuring_device/static/src/js/measuring_wizard.js
@@ -0,0 +1,60 @@
+odoo.define("stock_measuring_device.measuring_wizard", function(require) {
+ "use strict";
+
+ var FormController = require("web.FormController");
+
+ FormController.include({
+ init: function() {
+ this._super.apply(this, arguments);
+ if (this.modelName === "measuring.wizard") {
+ this.call(
+ "bus_service",
+ "addChannel",
+ "notify_measuring_wizard_screen"
+ );
+ this.call(
+ "bus_service",
+ "on",
+ "notification",
+ this,
+ this.measuring_wizard_bus_notification
+ );
+ this.call("bus_service", "startPolling");
+ }
+ },
+ measuring_wizard_bus_notification: function(notifications) {
+ var self = this;
+ _.each(notifications, function(notification) {
+ var channel = notification[0];
+ var message = notification[1];
+ if (channel === "notify_measuring_wizard_screen") {
+ if (message.action === "refresh") {
+ self.measuring_wizard_bus_action_refresh(message.params);
+ }
+ }
+ });
+ },
+ measuring_wizard_bus_action_refresh: function(params) {
+ var selectedIds = this.getSelectedIds();
+ if (!selectedIds.length || params.model !== this.modelName) {
+ return;
+ }
+ var currentId = selectedIds[0];
+ if (params.id === currentId) {
+ this.reload();
+ }
+ },
+ destroy: function() {
+ if (this.modelName === "measuring.wizard") {
+ this.call(
+ "bus_service",
+ "deleteChannel",
+ "notify_measuring_wizard_screen"
+ );
+ }
+ this._super.apply(this, arguments);
+ },
+ });
+
+ return {};
+});
diff --git a/stock_measuring_device/views/assets.xml b/stock_measuring_device/views/assets.xml
index de7d8fba5..8be276756 100644
--- a/stock_measuring_device/views/assets.xml
+++ b/stock_measuring_device/views/assets.xml
@@ -11,6 +11,10 @@
type="text/scss"
href="/stock_measuring_device/static/src/scss/measuring_wizard.scss"
/>
+
diff --git a/stock_measuring_device/wizard/measuring_wizard.py b/stock_measuring_device/wizard/measuring_wizard.py
index f06837fb1..e5aa6d489 100644
--- a/stock_measuring_device/wizard/measuring_wizard.py
+++ b/stock_measuring_device/wizard/measuring_wizard.py
@@ -89,6 +89,7 @@ class MeasuringWizard(models.TransientModel):
"barcode": pack.barcode,
"packaging_id": pack.id,
"packaging_type_id": pack_type.id,
+ "scan_requested": bool(pack.measuring_device_id),
}
)
vals_list.append(vals)
@@ -111,6 +112,8 @@ class MeasuringWizard(models.TransientModel):
packaging_ids_list = []
for line in self.line_ids:
packaging_type = line.packaging_type_id
+ if not line.is_measured:
+ continue
if packaging_type:
# Handle lines with packaging
vals = {
@@ -148,7 +151,11 @@ class MeasuringWizard(models.TransientModel):
self.onchange_product_id()
def action_close(self):
- self.ensure_one()
+ for line in self.line_ids:
+ if not line.scan_requested:
+ continue
+ line.packaging_id._measuring_device_release()
+ line.scan_requested = False
return {
"type": "ir.actions.act_window",
"res_model": self.device_id._name,
@@ -158,11 +165,35 @@ class MeasuringWizard(models.TransientModel):
"flags": {"headless": False, "clear_breadcrumbs": True},
}
+ def retrieve_product(self):
+ """Assigns product that locks the device if a scan is already requested."""
+ if self.device_id._is_being_used():
+ pack = self.env["product.packaging"]._measuring_device_find_assigned(
+ self.device_id
+ )
+ self.product_id = pack.product_id
+ self.onchange_product_id()
+
def reload(self):
return {
"type": "ir.actions.act_view_reload",
}
+ def _send_notification_refresh(self):
+ """Send a refresh notification on the wizard.
+
+ Other notifications can be implemented, they have to be
+ added in static/src/js/measuring_wizard.js and the message
+ must contain an "action" and "params".
+ """
+ self.ensure_one()
+ channel = "notify_measuring_wizard_screen"
+ bus_message = {
+ "action": "refresh",
+ "params": {"model": self._name, "id": self.id},
+ }
+ self.env["bus.bus"].sendone(channel, bus_message)
+
def _notify(self, message):
"""Show a gentle notification on the wizard
diff --git a/stock_measuring_device/wizard/measuring_wizard.xml b/stock_measuring_device/wizard/measuring_wizard.xml
index 41b29509c..a3b248c28 100644
--- a/stock_measuring_device/wizard/measuring_wizard.xml
+++ b/stock_measuring_device/wizard/measuring_wizard.xml
@@ -37,6 +37,12 @@
string="Refresh"
icon="fa-refresh"
/>
+
diff --git a/stock_measuring_device/wizard/measuring_wizard_line.py b/stock_measuring_device/wizard/measuring_wizard_line.py
index 3e3a9d5f2..18e66d0ef 100644
--- a/stock_measuring_device/wizard/measuring_wizard_line.py
+++ b/stock_measuring_device/wizard/measuring_wizard_line.py
@@ -33,6 +33,7 @@ class MeasuringWizardLine(models.TransientModel):
packaging_type_id = fields.Many2one("product.packaging.type", readonly=True)
is_unit_line = fields.Boolean(readonly=True)
required = fields.Boolean(related="packaging_type_id.required", readonly=True)
+ is_measured = fields.Boolean()
@api.depends("lngth", "width", "height")
def _compute_volume(self):
diff --git a/stock_measuring_device_zippcube/components/zippcube_device_component.py b/stock_measuring_device_zippcube/components/zippcube_device_component.py
index 4c009d41b..44520b34e 100644
--- a/stock_measuring_device_zippcube/components/zippcube_device_component.py
+++ b/stock_measuring_device_zippcube/components/zippcube_device_component.py
@@ -3,8 +3,6 @@
import logging
-from odoo import _
-
from odoo.addons.component.core import Component
_logger = logging.getLogger(__name__)
@@ -35,5 +33,8 @@ class ZippcubeDevice(Component):
}
def post_update_packaging_measures(self, measures, packaging, wizard_line):
- wizard_line.wizard_id._notify(_("Please, press the REFRESH button."))
+ # wizard_line is only set when measurements are made from the measurement
+ # device wizard.
+ if wizard_line:
+ wizard_line.wizard_id._send_notification_refresh()
packaging._measuring_device_release()