From 65ba22cb6ff24750bd390438ea4f12f3b85c08fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20M=C3=A9quignon?= Date: Fri, 23 Apr 2021 15:39:27 +0200 Subject: [PATCH 1/6] Zippcube measure update When the measure update is call from somewhere else than the device wizard, an exception is raised. --- .../components/zippcube_device_component.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stock_measuring_device_zippcube/components/zippcube_device_component.py b/stock_measuring_device_zippcube/components/zippcube_device_component.py index 4c009d41b..6e759412f 100644 --- a/stock_measuring_device_zippcube/components/zippcube_device_component.py +++ b/stock_measuring_device_zippcube/components/zippcube_device_component.py @@ -35,5 +35,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._notify(_("Please, press the REFRESH button.")) packaging._measuring_device_release() From e8b6914cfeca5ffa252ae28294cbc6a3ee113c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20M=C3=A9quignon?= Date: Tue, 27 Apr 2021 16:16:58 +0200 Subject: [PATCH 2/6] stock_measuring_device: Only create or update packages that have been measured --- stock_measuring_device/models/measuring_device.py | 2 +- stock_measuring_device/wizard/measuring_wizard.py | 2 ++ stock_measuring_device/wizard/measuring_wizard_line.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stock_measuring_device/models/measuring_device.py b/stock_measuring_device/models/measuring_device.py index 1ba9b6ed9..93cb0b9d1 100644 --- a/stock_measuring_device/models/measuring_device.py +++ b/stock_measuring_device/models/measuring_device.py @@ -87,7 +87,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/wizard/measuring_wizard.py b/stock_measuring_device/wizard/measuring_wizard.py index f06837fb1..43cb68b10 100644 --- a/stock_measuring_device/wizard/measuring_wizard.py +++ b/stock_measuring_device/wizard/measuring_wizard.py @@ -111,6 +111,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 = { 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): From b072a3b12ae2f944458921b367a3971b0c77d978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20M=C3=A9quignon?= Date: Wed, 28 Apr 2021 13:07:01 +0200 Subject: [PATCH 3/6] stock_measuring_device: Allow to auto-refresh the measuring wizard. --- stock_measuring_device/__manifest__.py | 2 +- .../static/src/js/measuring_wizard.js | 62 +++++++++++++++++++ stock_measuring_device/views/assets.xml | 4 ++ .../wizard/measuring_wizard.py | 14 +++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 stock_measuring_device/static/src/js/measuring_wizard.js 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/static/src/js/measuring_wizard.js b/stock_measuring_device/static/src/js/measuring_wizard.js new file mode 100644 index 000000000..766e6ac7f --- /dev/null +++ b/stock_measuring_device/static/src/js/measuring_wizard.js @@ -0,0 +1,62 @@ +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") { + switch (message.action) { + case "refresh": + self.measuring_wizard_bus_action_refresh(message.params); + break; + } + } + }); + }, + measuring_wizard_bus_action_refresh: function(params) { + var selectedIds = this.getSelectedIds(); + if (!selectedIds.length) { + return; + } + var currentId = selectedIds[0]; + if (params.id === currentId && params.model === this.modelName) { + 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" /> +