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" /> +