stock_measuring_device: Allow to auto-refresh the measuring wizard.

This commit is contained in:
Matthieu Méquignon
2021-04-28 13:07:01 +02:00
committed by Hai Lang
parent 23daffde7d
commit 740f5bde84
4 changed files with 81 additions and 1 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

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

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

@@ -165,6 +165,20 @@ class MeasuringWizard(models.TransientModel):
"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