Merge PR #1144 into 13.0

Signed-off-by simahawk
This commit is contained in:
OCA-git-bot
2021-05-12 13:04:36 +00:00
9 changed files with 117 additions and 7 deletions

View File

@@ -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",
],

View File

@@ -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(

View File

@@ -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):

View File

@@ -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 {};
});

View File

@@ -11,6 +11,10 @@
type="text/scss"
href="/stock_measuring_device/static/src/scss/measuring_wizard.scss"
/>
<script
type="text/javascript"
src="/stock_measuring_device/static/src/js/measuring_wizard.js"
/>
</xpath>
</template>
</odoo>

View File

@@ -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

View File

@@ -37,6 +37,12 @@
string="Refresh"
icon="fa-refresh"
/>
<button
name="retrieve_product"
type="object"
string="Retrieve Product"
icon="fa-search"
/>
</group>
<group name="col2" />
</group>

View File

@@ -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):

View File

@@ -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()