-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ADD] Add support for mettler toledo IND425 weighing machine (serial) #70
base: master
Are you sure you want to change the base?
[ADD] Add support for mettler toledo IND425 weighing machine (serial) #70
Conversation
lmignon
commented
Jun 7, 2021
•
edited
Loading
edited
a17a834
to
6b61339
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot for this new addons !
Took a quick look. some minor remarks.
Is it the Dialog06 norm ?
thanks.
@@ -58,6 +58,8 @@ Point of Sale with PyWebDriver as a Proxy. | |||
- [Epson OCD300](http://www.aures-support.fr/NEWSITE/ocd300/) | |||
- **Scale**: | |||
- TODO : planned by GRAP (Any help welcome); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could remove this lines.
let data = await response.json() | ||
weight_input = document.getElementById('weight'); | ||
weight_input.value=data.value; | ||
if (data.status === 'ACQUIRING') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed something, but should be orange, if ACQUIRING, and red if ERROR. (and green if FIXED)
don't you think ?
d55bec1
to
5d59a05
Compare
3afc5ae
to
08489ba
Compare
08489ba
to
29c7226
Compare
In the same time, improve robustness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the text as asked by Sylvain ?
Then I think we can merge since this is almost only an addition and CI is green (ubuntu does not build on master atm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry but my point regarding status is not answered. It is ?
@legalsylvain We could change the color if you want but it's just a sample on how to display the weight into a web page. On my project I've developed a specific widget for odoo 10 :-( ... Here it's the code... odoo.define("web_weighing_widget", function(require) {
"use strict";
const form_widgets = require("web.form_widgets");
const core = require("web.core");
const session = require("web.session");
const Model = require("web.Model");
const _t = core._t;
const WeighingWidget = form_widgets.FieldFloat.extend({
template: "WebWeighingWidget",
init: function() {
this.proxyUrl = null;
this.status = "FIXED";
this.weightPoolingIntervalId = null;
this._super.apply(this, arguments);
this.error_notification = null;
},
initialize_content: function() {
this.$input = undefined;
this.$error = undefined;
if (!this.get("effective_readonly")) {
this.$input = this.$("input");
this.$error = this.$("#weighing-widget-error");
}
this._super();
},
start: function() {
const self = this;
this.view.on("change:actual_mode", this, this.on_mode_change);
return $.when(this._super())
.then(() => {
new Model("res.users")
.call("read", [[session.uid], ["pywebdriver_proxy_ip"]])
.done(result => {
const data = result[0];
self.proxyUrl = data.pywebdriver_proxy_ip;
});
})
.then(() => {
self.on_mode_change();
});
},
destroy: function() {
this.stop_weight_pooling();
this._super();
},
do_show: function() {
this.start_weight_pooling();
this._super();
},
do_hide: function() {
this.stop_weight_pooling();
this._super();
},
start_weight_pooling: function() {
const self = this;
this.stop_weight_pooling();
this.weightPoolingIntervalId = setInterval(async function() {
try {
const response = await fetch(self.proxyUrl + "/hw_proxy/weight");
const data = await response.json();
self.set_weighing_data(data);
} catch (error) {
self.on_connection_error(_t("Trying to reconnect..."));
}
}, 500);
},
stop_weight_pooling: function() {
if (this.weightPoolingIntervalId) {
clearInterval(this.weightPoolingIntervalId);
this.weightPoolingIntervalId = null;
}
},
on_mode_change: function() {
if (this.view.get("actual_mode") === "edit" && !this.get("effective_readonly")) {
this.start_weight_pooling();
} else {
this.stop_weight_pooling();
}
},
set_weighing_data: function(data) {
if (this.view.get("actual_mode") !== "view") {
if (data.status === "ERROR") {
// Status change to error...
// notify user.
this.on_connection_error(data.value);
} else {
if (this.status !== "ERROR") {
this.on_connection_fixed();
}
this.set_value(data.value);
}
this.set_status(data.status);
}
},
on_connection_error: function(message) {
this.$error.get(0).title =
_t("Could not connect to weighing machine") + ": " + message;
this.$error.show();
this.error_notification = true;
},
on_connection_fixed: function() {
if (this.error_notification) {
this.$error.get(0).title = "";
this.$error.hide();
this.do_notify(
_t("Connection restored"),
_t("Connection to weighing machine restored"),
false
);
this.error_notification = false;
}
},
set_status: function(status) {
if (this.view.get("actual_mode") !== "view" && !this.get("effective_readonly")) {
this.status = status;
let color = "#F16567";
if (!status || status === "FIXED" || status === "ERROR") {
color = "transparent";
}
this.$input.css("background-color", color);
}
},
is_syntax_valid: function() {
const res = this._super();
return res && (!this.status || this.status !== "ACQUIRING");
},
});
core.form_widget_registry.add("weighing_widget", WeighingWidget);
return {
WeighingWidget: WeighingWidget,
};
}); .o_form_view {
.weighing_widget {
.o-input();
.o-align-items(baseline);
> .o_form_input {
border-style: none !important;
width: 100px;
.o-flex(1, 0, auto);
}
}
// Flex fields
.weighing_widget {
.o-inline-flex-display();
> span,
> button {
.o-flex(0, 0, auto);
}
> .weighing_widget_error {
&::before {
color: @notification-error-bg-color;
}
display: none;
}
}
} <?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t t-name="WebWeighingWidget">
<span t-if="widget.get('effective_readonly')" />
<div
t-if="!widget.get('effective_readonly')"
id="weighing-widget"
class="weighing_widget"
>
<input
t-if="!widget.get('effective_readonly')"
class="o_form_input"
t-att-barcode_events="widget.options.barcode_events"
t-att-type="widget.password ? 'password' : 'text'"
t-att-id="widget.id_for_label"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-placeholder="widget.node.attrs.placeholder"
t-att-autocomplete="widget.password ? 'new-password' : widget.node.attrs.autocomplete"
t-att-maxlength="widget.field.size"
/>
<span
id="weighing-widget-error"
class="fa fa-exclamation-circle weighing_widget_error"
data-toggle="tooltip"
data-html="true"
data-placement="right"
title=""
>
</span>
</div>
</t>
</templates> |
This PR should be rebased on top of the @carmenbianca work. Don't you think ? |